Top 10 C# Best Practices (plus bonuses)

Поделиться
HTML-код
  • Опубликовано: 24 янв 2025

Комментарии • 1,2 тыс.

  • @pwings01
    @pwings01 7 лет назад +51

    0:51 Name things well
    7:51 One class per file
    10:18 Use properties not variables
    12:58 Methods should do one thing
    23:27 Keep it simple
    28:21 Be consistent
    32:25 Use curly braces for if statements
    37:45 Concatenate strings using $""
    45:38 Avoid global variables
    48:40 Use public modifier only when necessary
    50:53 Never trust the user
    52:28 Plan before you build

    • @tomthelestaff-iamtimcorey7597
      @tomthelestaff-iamtimcorey7597 4 года назад +3

      Thank you for doing this. This really helps other students in finding what they are looking for within the video PLUS it helps when doing searches within the IAmTimCorey channel.

    • @Christobanistan
      @Christobanistan 3 года назад

      One class per file, in addition, is a bit outdated IMO. If you have a handful of small, related classes, I see value in keeping them together. Alphabetical is not as useful as a human's grouping, and pressing F12 or Ctrl+T+T makes it very easy to locate classes already. Just my IMO.

  • @lautarolavecchia5995
    @lautarolavecchia5995 4 года назад +16

    I like how you divide the whole video with timestamps it makes the learning process easier and to the point, thank you

    • @IAmTimCorey
      @IAmTimCorey  4 года назад +4

      Glad it was helpful! I actually did not do that. It was a contribution from folks in the community. They were looking for a way to contribute and came up with that. Its GREAT and I really appreciate their help. You can scroll down the comments and that them directly. Search for Ralfs and/or Julio

  • @jonathansaindon788
    @jonathansaindon788 6 лет назад +63

    Another best practice: Optimize only if performance suffers. It's so easy to get carried away in useless optimizations.

    • @IAmTimCorey
      @IAmTimCorey  6 лет назад +9

      Very true.

    • @Gizmo199
      @Gizmo199 4 года назад +4

      To add to this point though: always try to set it up so that it is easier IF you decide/need to optimize. Too many times I have had to completely rework systems because I set them up in an 'as is' type of mindset without thinking about making my life easier in the future if need to optimize

    • @drwombat
      @drwombat 4 года назад +2

      @@Gizmo199 would love to see a video discussing examples of as is code versus code setup for optimization if/when at a later date

    • @Gizmo199
      @Gizmo199 4 года назад +3

      @@drwombat not a bad idea actually. It's mainly making sure to keep everything de-coupled and leaving room for easy adjustments. It's kinda circumstantial most of the time but an example could be when designing your character, instead of say directly reading "if input is pressed do x" you set up some variables like key_left = input is pressed And have the actions of the player react to the variable key_left instead. That way if you decide to make your game multiplayer, you can basically duplicate your player character to make your 'dummy' players and get rid of the key_left = input pressed script and instead just have the server say "dummy1.key_left = true". Hopefully that makes sense. Ha

    • @trevorcoleman9125
      @trevorcoleman9125 3 года назад +2

      I hv optmzd ths cmmnt by rmving unncssry lttrs!

  • @smartdatalearning3312
    @smartdatalearning3312 4 года назад +6

    Whenever I see name Tim Corey I know that I can expect high quality material delivered in a well thought explanation style.
    On a side note I also wanted to mention that fonts look crisp and well focused when he is showing his computer screens. As I am also recording lectures I know that this is sometimes difficult to achieve and takes a lot of time and experimentation with different recording tools, parameters and video cards. So I appreciate that this author is spending time and taking efforts to make his videos enjoyable for viewers in all aspects.

  • @eTzTheGamer
    @eTzTheGamer 4 года назад +5

    Holy crap, this video is almost 6 years old, and you're still actively replying to comments!
    Thank you for all your super informational videos, and your interactivity helping people :)

  • @kermy2110
    @kermy2110 6 лет назад +5

    I've seen alot of videos and tutorials about C# - But this is without doubt the best and most useful one yet. Now i will start watching all your C# Lessons :D

    • @IAmTimCorey
      @IAmTimCorey  6 лет назад

      I am glad you found my content valuable.

  • @vinipickrodt
    @vinipickrodt 5 лет назад +4

    Great tips Tim!
    I would like to add just two..
    1. When doing high performance code to use local variables instead of properties inside the loop.
    2. When dealing with serialization using the properly Stream handler. Like StreamReader, XmlReader etc.

  • @AdebayoAdegbemboAsa
    @AdebayoAdegbemboAsa 6 лет назад +2

    Awesome! I tried out the StringBuilder option on 100,000 iterations and it completed same time as I started in seconds. On the other hand, the concatenation approach took 33 seconds to complete. This lesson coincides with a book I am currently reading on data structures and algorithms. I'm learning how much more there are to seemingly harmless practices when it comes to using data etc. Thanks Tim.

    • @IAmTimCorey
      @IAmTimCorey  6 лет назад

      You are welcome.

    • @jimmccoydura9717
      @jimmccoydura9717 6 лет назад

      Interesting. What is the book name on data structures and algorithms?

    • @AdebayoAdegbemboAsa
      @AdebayoAdegbemboAsa 6 лет назад

      Jim McCoyDura A common-sense guide to data structures and algorithms by Jay Wengrow

    • @jimmccoydura9717
      @jimmccoydura9717 6 лет назад

      @@AdebayoAdegbemboAsa Cool. Thanks.

  • @nwdreamer
    @nwdreamer 6 лет назад +3

    Although my "work for others" IT career is pretty much done, I still write for my own businesses. Especially when programming was new (I started at the age of 7 waaaay back in 1971), everyone tried to show off their skills which resulted in a lot of obfuscated code (there was even a contest for this!) that was virtually unmaintainable. One of the main things that set me apart from my co-workers, is that I used to write everything as simple as I could (which is why I was happy to see you mention it). Ironically, while others wrote complex code in an attempt to show management that they needed to keep their jobs, they only ended up having to maintain the confusing monsters they had created until someone else eventually rewrote them from scratch. On the other hand, because my programs were easy for even a newbie to understand, I was able to pass off the old work and always be involved in whatever was new and exciting.

    • @IAmTimCorey
      @IAmTimCorey  6 лет назад

      Yep, that sounds about right. Writing complex code does not show that you are skilled, it usually indicates that you don't understand how difficult you are making things for yourself and others. I'm glad you figured that out early on.

  • @BillSchultz70
    @BillSchultz70 8 лет назад +2

    Great video and tips, Tim. I would also add a short list of the best practices to your video description. Even better would be put the time in the video that each tip is presented so people can jump to it. Keep up the great work. LOL. Ok, Ok. I shouldn't comment until I finish watching the whole video. Nice trick with #5! :P

  • @reidwilliams2046
    @reidwilliams2046 6 лет назад +4

    Just to share a little anecdotal fuel to two of your best practices.
    1. in the late 1980's or early 90's I took a programming course using Borland C. This was back when DOS was still king and the big debate was whether Borland or Microsoft would be king of the C development world. Anyway, upon turning in my very first program the professor ran it and when it ask for the first user input he just started hitting any and every key on the keyboard. The program crashed and locked up the computer. He re-ran my program and used the proper user input and the program worked perfectly. I only got an 85 rather than a 100 for a perfect program because I failed to expect the unexpected (I trusted the user). I have never and will never do so again!
    2. Back in 2012 I began a program for a Steel Fabricator which calculated a lot of dimensions and points for laying out and cutting several different steel shapes. I was really intrigued and excited to get started and so that is just what I did. Because I was very familiar with this and knew how to do these things very well, I jumped right in and started writing code without much if any planning. Almost 1500 lines of code later I realized that I would have to start over from scratch because I failed to anticipate quiet a large number of possibilities that could and did occur. Fortunately I was able to use some of the code I had already written. Never Again!
    As I have heard so many times in the past "If you fail to plan, you are planning to Fail". I believe this is true even of small hobby projects because I have had so many of those projects turn into something much larger. Also, as you said and I learned the hard way "Never Ever Trust The User". If there is any way your program can be broken, some user will find that way and break it!
    Thanks for the video.

    • @IAmTimCorey
      @IAmTimCorey  6 лет назад

      Thanks for sharing your experiences.

  • @krishnanigalye1173
    @krishnanigalye1173 4 года назад +3

    Excellent as always Tim! I have learnt a lot from your videos.
    I was hoping you to do one video which covers these topics:
    1. how to plan a project
    2. how to plan the architecture
    3. how to choose the best possible tools

    • @IAmTimCorey
      @IAmTimCorey  4 года назад

      I will add them to the list. Thanks for the suggestions.

  • @evaikuun
    @evaikuun 5 лет назад +3

    I love this! It helps translate Robert Martin's book, Clean Code, from Java into C#. Thank you for this.
    It is incredible to find how many senior developers agree on (and abide by) the same basic concepts throughout their own code!

  • @bkramber
    @bkramber 3 года назад +3

    I applyed the forth practice (metod shoud do only one thing) to my latest programm. The programm was simple and I thought that I can't do it in this way. But then I start, I found:
    1. This refactoring is not so simple, as I thought
    2. My programm reads and debugs much, much better
    3. I used same pieces of code more than one time before refactoring
    Thank you! It was really useful!

  • @Metanis
    @Metanis 7 лет назад +3

    Very nice presentation. I like your pacing, enunciation, and grammar. The delivery facilitates a good understanding of the concepts. Thank you!

    • @IAmTimCorey
      @IAmTimCorey  7 лет назад

      Glad you enjoyed it.

    • @DefaultUser3301
      @DefaultUser3301 7 лет назад

      Couldn't agree more

    • @Layarion
      @Layarion 7 лет назад

      it is very good, but it bugs me that he said "one line" option for if-statements instead of "one statement". Now idiots will think they can do this:
      if (true)
      do this; do this as well;

  • @trackchampz6991
    @trackchampz6991 8 лет назад

    Just jumping into C# coming from javascript and web development looking to get deep into some software development and I was browsing and found your channel. Thanks in advance.

  • @mariannajedruch4614
    @mariannajedruch4614 6 лет назад +4

    That was really helpful! I really feel I've learnt a lot! Also, as a non-native english speaker I find your accent really understanable, which is soooo nice. Thank you!

    • @IAmTimCorey
      @IAmTimCorey  6 лет назад

      You are most welcome. Thanks for watching.

  • @itisito4769
    @itisito4769 4 года назад +1

    That was the best one hour c# teaching I have seen to date. I only program when there is no other way of getting the data I need and I strugled a lot with methodes and what the scope of them should be. And the same goes for the classes, and my question always is where I should put them. This helped me so much more than hours of watching some Bob talking for hours and confusing me more than before I watched. I think 7 tips where real eye openers but ill give you a 10 for the way you explained it in such a clear way. Thanks, and yes, I know this is a old post but never the less :-)

    • @IAmTimCorey
      @IAmTimCorey  4 года назад +1

      I am glad it was so clear and helpful.

  • @VISHNUKUMAR-bh8uj
    @VISHNUKUMAR-bh8uj 2 года назад +3

    This is a great video sir 👍
    My Best practice is: Writing down my whole plan on a notepad.
    I often split the requirement into 3 part
    1) The areas I am ready to code
    2) The topics I need to research
    3) Once my research is done I write some sudo code (Mostly the key logic)
    Once my planning is done(Usually I spent more time on this planning ) I am ready to open my visual studio and write my code
    Once the coding is complete I will spend some time doing some optimization either by myself or with a friend

    • @IAmTimCorey
      @IAmTimCorey  2 года назад

      Thanks for sharing.

    • @MD-vs9ff
      @MD-vs9ff 2 года назад +1

      As a fellow programmer, nothing beat good old analog pen-n-paper for organizing my thoughts. No fancy software will ever replace that.

  • @sal96ali
    @sal96ali 4 года назад +2

    I admire your honest content, and your care for your viewers. Thank you Sir.

  • @codingwithgyver1637
    @codingwithgyver1637 4 года назад +2

    One of the best mentors especially when implementing clean codes.
    I have one another tips here same as in your tip#1(Name things well)
    Never use a variable/method naming that has "double negation", I found it useful from another channel who is ex-Google developer
    ex1: var isEvenNumber=true;
    ex2: var isNotEvenNumber=false;
    both of them have same definition and purpose, to identify if the number is even.
    In ex1, you dont need to evaluate the actual purpose of it, its direct to the point, when it says false, then its an ODD numbers or when true, its EVEN,
    while in ex2, your minsdet will be like this. Although you read it, you must evaluate the actual purpose, when it says TRUE on first stage of evaluation, followed by negating the TRUE value on second stage will lead that final value is FALSE or a ODD number.

    • @IAmTimCorey
      @IAmTimCorey  4 года назад +1

      Thanks for sharing that tip.

  • @Bobodeveloper
    @Bobodeveloper 8 лет назад

    The best 10 Best Practices was to learn to learn to plan before I build project and the other was with useful as keep it simple.
    Everyone was very useful. THANKS
    You are doing a great job. Keep Going Tim. :)

  • @jonwoodhead000
    @jonwoodhead000 4 года назад +6

    The other good practice I would encourage is to review your project once you have finished. So often you will realise that you made a wrong decision that made things harder than they needed to be. It's often only at the end you get the perspective to spot that. Learn from your mistakes. In a commercial environment this step often gets lost under the pressure to do the next thing, but try to find the time.

    • @IAmTimCorey
      @IAmTimCorey  4 года назад

      Great point. A code walkthrough with peers is another highly encouraged option.

  • @edi_gun_awan
    @edi_gun_awan 4 года назад +1

    Thank You very much, Sir! I self learn with broken English and this is the first time someone said its ok to keep the basic. its help me a lot and courage me for learn with patiance.

    • @IAmTimCorey
      @IAmTimCorey  4 года назад

      Glad to hear that! Hang in there, you can do this. I believe that you can, which is why I keep making these videos.

  • @EgyptUnderGroundArmy
    @EgyptUnderGroundArmy 4 года назад +3

    Tim you are absolutely amazing, thank you so much. even after all that time you take the time to reply to every comment, if I am ever in America I will buy you a beer! cheers.

  • @CanadaWry
    @CanadaWry 7 лет назад

    Well produced video. Clear images and super clear voice and more importantly, clear explanations!

  • @donv1to76
    @donv1to76 5 лет назад +4

    Some of my personal best practices
    1) Use ternary operators for small if else statements
    2) GET RID OF COMMENTED CODE THAT IS NO LONGER BEING USED AT ALL
    You can also use a Parallel.ForEach in C# if order doesnt matter

  • @raskand1977
    @raskand1977 6 лет назад +2

    Tim Corey = The gentle voice of reason! Great video! Many thanks!

  • @RalfsBalodis
    @RalfsBalodis 4 года назад +4

    Minor adjustments to the existing time codes in the video description.
    0:00 - Intro
    0:50 - Name things well
    7:51 - One class per file
    10:18 - Use properties not variables
    12:57 - Methods should do one thing
    23:27 - Keep it simple
    28:21 - Be consistent
    32:22 - Use curly braces for if statements
    37:45 - Concatenate strings using $""
    45:37 - Avoid global variables
    48:39 - Use public modifier only when necessary
    50:54 - Never trust the user (bonus)
    52:24 - Plan before you build
    55:31 - Concluding remarks

  • @claytoncoleiro7190
    @claytoncoleiro7190 3 года назад +2

    Perhaps the only thing I would add to your Best practice #8
    When you want to add a line to your if or else, or even to your else if, should these not have the curly braces, you will have to find the if and the end of that if, add the curly braces and then add your line.
    However, if you do add the braces before, it does not require more typing as you showcased, but does not require you to find the beginning of the if and the end, using your mouse or cursor, and simply add your line[s] in.
    Great video as always, I've been in the field for a number of years and watch your videos for the sake of refreshing my memory, plus sometimes you do teach me another nice way of doing things. Keep it up Mr.Corey :)

  • @gene7433
    @gene7433 8 лет назад +3

    Hi Tim, nice video.
    Well what I miss is "commenting". You can pick the best describing names for variables, methodes, classes and so on, but a comment can say so much more and tells you what this e.g. method is doing. On the other hand when should one write a comment?

    • @Soundtech98
      @Soundtech98 8 лет назад

      Tim Corey I love the video and have received some great advice. I'm a keen programmer (mostly C#) and wanted to hear your thoughts on error catching statements.
      If my code is broken up into functions where Main() calls the function (eg. Function() ), does a try catch statement go into the Main() or Function()?
      In other words: Does the try catch statement surround the code (inside the function) or does it surround the function being called in Main() or perhaps in both places? I guess it's all the same in the end but what's considered best practice out there? Thank you very much Tim.

  • @needler1234
    @needler1234 7 лет назад

    You are the first online teacher that actually explained everything for a beginner to understand what everything is really about. You bring facts to the overall facts and makes you understand each step in the code. Many thanks :)

    • @IAmTimCorey
      @IAmTimCorey  7 лет назад

      Awesome! I'm glad you found my content so useful.

  • @johannes8410
    @johannes8410 2 года назад +7

    My best practice is: if you can't find the error, go out for a walk or sleep a bit. I solved a lot of problems in my dreams.
    But, when you got the solution mid night, write it down you hate yourself if you don't know it the next morning. 🙈

    • @IAmTimCorey
      @IAmTimCorey  2 года назад +1

      Agreed. Letting your brain stop pushing on something actually allows it to hit it more effectively.

  • @burnie74
    @burnie74 4 года назад +2

    I started my programming career in 1967 (using machine language, assemblers, etc.) and spent many years primarily as a contractor in the Boston area. Used many languages such as Fortran, C and mainly COBOL/CICS among others. Personal computers came along and I used C (and assembler) for my projects in DOS. Unfortunately, C didn't have many libraries at the time so I had to create my own (including keyboard handlers).
    First started programming Windows stuff using Quick C for Windows until Visual Basic came along in 1991 and I switched to that (while still working as a contractor using COBOL). Around 2001 I designed, developed, coded and implemented a Point of Sale system to be used in my computer store.
    The POS system has been running since 2001 in 3 different stores and of course, many updates and improvements have been made. It currently uses SQL Server locally which is synchronized with an Azure SQL database.
    It's now time to rewrite the POS system. I already rewrote most of it using VB.net and it works fine, but I think it should be changed to C#. Thus my review of your video.
    I just want to say that you have hit the nail on the head with all of your "Best Practices", and I encourage anyone (novice or expert) to check out the video to either learn them anew or just refresh their own experiences. Great video!

  • @souvikdas1267
    @souvikdas1267 6 лет назад +3

    I learned one from my teammate which is DRY(Don't repeat yourself) and YAGNI(You aren't going to need it). I think the terms are quite understandable and should help any fellow programmer.

    • @IAmTimCorey
      @IAmTimCorey  6 лет назад +1

      I did a whole video on DRY: ruclips.net/video/dhnsegiPXoo/видео.html Those two are definitely good ones to constantly be thinking through as you build applications.

    • @peterfarr9591
      @peterfarr9591 5 лет назад

      @@IAmTimCorey The only issue with DRY can be that it will cause you to violate SRP. In "Clean Architecture" Robert Martin mentions that it's better to have repeated code if doing so separates each module such that any one module can only be subjected to change requests from a single department.

  • @VitaliyParitskiy
    @VitaliyParitskiy 4 года назад +1

    You are a great teacher, Tim. Plus, with slow speech pace you give my brain a time to process the information. Thank you

  • @Hi_Tech
    @Hi_Tech 6 лет назад +4

    I would love to see your process of how you work through planning out your projects

    • @IAmTimCorey
      @IAmTimCorey  6 лет назад +1

      I do provide one glimpse into some of that process with the C# Application from Start to Finish course. There are about five videos that do nothing but planning.

    • @Hi_Tech
      @Hi_Tech 6 лет назад

      @@IAmTimCorey Thanks Tim. I'll definitely check those out!

  • @yanwo2359
    @yanwo2359 4 года назад +2

    Bonus #1: 35 years ago (can't be!) at Ampex, I coined the phrase, "Paranoid Programming." Your description fits it exactly. Loved the video. In fact I haven't seen one of yours that I haven't liked very much. Thanks!

  • @Sad-Lemon
    @Sad-Lemon 7 лет назад +3

    A very high quality content video on best practices! From my perspective I would add: Stay in shape, stay healthy! With your body in shape you thinking process will be much more efficient. You will feel good and avoid depression, which is an often phenomena for programmers(because of the lifestyle we have in connection to our job). Watching this movie I burnt 1100 calories(140 grams of fat effectively) running on an elliptic bike. There are tutorials and movies that can't be watched running(for example when you have to follow the steps in a tutorial on you own) but this was so nice and well put together that I could just relax and run with the knowledge being absorbed into my brain.

    • @IAmTimCorey
      @IAmTimCorey  7 лет назад +3

      Exercise is important, especially for developers. Personally, I have to make a conscious effort to exercise every day or I'll end up barely moving. That isn't healthy. Good suggestions.

  • @goji5887
    @goji5887 7 лет назад

    You are awesome at explaining and your voice is just perfect for things like this. Subscribed immediately after I finished the video.

    • @IAmTimCorey
      @IAmTimCorey  7 лет назад +1

      Welcome aboard. Let me know what topics you are looking for that I don't already provide and I'll put them on my list. My videos come out of the suggestions of viewers. The more suggestions I get for a topic, the more likely it is that I'll do it.

  • @ajayvijayh
    @ajayvijayh 7 лет назад +6

    summary of video is at 50:03

  • @nhanth
    @nhanth 7 лет назад +1

    Hi Tim , I know maybe there was someone already said this but I really enjoyed your tone from microphone. :D Keep it up , you are doing great things for me and everyone else.

  • @cirezno5960
    @cirezno5960 3 года назад +3

    Methods should do one thing. This is my best one !!

  • @TheAngelOfDeath01
    @TheAngelOfDeath01 7 лет назад +1

    Hello from Sweden!
    You nailed them, that's all I can say. Apart of the 8th "rule" I follow those exact same practices. I've coded for years using PHP and MySQL. For me personally, I like to add Hungarian Notation into the mix of favourite practices, simply because as you go down through your code, it can be quite the job keeping track of what type various variables are, and not all IDE's are strong on the whole IntelliSense aspect. Visual Studio and Zend Studio are without doubt the strongest IDE's I've ever worked with.
    Thanks for the video. :-)

    • @IAmTimCorey
      @IAmTimCorey  7 лет назад

      I'm glad you enjoyed the video and thanks for the feedback.

  • @Winged4Ever
    @Winged4Ever 4 года назад +11

    My best practice? Learn from Tim Corey! : P

  • @CitAllHearItAll
    @CitAllHearItAll 7 лет назад +1

    Thank you! The "methods should do one thing" concept cleared some clouds for me.

  • @bri3fcas3
    @bri3fcas3 5 лет назад +4

    One of my best practice is to write the comment first before start coding. Then clean up the comment if the code itself is readable.

    • @IAmTimCorey
      @IAmTimCorey  5 лет назад +1

      That's a good one. I do that a lot.

  • @ThePravoslavlje
    @ThePravoslavlje 7 лет назад

    You sir are a hero, the content you provide is perfect for young people who want the learn. And you as a busy person(I suppose you are) in doing this prove how selfless you are. Thank you! :)

    • @IAmTimCorey
      @IAmTimCorey  7 лет назад

      Thanks! Yeah, I'm a busy guy but not only is this important, I really enjoy helping others learn C#.

  • @InformationSensation
    @InformationSensation 6 лет назад +5

    The "never trust the user" tip shouldn't be a bonus tip, it's a common practice any programmer should do.
    My capstone group in college thought "hey, it's their fault" if they input wrong data into the system we created. I couldn't believe how long I had to argue to convince them that they're complete idiots for even thinking that it's OK for the entire program to crash because of user error.

    • @IAmTimCorey
      @IAmTimCorey  6 лет назад +3

      It is a big one to learn, for sure.

  • @ScorpioHR
    @ScorpioHR 7 лет назад

    Hi Tim.
    Great video, I just wanted to add something to your vast knowledge base:
    1. you can comment things by selecting lines and holding CTRL, press K and after that C (uncommenting is CTRL+K, U)
    2. Quick search of a class member (Property, Method, any other thing) is by simply typing capital letters of a member name:
    example You want Console.ReadLine -> You type Console. RL and auto complete will jump to all members that have capitalized "RL".
    Or, other example: you want System.AccessViolationException, you type System.AVE and autocomplete will show you what you were looking for (and maybe some more members if they have same capital letters... but it narrows the list.)
    I've seen this in Android Studio, then tried in VS 2015 and realized.... HEY, IT WORKS!
    Hope this will make you a little bit more productive. ;)

    • @ScorpioHR
      @ScorpioHR 7 лет назад

      Yeah, Android Studio (probably IntellJ, too, since it's a fork of it) has CTRL+/ and CTRL+shift+/ for single line/block comment (respectively), and it's faster than double key shortcuts... I just saw it took you few seconds to comment those two lines so I thought to myself using shortcut would be faster.
      But, of course, it's not about syntax and shortcuts, it's about logic.

  • @MichaelNikolaus
    @MichaelNikolaus 6 лет назад +3

    This kind of video will give you maybe some best practices, but also bad practices. Which are: Methods which rely on each other and only work if they are called in the same order, mutable objects which makes it hard to debug when an application grows and static properties which lead the thread unsafety and lead to hard coupling. And i also agree, those content can be shortened. Some other „Best Practices“: Use Code Formatters and Extensions for StyleGuides (But not take them too serious), Don‘t use NULL, Always Check / Validate Parameters, Learn at least one hour a day (from other programmers).

    • @IAmTimCorey
      @IAmTimCorey  6 лет назад

      I'm not sure I really understand which practices you are saying are bad. I also disagree with your "don't use null" (it has a clear purpose).

    • @MichaelNikolaus
      @MichaelNikolaus 6 лет назад +2

      @@IAmTimCoreyLets try to explain it: Those methods you created, modify the internal state of the Class. So they must be used in the same order and the same amount of times of executing to create the same result. Which I mean about they a kind of "hard coupled". I would prefer a method Person[] Examples() and a Person[] parameter for the other function.
      About threading, in your example, if I would call the function for the Example data more than one times in a not multi-threaded environment I'll receive a list with the same ordering and the length and count of items will depend on the number of calls. In a multi-threaded environment, where you may call the method from a different place in and different threads you may get a different result each time.
      I hope explained my thoughts well, so if they more clear now I would love to see a video about that from you because you're youtube guy.
      It's fine to disagree to not use nulls, also here, I would like to see a video why we should use NULL and where to not use NULL. Maybe it's "Don't try to use NULL" after that?

    • @jonathancg2161
      @jonathancg2161 5 лет назад

      Btw I wanna point out that the practices explained in this video are still very good tho. I feel like my comment says your video is shit but it really isn't lol. :)

  • @LornaKelso
    @LornaKelso 7 лет назад

    I found this video very helpful Tim. I don't think it was too long at all. The negativity in the comments bugs me when it's obvious that you put a lot of effort into ensuring that this tutorial is explained in a such way that all levels can understand and get something from it.

  • @rogerbenson8493
    @rogerbenson8493 4 года назад +2

    1. EVERY data element serves ONE purpose and ONE purpose only.
    Example: itemCategory is designed to group like items together but then it is also used to determine which price file to use. Best practice is to use a file that stores the item id, the category code, and the PRICE FILE code.
    2. NEVER (if humanly possible) hard code anything based on data values.
    Example: If (itemCategory == 234) {do something special}
    3. NEVER design a file without determining who (in the organization) will maintain each data element. (this should be #1)

  • @pauldhartley
    @pauldhartley 7 лет назад +1

    Regarding your best practice number 12 about planning the project, I remember seeing Charles H. Moore (Forth programming language) at a Forth Interest Group meeting talking on this subject and saying 'Do the interesting bits of programming first - to generate the necessary enthusiasm for getting started.
    I always think of Mr. Moore when I start a new project, and I do frequently look at the 'interesting i.e. most challenging' parts first.

    • @IAmTimCorey
      @IAmTimCorey  7 лет назад +2

      I approach it mostly the same way. I tend to do the hardest things first so that I know they can be done. Usually I do this with an experimental app first. Then I do it in order (models and forms first, then wire up from small to big). It gives me the fastest development process and there doesn't ever seem to be large sections where I'm dragging along. That limits the overwhelming feeling of having SO MUCH to do yet.

  • @ApacheGamingUK
    @ApacheGamingUK 4 года назад +4

    Are abstract classes really classed as a Senior level concept? I've been a hobbyist for decades, and I've received formal training at Uni, and College in C#. I'm now looking at jobs in C#, trying to work out where I am as a hobbyist within industry. I've always considered inheritance and polymorphism to be a fairly basic feature within C#. Am I drastically over-estimating what a junior level programmer would be doing within industry, and if so, should I push to get in on a higher rung of the ladder?

  • @stephencutts6625
    @stephencutts6625 5 лет назад +1

    Once again another great video! I was practicing what I learned and am making a Console Program that will have various tools and maybe even a text adventure game. I stacked so much of my code in the Main and kept getting confused and even started over. Now I'm placing things in custom methods and only having them do one thing. Coding life is getting so much better and enjoyable for me. Thank you!

  • @ScriptStudios
    @ScriptStudios 6 лет назад +3

    Plan before you build.
    I try to do this but I always loose my inspiration and do nothing in the end.
    I found Coding first and then Refactoring it into a proper architecture is easier for me (Not in the sense of headaches but for getting things done).
    But I only work on hobby Projects and not with multiple persons.

    • @IAmTimCorey
      @IAmTimCorey  6 лет назад +1

      I can understand that. Hobby projects have a different feel and that is ok. Sometimes you just need to make progress. The more you practice good coding techniques, the easier it will be to create these applications right (or closer to it) the first time. That can be a danger in that you think you don't need to plan if you get into a job situation but for personal stuff, it is fine.

    • @ScriptStudios
      @ScriptStudios 6 лет назад

      IAmTimCorey Amen to that. In my last project I created an WinForms Application for a colleague. I nearly lost my Sanity until I implemented the MVP Pattern. It's crazy how much proper structure can make your life so much easier.

  • @jordytaylor9538
    @jordytaylor9538 3 года назад +2

    I was in the middle of creating my first text-based adventure game, and then I watched your video. I believe I have some editing to do now to my code lol 😂

  • @R.K.Choudary
    @R.K.Choudary 3 года назад +5

    Please zoom the code for better understanding..

    • @IAmTimCorey
      @IAmTimCorey  3 года назад +5

      I can't go back and fix this video, but my newer videos do have larger fonts and zooming when necessary.

    • @hugogogo13
      @hugogogo13 3 года назад +1

      @@IAmTimCorey No problem to read on my side, video is great and quality of image is more than enough, thanks Tim for the amazing content as always !

    • @HP-ol2ux
      @HP-ol2ux 3 года назад

      @@IAmTimCorey It is zoomed in enough

  • @omkarpujari6603
    @omkarpujari6603 4 года назад +1

    Mastering the basics will help us to truly understand why some of the advance stuff like abstract class, Interface is required.
    Thanks for making me understand this approach.

  • @etiennemarais3750
    @etiennemarais3750 5 лет назад +3

    Thank you. Given the stress placed on planning, could you provide some information on how to deal with analysis paralysis and overthinking ? Not approaching planning itself the right way has caused me some major problems and unnecessary complex or otherwise superfluous structures/design/approaches...

    • @IAmTimCorey
      @IAmTimCorey  5 лет назад +3

      I have a course here on RUclips that demonstrates how to plan out an application (C# Application from Start to Finish). That might give you a practical example. As for how to not get locked up, my method is to get an overview of the application, then strip out everything that is not essential to have at launch. Be ruthless. Put everything "nice" in the version 2 list (or beyond) and keep only what is needed. Then get a rough overview of what technologies you will need (to make sure you know how to code them). After that, plan out the first part (something small that you can get running) and go from there. Build small parts of the whole over and over until you have your version 1 application.

  • @mau_lopez
    @mau_lopez 7 лет назад +1

    Great tutorial, very clearly explained, excellent video and audio quality. I agree that the most important practice is planning before even think to execute, but all the practices listed are really helpful, specially number 9 and 10 for me. Thanks a lot !

    • @IAmTimCorey
      @IAmTimCorey  7 лет назад

      I am glad these were helpful for you.

  • @shaquillesgriffin3687
    @shaquillesgriffin3687 4 года назад +2

    Thank you for this it's helped me so much.

    • @IAmTimCorey
      @IAmTimCorey  4 года назад +2

      Glad it helped!

    • @shaquillesgriffin3687
      @shaquillesgriffin3687 4 года назад

      @@IAmTimCorey big problem I faced was deciding what method to use and somewhat always ended up using the complex methods as opposed to the simple efficient way.. You've shown the light lol

  • @JoseLemus68
    @JoseLemus68 7 лет назад

    So glad that you take the time to really explain in detail each of the best practices. I believe it is imperative to always start with a good solid foundation. I am fairly new to programming and having someone teach not only the fundamentals but also best practices and give clear explanations as to why to use them it is awesome. Thank you!

    • @IAmTimCorey
      @IAmTimCorey  7 лет назад

      I am glad you found my video useful. Thanks for watching.

  • @Chess_Improvement
    @Chess_Improvement 5 лет назад +3

    thank you, i like the string builder

  • @fungaionline
    @fungaionline 8 лет назад +2

    Thanks for all your videos, keep up the good work.

  • @ww1flyingace263
    @ww1flyingace263 5 лет назад +3

    One tip I would add is "Keep It Simple". You can do things in a clever tricky way, especially with C#, but it will be hard to maintain that code. Other programmers will have trouble reading your code and figuring out what you are doing; furthermore, if you return to your code months or years later, you yourself will have trouble remembering what it was you were doing.

    • @MrBan001
      @MrBan001 5 лет назад

      huh ? 23:30

    • @IAmTimCorey
      @IAmTimCorey  5 лет назад

      Yeah, that was best practice #6.

    • @ww1flyingace263
      @ww1flyingace263 5 лет назад

      @@MrBan001 Oops! That's what I get for watching this over several days.

  • @Peaceful_Melodies1618
    @Peaceful_Melodies1618 7 лет назад

    Thank you so much for this! I'm still a beginner and I found this video really helpful in understanding a variety of things. I've been watching a couple C# videos about similar topics before but after watching yours it finally 'clicked' and made me understand it :) Greetings from Germany :P

  • @PhilGeissler
    @PhilGeissler 5 лет назад +2

    I wish I would have watched this before I started my project, lol!

    • @IAmTimCorey
      @IAmTimCorey  5 лет назад +1

      Well, it should help for the next project.

    • @PhilGeissler
      @PhilGeissler 5 лет назад

      @@IAmTimCorey Yes sir it certainly will!

  • @pauldyer2957
    @pauldyer2957 7 лет назад

    Great vid buddy. You helped me make my final year project much cleaner, shorter and understandable. Really helps with debugging using simple methods :)

    • @IAmTimCorey
      @IAmTimCorey  7 лет назад

      Ha! Excellent. I tell you what, those small, clear methods that do one thing make your life a whole lot easier during debugging but they also make it easier on the next person who's in your code. Your code reads like a good book instead of like a government report on crop growth.

  • @chrismcgrath7082
    @chrismcgrath7082 6 лет назад +3

    One mistake - you said adding strings is inefficient and you string interpolation is better. This is just not true. At best, the compiler would translate the $string to string additions - so it would be the same, but that's not what the compiler does. It basically turns it into a string.format, so at runtime it has to look for the placeholders and replace them with the values - FAR less efficient than adding strings together.
    Does this mean you should avoid string interpolation? No, it can significantly improve readability which can avoid bugs. As such, the cost is often with it.

    • @IAmTimCorey
      @IAmTimCorey  6 лет назад +1

      You are correct. My initial testing seemed to indicate a performance improvement but it turns out to not be the case. Yes, it is still the recommended formatting method for readability, localization, etc. but the performance isn't great for large number of actions, which is where the stringbuilder comes in. Thanks for pointing it out.

  • @Zulfiqar.Ali.Abbasi
    @Zulfiqar.Ali.Abbasi 4 года назад +1

    When a Wise Man speak there is wisdom in each of his words... I have seen first video and i believe in this quote. Excellent Video and teaching style.. The dept, perfection, professionalism and care reflected in video and comments.. its Quality & Perfection... People complaining about the length and duration of video, not seeing the effort that a person know a way much teaching and explaining and spreading his knowledge with extreme care and responsibility, Bravo...though u can indicate audience level at start so people can skip if they want... as personal gain i have learned 20 tips from it though i want to listen more about 5 and 10 tips, further i have listen that static declaration is not recommended (specially in parallel execution) as well then whats a way around of this? lastly if i may request to explain about the use of inheritance and its usefulness, where its good and where it should not b used. (I know i have written a lot but i think everyone should complement a good work to encourage excellent work in future)... (Y)

    • @IAmTimCorey
      @IAmTimCorey  4 года назад

      Static data storage is not usually wise for a number of reasons, including the fact that the memory can not be released until the enclosing scope (usually the entire application) closes and because it can cause major issues if, like you said, you attempt to access it across threads. Avoid this if possible. There are reasons for static, this is just an abuse. As for inheritance, I explain a bit here: ruclips.net/video/jRkmPRk5j2E/видео.html and I explain more in my Foundation in C# course series ( www.iamtimcorey.com/p/complete-foundation-in-c-course-series ).

  • @timstuff864
    @timstuff864 7 лет назад +3

    Could you explain more how to use "App.config" instead of Global Variables !?

    • @sebastiancadena485
      @sebastiancadena485 5 лет назад

      You can have this in the App.config
      "
      " and use that path in your code when you need it. "var path = ConfigurationManager.AppSettings["Setting1"]".

  • @GarethDoherty1985
    @GarethDoherty1985 8 лет назад

    I particularly liked number 4. but what's ironic about it though is that I recently just refactored so that I combined some methods together as I believed it would be easier to read.... I will now go back an ensure each method performs only one action . I am super new to programming by the way, videos like this are really helping. I have signed up to your mailing list so looking forward to you next content.

  • @ParrhesiaJoe
    @ParrhesiaJoe 3 года назад +3

    I'd like to see a tip about comparing floats for equality.
    float val = 3.0
    val += 1.0
    float testVal = 4.0
    if (val == testVal) console.writeline("equal")
    WRONG
    val might be 3.999999999999999998 and
    testval might be 4.00000000000000001

    • @technoo4891
      @technoo4891 3 года назад +3

      Math.abs(float1-float2) < PRECISION

    • @Shenron666
      @Shenron666 2 года назад +1

      Agree, do never test float or double for equality
      You can do it like in Technoo's comment using float.Epsilon

  • @Chyumgo
    @Chyumgo 6 лет назад +1

    That point about using App.config for storing data across the whole project just blew my mind. Beautiful solution! Thanks a lot, very good video.

    • @IAmTimCorey
      @IAmTimCorey  6 лет назад +1

      I'm glad you got so much value out of it.

  • @tsilb
    @tsilb 2 года назад +5

    2016: Keep It Simple, Stupid
    2022: OAuthConnectorFactory

    • @IAmTimCorey
      @IAmTimCorey  2 года назад +2

      OAuth is always going to be complex. Security is difficult. Simple security usually means easy to break. The OAuth tools at Microsoft do a fairly good job of making it simpler, though. They aren't perfect (not by a long shot), but they do reduce complexity.

    • @tsilb
      @tsilb 2 года назад

      @@IAmTimCorey Yeah, sorry if that came off as standoffish. I was really just commenting on how the enterprise market seems to have abandoned the KISS principle. Every job I've had, I see people adding layers and dependencies that they don't really need. Half the time they get abandoned or forgotten within half a decade, as people come and go; and you end up in Dependency Hell. Not really a criticism of anything, just a likely-unavoidable artifact of the pace of change.

  • @mikerentnelli9580
    @mikerentnelli9580 7 лет назад

    Great tutorial. I find commenting my code to be a "best practice" for me as I can return to something I wrote a long time ago and more easily understand what I was thinking when I wrote the code.

    • @IAmTimCorey
      @IAmTimCorey  7 лет назад

      Been there, done that. I've looked at code for 10+ minutes to try to figure out what it did (while getting frustrated at the author) only to realize later that I was the author of the code. The more you code, the less you remember of the specifics of the code you wrote previously. Code comments can be a big deal when it comes to remembering what the big idea was of the code.

  • @ScilexGuitar
    @ScilexGuitar 4 года назад +2

    Is it ever useful to make a private class?

  • @KoazK1121
    @KoazK1121 8 лет назад

    Hold to the good work Tim, your film is really educational :) Great video that really helped me as a beginner. Waiting for more good advice from your films!

  • @RioTheHitman
    @RioTheHitman 8 лет назад +3

    Cant wait to watch this video too sleepy to watch now

  • @linojrasmolo1015
    @linojrasmolo1015 Год назад

    Hi Tim. This is the best explaination for D in SOLID. At first it is confusing, but after watching two times, the principle and the implementation become a lot more clearer to me. Thank you.

  • @_zzzzzzin
    @_zzzzzzin 2 года назад +4

    the bonus no.2 make me laugh hahahahaha, bcuz i always code without planning hahahaha and i always getting confused with my project

    • @IAmTimCorey
      @IAmTimCorey  2 года назад +1

      Glad you enjoyed it.

    • @_zzzzzzin
      @_zzzzzzin 2 года назад

      @@IAmTimCorey its a big help sir how you keep guiding us in programming

  • @loam
    @loam 5 лет назад +2

    At my job most of the time I get task I think a little bit how to handle it, how to solve it, and then upfront just start writing the code. There was one time when my manager in addition to the big task that I was currently working on created another sub-task, saying writedown UML-schema of my solution to that task and the overall algorithm broadly speaking. I misunderstood his intention and logically figured out that creating UML-chema and wrtining down the overall algorithm should be done before starting to write code. So, I put current task on pause, switched to that subtask (JIRA, you know), spend whole working day creating UML-schema and thinking through what I'm gonna do. Then, my manager contacted me and asked why did I pause that task. When I told him, he said he meant to do that sub-task after I done with the task itself. But anyways, day was already spent, and UML-schema was already made. SO, very next day I switched back to my task and started programming, and what I found was that it was much, much easier to program, when I have thought through the whole process and have clear conception of what I'm doing. Though, there was some divergences from inital UML-schema, but common concept remained the same and it turned out very well.
    P.S. Before that subtask I haven't dealt with UML at all, so I spent half of a day reading books about UML, relations between classes, notations, etc. My final diagramm was somewhat good, my colleague helped my to reorganize things, so that it would be even more plain and cleaner.

    • @IAmTimCorey
      @IAmTimCorey  5 лет назад +2

      Designing before you build is definitely important. It helps you address the logic issues in your code before you get to them.

  • @chriscatignani8206
    @chriscatignani8206 3 года назад +3

    One practice I have is to only have one return from a method...and its at the end.
    Its a little cleaner to follow and debug.

    • @tomthelestaff-iamtimcorey7597
      @tomthelestaff-iamtimcorey7597 3 года назад

      Thanks for sharing your approach.

    • @torrvic1156
      @torrvic1156 Год назад

      Sir! But as far as I know you can only return one type from the method. Their is no other ways. Only tuples can return several types as far as I know. Or did you meant something else?

  • @lizliangh2001
    @lizliangh2001 7 лет назад

    Learned Bonus #1 the hard way. Your video is spot on!

    • @IAmTimCorey
      @IAmTimCorey  7 лет назад +1

      When I teach new developers that principle, they usually laugh or look at me weird. It usually takes a first-hand experience to really drive this point home. It is usually the nicest people that are the ones you shouldn't trust, too. Grandma can be a real hardship on an application. We may develop applications for users, but that doesn't mean we should trust them an inch.

  • @minhtrinh7440
    @minhtrinh7440 5 лет назад +3

    wow I didn't even notice that we skipped number 5

  • @DouglasdeAlencar
    @DouglasdeAlencar 7 лет назад

    Your explanation are very clean! Congratulations and thanks for sharing this with us

    • @IAmTimCorey
      @IAmTimCorey  7 лет назад

      Thanks. I'm glad you liked the video.

  • @theguy9067
    @theguy9067 7 лет назад +3

    In the real world though, I hope you don't call helper libraries "HelperLibrary". It doesn't tell you what it does at all

    • @IAmTimCorey
      @IAmTimCorey  7 лет назад +3

      lol, yeah, I'm actually big on naming things by what they are. In this demo, it really didn't have a better name, but in the real world I wouldn't be a fan of a library being called HelperLibrary. The problem is that this type of demo doesn't really have a good naming structure. I might need to come up with a structure like Microsoft does with their Contoso demo organization.

  • @gerardramonmonte7078
    @gerardramonmonte7078 5 лет назад +2

    Thanks for the video! It actually helped me a lot and I'm going to apply this to my project ASAP. I've been reading the comments and people are just asses... I think you're doing this video for begginers like me so we can start to learn programming with good practices, not to be instant engineers. IMO, finding problems is a part of the learning curve and it will be better for me to find some of the problems people are mentioning about your good practices than someone telling me at first.
    Again, thanks for taking the time for helping all of us :D (Loved the autoupdate video with Squirrel as well hahaha)

    • @IAmTimCorey
      @IAmTimCorey  5 лет назад

      I am glad you enjoyed the video.

    • @hardgrafter2787
      @hardgrafter2787 5 лет назад

      I'm an experienced professional WPF developer. These videos are excellent & wish there was a resource around like this when I was learning as a beginner.

  • @MrKimThomsen
    @MrKimThomsen 3 года назад +3

    One of my Best practices: is keep it Simple, Stupid :)

  • @MorgurEdits
    @MorgurEdits 4 года назад

    As a beginner, I think this is one of the most important videos I have seen, after learning the bare bone basics of coding.
    Since as a new code writer its really good to start doing these things now
    and never create those bad habits to begin with.
    Half way thru so still 30 minutes of these really valuable and informative tips available.
    Thank you so much Tim!

  • @AyyyyyyyyyLmao
    @AyyyyyyyyyLmao 5 лет назад +11

    1.25 speed ftw!

    • @IAmTimCorey
      @IAmTimCorey  5 лет назад

      Thanks for watching.

    • @kitsurubami
      @kitsurubami 4 года назад

      I'm always on x2 unless it's a video where the audio is unimportant. In those cases i do x8 c:

    • @tirusbrown
      @tirusbrown 4 года назад

      Disagree! I'm enjoying this like cool elevator muzak, playing in the background - woohoo! So mellow...

  • @Garamondj
    @Garamondj 8 лет назад +1

    Another great video Tim, glad you are sharing...

  • @lordamateur
    @lordamateur 5 лет назад +6

    Best practice #13: watch Tim Correy's videos

  • @tiosatria9919
    @tiosatria9919 4 года назад

    i'm scratching my head knowing that i do things inefficiently all the time. thank you for this!

  • @mehdialvandi9450
    @mehdialvandi9450 3 года назад +3

    you are perfect

    • @IAmTimCorey
      @IAmTimCorey  3 года назад +4

      A bit of a stretch there but I appreciate the sentiment.

  • @mykulpierce
    @mykulpierce 3 года назад +1

    Fantastic thank you for this video. I am in the learning process for c# and I have a data storage technical support background. So my first instinct was to look up as practices so that I'm learning the right way! This definitely gives me a lot to think about and it's trajectory for what to aim my learning around.

    • @IAmTimCorey
      @IAmTimCorey  3 года назад +1

      I am glad it was so helpful.

  • @wojciechdziurawiec341
    @wojciechdziurawiec341 7 лет назад +3

    Can't agree on "Use curly braces for if statemets"
    1. You can easily see just by having tab before it
    2. Code is shorter so you can see more without scrolling
    Not speaking about ternary operator (?:) because that is a whole different story

  • @torrvic1156
    @torrvic1156 Год назад

    There are no words to say how great and realistic this advices are. Thank you for sharing them with us!