Top 10 C# Best Practices (plus bonuses)

แชร์
ฝัง
  • เผยแพร่เมื่อ 7 ส.ค. 2024
  • To sign up for announcements about new videos and exclusive discounts, fill out this form: signup.iamtimcorey.com/ (your email will be kept safe and you will not be spammed).
    Learn what I believe are the top 10 best practices for C# developers. When you are programming in Visual Studio, I think these will help you do so better, more efficiently, and with less bugs. Once you see all 10 (plus the bonuses at the end), let me know what you think in the comments. Did I miss one? Do you disagree with one?
    Thanks to Ralfs K and Julio M, here is a list of the best practices along with their video times:
    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

ความคิดเห็น • 1.2K

  • @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 3 ปีที่แล้ว +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.

  • @jonathansaindon788
    @jonathansaindon788 5 ปีที่แล้ว +63

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

    • @IAmTimCorey
      @IAmTimCorey  5 ปีที่แล้ว +8

      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 3 ปีที่แล้ว +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 3 ปีที่แล้ว +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!

  • @lautarolavecchia5995
    @lautarolavecchia5995 3 ปีที่แล้ว +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  3 ปีที่แล้ว +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

  • @smartdatalearning3312
    @smartdatalearning3312 3 ปีที่แล้ว +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 :)

    • @IAmTimCorey
      @IAmTimCorey  4 ปีที่แล้ว +1

      You are most welcome.

  • @kermy2110
    @kermy2110 5 ปีที่แล้ว +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  5 ปีที่แล้ว

      I am glad you found my content valuable.

  • @evaikuun
    @evaikuun 4 ปีที่แล้ว +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!

  • @vinipickrodt
    @vinipickrodt 4 ปีที่แล้ว +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.

  • @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.

  • @mariannajedruch4614
    @mariannajedruch4614 5 ปีที่แล้ว +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  5 ปีที่แล้ว

      You are most welcome. Thanks for watching.

  • @needler1234
    @needler1234 6 ปีที่แล้ว

    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  6 ปีที่แล้ว

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

  • @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!

  • @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.

  • @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.

  • @trackchampz6991
    @trackchampz6991 7 ปีที่แล้ว

    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.

  • @raskand1977
    @raskand1977 6 ปีที่แล้ว +2

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

  • @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!

  • @codingwithgyver1637
    @codingwithgyver1637 3 ปีที่แล้ว +3

    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  3 ปีที่แล้ว +1

      Thanks for sharing that tip.

  • @itisito4769
    @itisito4769 3 ปีที่แล้ว +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  3 ปีที่แล้ว +1

      I am glad it was so clear and helpful.

  • @VitaliyParitskiy
    @VitaliyParitskiy 3 ปีที่แล้ว +1

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

    • @IAmTimCorey
      @IAmTimCorey  3 ปีที่แล้ว +1

      Glad it was helpful!

  • @Metanis
    @Metanis 6 ปีที่แล้ว +3

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

    • @IAmTimCorey
      @IAmTimCorey  6 ปีที่แล้ว

      Glad you enjoyed it.

    • @DefaultUser3301
      @DefaultUser3301 6 ปีที่แล้ว

      Couldn't agree more

    • @Layarion
      @Layarion 6 ปีที่แล้ว

      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;

  • @jonwoodhead000
    @jonwoodhead000 3 ปีที่แล้ว +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  3 ปีที่แล้ว

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

  • @BillSchultz70
    @BillSchultz70 7 ปีที่แล้ว +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

  • @edi_gun_awan
    @edi_gun_awan 3 ปีที่แล้ว +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  3 ปีที่แล้ว

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

  • @johannes8410
    @johannes8410 ปีที่แล้ว +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  ปีที่แล้ว +1

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

  • @VISHNUKUMAR-bh8uj
    @VISHNUKUMAR-bh8uj ปีที่แล้ว +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  ปีที่แล้ว

      Thanks for sharing.

    • @MD-vs9ff
      @MD-vs9ff ปีที่แล้ว +1

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

  • @Bobodeveloper
    @Bobodeveloper 7 ปีที่แล้ว

    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. :)

  • @JoseLemus68
    @JoseLemus68 6 ปีที่แล้ว

    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  6 ปีที่แล้ว

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

  • @Winged4Ever
    @Winged4Ever 4 ปีที่แล้ว +11

    My best practice? Learn from Tim Corey! : P

  • @donv1to76
    @donv1to76 4 ปีที่แล้ว +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

    • @IAmTimCorey
      @IAmTimCorey  4 ปีที่แล้ว +2

      Yep, those are good ones.

  • @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!

  • @mykulpierce
    @mykulpierce 2 ปีที่แล้ว +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  2 ปีที่แล้ว +1

      I am glad it was so helpful.

  • @ApacheGamingUK
    @ApacheGamingUK 3 ปีที่แล้ว +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?

  • @souvikdas1267
    @souvikdas1267 5 ปีที่แล้ว +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  5 ปีที่แล้ว +1

      I did a whole video on DRY: th-cam.com/video/dhnsegiPXoo/w-d-xo.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.

  • @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.

  • @Chyumgo
    @Chyumgo 5 ปีที่แล้ว +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  5 ปีที่แล้ว +1

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

  • @cirezno5960
    @cirezno5960 3 ปีที่แล้ว +3

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

  • @Chess_Improvement
    @Chess_Improvement 4 ปีที่แล้ว +3

    thank you, i like the string builder

  • @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.

  • @KoazK1121
    @KoazK1121 7 ปีที่แล้ว

    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!

  • @etiennemarais3750
    @etiennemarais3750 4 ปีที่แล้ว +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  4 ปีที่แล้ว +3

      I have a course here on TH-cam 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.

  • @InformationSensation
    @InformationSensation 5 ปีที่แล้ว +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  5 ปีที่แล้ว +3

      It is a big one to learn, for sure.

  • @GregGagnaux
    @GregGagnaux 7 ปีที่แล้ว

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

  • @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.

  • @shaquillesgriffin3687
    @shaquillesgriffin3687 3 ปีที่แล้ว +3

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

    • @IAmTimCorey
      @IAmTimCorey  3 ปีที่แล้ว +2

      Glad it helped!

    • @shaquillesgriffin3687
      @shaquillesgriffin3687 3 ปีที่แล้ว

      @@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

  • @RalfsBalodis
    @RalfsBalodis 3 ปีที่แล้ว +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

  • @sal96ali
    @sal96ali 4 ปีที่แล้ว +2

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

  • @mau_lopez
    @mau_lopez 6 ปีที่แล้ว +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  6 ปีที่แล้ว

      I am glad these were helpful for you.

  • @gene7433
    @gene7433 7 ปีที่แล้ว +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 7 ปีที่แล้ว

      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.

  • @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.

  • @fungaionline
    @fungaionline 7 ปีที่แล้ว +2

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

  • @nhanth
    @nhanth 6 ปีที่แล้ว +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.

  • @ScilexGuitar
    @ScilexGuitar 3 ปีที่แล้ว +3

    Is it ever useful to make a private class?

  • @Hi_Tech
    @Hi_Tech 5 ปีที่แล้ว +4

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

    • @IAmTimCorey
      @IAmTimCorey  5 ปีที่แล้ว +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 5 ปีที่แล้ว

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

  • @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.

    • @IAmTimCorey
      @IAmTimCorey  ปีที่แล้ว

      I am glad it was helpful.

  • @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!

  • @ajayvijayh
    @ajayvijayh 7 ปีที่แล้ว +6

    summary of video is at 50:03

  • @rogerbenson8493
    @rogerbenson8493 3 ปีที่แล้ว +3

    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)

    • @IAmTimCorey
      @IAmTimCorey  3 ปีที่แล้ว +1

      Good points, thanks

  • @cemkalkan476
    @cemkalkan476 7 ปีที่แล้ว

    Thanks for sharing Tim I've joined your list

  • @Garamondj
    @Garamondj 7 ปีที่แล้ว +1

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

  • @PhilGeissler
    @PhilGeissler 4 ปีที่แล้ว +2

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

    • @IAmTimCorey
      @IAmTimCorey  4 ปีที่แล้ว +1

      Well, it should help for the next project.

    • @PhilGeissler
      @PhilGeissler 4 ปีที่แล้ว

      @@IAmTimCorey Yes sir it certainly will!

  • @Sad-Lemon
    @Sad-Lemon 6 ปีที่แล้ว +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  6 ปีที่แล้ว +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.

  • @AdebayoAdegbemboAsa
    @AdebayoAdegbemboAsa 5 ปีที่แล้ว +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  5 ปีที่แล้ว

      You are welcome.

    • @jimmccoydura9717
      @jimmccoydura9717 5 ปีที่แล้ว

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

    • @AdebayoAdegbemboAsa
      @AdebayoAdegbemboAsa 5 ปีที่แล้ว

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

    • @jimmccoydura9717
      @jimmccoydura9717 5 ปีที่แล้ว

      @@AdebayoAdegbemboAsa Cool. Thanks.

  • @BenKyoBaduk
    @BenKyoBaduk 7 ปีที่แล้ว

    This is extremely awesome, thank you!

  • @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.

  • @MichaelNikolaus
    @MichaelNikolaus 5 ปีที่แล้ว +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  5 ปีที่แล้ว

      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 5 ปีที่แล้ว +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. :)

  • @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 :)

  • @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

  • @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.

  • @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"]".

  • @torrvic1156
    @torrvic1156 ปีที่แล้ว

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

  • @MBlackAlpha
    @MBlackAlpha 5 ปีที่แล้ว +1

    Thanks a lot for your videos. Very helpful and I learn a lot seeing examples of what you're explaining.

  • @R.K.Choudary
    @R.K.Choudary 2 ปีที่แล้ว +5

    Please zoom the code for better understanding..

    • @IAmTimCorey
      @IAmTimCorey  2 ปีที่แล้ว +5

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

    • @hugogogo13
      @hugogogo13 2 ปีที่แล้ว +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 2 ปีที่แล้ว

      @@IAmTimCorey It is zoomed in enough

  • @_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

  • @didierfolly
    @didierfolly 6 ปีที่แล้ว

    Hi Tim. Thanks a lot for your video. I enjoyed it so much. Keep doing great videos like this one. "Keep it simple" is the most important to me.

    • @IAmTimCorey
      @IAmTimCorey  6 ปีที่แล้ว

      Simple is hard, but that is when you know you are doing something right when you can do a complex task with simple code.

  • @nanibanani7560
    @nanibanani7560 4 ปีที่แล้ว

    to be honest, i normally just check and watch for videos of youtube uploaders wich dont use music, any unsults or respectless speech , or upshowing repaetendly half naked women and stuff like that in theire videos. But in this case i want to say that u fullfilled my basic requirements surely more 100% and i want to tell you that you are just professional mr. corey . what you are doing is just clean and professional. PROFESSIONAL!
    surely suscribe

    • @IAmTimCorey
      @IAmTimCorey  4 ปีที่แล้ว

      I am glad my content is helpful to you.

  • @ww1flyingace263
    @ww1flyingace263 4 ปีที่แล้ว +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 4 ปีที่แล้ว

      huh ? 23:30

    • @IAmTimCorey
      @IAmTimCorey  4 ปีที่แล้ว

      Yeah, that was best practice #6.

    • @ww1flyingace263
      @ww1flyingace263 4 ปีที่แล้ว

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

  • @chrismcgrath7082
    @chrismcgrath7082 5 ปีที่แล้ว +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  5 ปีที่แล้ว +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.

  • @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 😂

  • @jarno27
    @jarno27 7 ปีที่แล้ว

    Thank you Tim! Great stuff. Subscribed!

    • @IAmTimCorey
      @IAmTimCorey  7 ปีที่แล้ว

      Thanks and welcome aboard.

  • @ParrhesiaJoe
    @ParrhesiaJoe 2 ปีที่แล้ว +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 2 ปีที่แล้ว +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

  • @mehdialvandi9450
    @mehdialvandi9450 2 ปีที่แล้ว +3

    you are perfect

    • @IAmTimCorey
      @IAmTimCorey  2 ปีที่แล้ว +4

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

  • @kerandonovan7255
    @kerandonovan7255 4 ปีที่แล้ว

    Awesome. I had some questions in my mind for the last two days and this video answered them I am glad I watched.

  • @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#.

  • @RioTheHitman
    @RioTheHitman 7 ปีที่แล้ว +3

    Cant wait to watch this video too sleepy to watch now

  • @MrKimThomsen
    @MrKimThomsen 3 ปีที่แล้ว +3

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

  • @FurryDanOriginal
    @FurryDanOriginal 6 ปีที่แล้ว +1

    Many props to you. First of all, as a beginner I'm actually quite happy that I did tend to do most of these just because it seemed to make sense to me but those which I didn't do / didn't knew the purpose of doing were thanks to the awesome examples really easy to grasp. Secondly, from watching multiple of your videos I can tell that you are really good at teaching things since on your videos I hardly ever need to repeat any parts to understand the purpose of doing them unlike on some other tutorials where I might repeat something a dozen times to understand the idea behind it.
    Thanks for all of your tutorials and the really great explanations behind everything you talk about.

    • @IAmTimCorey
      @IAmTimCorey  6 ปีที่แล้ว

      Awesome! I'm glad you are getting a lot out of the videos.

  • @prempaulj
    @prempaulj 3 ปีที่แล้ว

    Thanks much, Tim. The tips in your video are very useful. Without learning C# polymorphism and inheritance, I did not have the confidence to code. But from your video I got the confidence to start a project and learn what is required for the project.

    • @IAmTimCorey
      @IAmTimCorey  3 ปีที่แล้ว

      I'm glad my content has been helpful to you.

  • @lordamateur
    @lordamateur 4 ปีที่แล้ว +6

    Best practice #13: watch Tim Correy's videos

  • @minhtrinh7440
    @minhtrinh7440 4 ปีที่แล้ว +3

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

    • @IAmTimCorey
      @IAmTimCorey  4 ปีที่แล้ว

      Me neither until near the end. :-)

    • @LeBronJames-ns6to
      @LeBronJames-ns6to 4 ปีที่แล้ว

      He skipped a bunch. Still great tips tho

  • @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.

  • @GarethDoherty1985
    @GarethDoherty1985 7 ปีที่แล้ว

    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.

  • @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...

  • @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.

  • @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.

  • @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?

  • @prasantapradhan5449
    @prasantapradhan5449 4 ปีที่แล้ว +5

    i was expecting more advance not basic....

    • @IAmTimCorey
      @IAmTimCorey  4 ปีที่แล้ว +3

      Best practices aren’t typically advanced. They are foundational things you build everything on.

    • @prasantapradhan5449
      @prasantapradhan5449 4 ปีที่แล้ว

      yes, thanks

  • @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.

  • @ef1196
    @ef1196 3 ปีที่แล้ว

    Hello Tim,
    I just found your channel and I am delighted! As a self taught developer I am always looking for ways to improve my skills. Your collection is just what I was looking for!

  • @arnaldofernandez
    @arnaldofernandez 2 ปีที่แล้ว +20

    Thank God for 1.5x playback speed 😄

    • @mauricemakesmovies
      @mauricemakesmovies 2 ปีที่แล้ว +2

      What's the point of your comment?

    • @arnaldofernandez
      @arnaldofernandez 2 ปีที่แล้ว +7

      @@mauricemakesmovies advice other people so they can save time.

    • @mauricemakesmovies
      @mauricemakesmovies 2 ปีที่แล้ว +3

      @@arnaldofernandez Riiiight.

    • @ivanmihaylov4365
      @ivanmihaylov4365 2 ปีที่แล้ว +1

      @@mauricemakesmovies It was helpful actually.

    • @mauricemakesmovies
      @mauricemakesmovies 2 ปีที่แล้ว +2

      @@ivanmihaylov4365 You can't be serious lmao