5 Ways to Improve Your Code

  Рет қаралды 74,504

Continuous Delivery

Continuous Delivery

Күн бұрын

What can you do to improve your code? Readable code, clean code is easier to work with and easier to change. So how do you get better at coding, what are some tips for coding beginners, and for more experienced developers, that will result in better code? What are the programming and coding tips that you can adopt to make it easier to create better software faster?
Being a software developer is not just about being able to write code that a computer can understand, it is about organising ideas so that you, and others, can understand it too. Writing software is challenging, software is abstract, almost infinitely flexible and extremely fragile. All this means that the quality of our choices, the design of our code matters.
In this episode, Dave Farley shows five common, really bad, examples that we see in code all the time and offers his advice on how to fix them, and how to improve your software, and your coding. Software engineering is about the continuous delivery of valuable software into the hands of our users: writing good quality code is an important part of that discipline.
Some of the content in this episode was inspired by this blog post: blog.codinghorror.com/code-sm...
-------------------------------------------------------------------------------------
🎓 CD TRAINING COURSES 🎓
If you want to learn Continuous Delivery and DevOps skills, check out Dave Farley's courses ➡️ bit.ly/DFTraining
📖 Dave’s NEW BOOK "Modern Software Engineering" is now available on
Amazon ➡️ amzn.to/3DwdwT3
In this book, Dave brings together his ideas and proven techniques to describe a durable, coherent and foundational approach to effective software development, for programmers, managers and technical leads, at all levels of experience.
📖 "Continuous Delivery Pipelines" by Dave Farley
paperback ➡️ amzn.to/3gIULlA
ebook version ➡️ leanpub.com/cd-pipelines
📖 The original "Continuous Delivery" book by Dave Farley and Jez Humble
➡️ amzn.to/2WxRYmx
📧 JOIN CD MAIL LIST 📧
Keep up to date with the latest discussions, free "How To..." guides, events and online courses.
➡️ bit.ly/MailListCD
-------------------------------------------------------------------------------------
Dave Farley's Blog ➡️ bit.ly/DaveFWebBlog
Dave Farley on Twitter ➡️ bit.ly/DaveFTwitter
Dave Farley on LinkedIn ➡️ bit.ly/DaveF-LI
--------------------------------------------------------------------------------------
📚 BOOKS:
Refactoring: Improving the Design of Existing Code (Addison-Wesley Signature Series (Fowler)) ➡️ amzn.to/30ntgaK
Refactoring: Ruby Edition (Addison-Wesley Professional Ruby Series) ➡️ amzn.to/2XGbuhi
Working Effectively with Legacy Code, Michael Feather ➡️ amzn.to/3hP0F4z
Clean Code: A Handbook of Agile Software Craftsmanship (Robert C. Martin) (Robert C. Martin Series) ➡️ amzn.to/3aLXGad

Пікірлер: 306
@ZenoDovahkiin
@ZenoDovahkiin 3 жыл бұрын
"An idiot admires complexity, a genius admires simplicity, a physicist tries to make it simple. An idiot will make everything so complicated you'll think he's a god for understanding it." -paraphrased, Terry A. Davis As deranged as he was, these are words to live by, both for designing software and life in general.
@LPFan33
@LPFan33 3 жыл бұрын
RIP based Terry
@tomwimmenhove4652
@tomwimmenhove4652 2 жыл бұрын
"The greatest programmer that ever lived"
@ashishmishra1688
@ashishmishra1688 3 жыл бұрын
*5 Ways to Improve Your Code* 1. Minimize the need for Comments, Code should explain what it does. Write a comment to explain [why you make that choice] rather explaining [what it does]. 2. Avoid Long Methods (Avoid creating long methods it's hard to read, maintain & troubleshoot), prefer short methods over long methods 3. Avoid Long Parameter List (use max 2 parameters) 4. Avoid Duplicated Code (Duplicated code is maintenance overhead) 5. Avoid Complex Conditional code (Avoid large block of code in single condition)
@Sorc47
@Sorc47 3 жыл бұрын
I'm so glad I found this channel. It's full of gold. Thank you very much for your videos.
@ContinuousDelivery
@ContinuousDelivery 3 жыл бұрын
Thank you
@alschneider5420
@alschneider5420 Жыл бұрын
The biggest problem is that programmers code before structuring and/or understanding the data. On many contracts I am asked why I am not coding. I say I am organizing the data. That does not go over well. I get heat from management. I persist and normally finish with a very stable solution before the allotted time. I have worked on pacemakers, motor control, heat, HVAC, aviation, proprietary RTOSs, search systems and more. I am a very big fan of structuring my data like organized MUD.
@BigKevSexyMan
@BigKevSexyMan 3 жыл бұрын
Here's what I usually do with comments: 1) Describe the business purpose of a function or method. Fellow developers can usually determine what you are doing, but why you are doing it can be even more valuable and not apparent from the code alone. 2) Describe assumptions and scenarios where the logic may break under certain data inputs (although it's generally better to just do proper exception handling) - For instance, I had to write a service that wakes up and copies a daily file from sftp and appends the date to a very specific name. However, there can technically be more than one file since it's just an sftp server. So we decided to just overwrite the old daily file when that happens. We describe that in a comment so when people look back at the code, they know it's intended behavior, and can react accordingly. 3) Describe unintuitive bits of code you either can't re-write(ie. to make a third party's code work) or don't have time to re-write. Bring it up in code reviews! Maybe others will have suggestions. 4) TODOs if you still have more development you would like to do at a future date. Do these even if you haven't submitted your code for review. You never know when you have to pivot to a new project/bug and will need to remind yourself where you left off. Obviously you need to make sure your code works properly before it gets submitted, but there will always be things that you would like to do, but don't have time. I think good comments generally arise out of a respect for time. Both yours and your fellow developers. If a comment gives them an easier understanding of what's going on, then do it. But don't waste their time with clutter.
@tldw8354
@tldw8354 Жыл бұрын
best guidance about comments ever. period
@thomas-sinkala
@thomas-sinkala 3 жыл бұрын
Finally a channel that offers unpaid advice. Just what I need for my new role. I hit that subscribe button faster than anything else.
@MarceloSantos-pt3hj
@MarceloSantos-pt3hj 3 жыл бұрын
"If you're really good you're allowed to have an else clause as well" hahah subtle but made me laugh
@ContinuousDelivery
@ContinuousDelivery 3 жыл бұрын
😁 😎
@visiongt3944
@visiongt3944 3 жыл бұрын
@@ContinuousDelivery Hello sir, I am a senior undergrad Comp Sci major and my goal currently is to get a job by the time I graduate in December 2021. I would like to know whether I should be going for learning different tech stacks, CI/CD, Cloud etc. or just get a good GPA and know how to solve data structures problems.
@ContinuousDelivery
@ContinuousDelivery 3 жыл бұрын
​@@visiongt3944 My main advice is to write as much code as you can. Find projects that interest or excite you, play with different kinds of things, maths problems, graphics, little tools to help you do something, almost anything. Next I would advise that you learn TDD, watch a few of my videos on that topic, I hope that they may help, but also pick a 'coding kata' to practice. Take a look here for some inspiration cyber-dojo.org/ On tech-stacks, I don't think that should be very important, however, there are lots of orgs that aren't very good at interviewing and so all they go on is a check-list of tech. That is a terrible way to interview anyone, but particularly bad for people just starting out. If I were in your place now, knowing what I know, I would treat that as a bad sign for that employer, but, being pracgmatic, getting your first job is hard and so you may have to play that game. My advice though, don't treat them like a collection, pick tools and tech that you like working with and get good with that. You can look at what sorts of tech are popular in places where you would like to work, or just pick the most popular things generally. Python and Java and Javascript are popular, but it does depend on what you want to do. As for frameworks or platforms, I wouldn't worry too much about that, most orgs will use a few technologies and it will be hit or miss if you have the ones that they use. Also they are ephemeral, they will change all the time through your career. The skill that you will/should develop is the skill to learn new ones. You get that from doing real work and thinking about what is happening in terms of design, not just the sytax of the use of framework A over framework B. Take a look at this for thinking about languages, dzone.com/articles/top-10-most-promising-programming-languages-for-20 but first get comfortable with one (oh and with TDD 😁 😎).
@hi3694
@hi3694 3 жыл бұрын
@@ContinuousDelivery Great advice Dave. I'm just starting out in software engineering and this is extremely useful. Many thanks from a fellow brit!
@ContinuousDelivery
@ContinuousDelivery 3 жыл бұрын
​@@hi3694 Thanks
@zpinacz
@zpinacz 3 жыл бұрын
I am glad I found your channel. Very clear and to the point explanation of not very simple problems !
@pablostraub
@pablostraub 3 жыл бұрын
This video is another jewel from Continuous Delivery. I've seen about half a dozen of your videos and so far all of them are brilliant. THANKS!
@Guido_XL
@Guido_XL 3 жыл бұрын
Couldn't agree more. It somehow reminds me of "The Pragmatic Programmer" by Andrew Hunt and David Thomas.
@BBuckB
@BBuckB 3 жыл бұрын
Thank you very much, Dave, for sharing your knowledge and for the awesome content of your channel. You make your points in a very light and comprehensive way, and put our minds to work along your argumentation. Very well explained and reasoned. Once again, thank you and keep up the excellent work, I'm looking forward to more content. Best regards, from all across the Atlantic ocean!
@Oswee
@Oswee 3 жыл бұрын
Use the scout rule - leave the code better than you found it. :)
@ContinuousDelivery
@ContinuousDelivery 3 жыл бұрын
Yes
@ericpmoss
@ericpmoss 3 жыл бұрын
@@ContinuousDelivery I agree, but wow are there office politics to be considered, too. I had untold trouble even when I could (actually ESPECIALLY when I could) prove that I improved code. Some co-workers don't like that, and coding is often a social endeavour.
@JeanFrancoisDesrosiers
@JeanFrancoisDesrosiers 3 жыл бұрын
@@ericpmoss exactly. when the product owner moto is : if it ain't broke don't fix it, you are not allowed to touch any line of code that are not directly impacting your functional changes.
@LPFan33
@LPFan33 3 жыл бұрын
I also like that one: "Make the change simple, then make the change". So refactor before making a change. But don't forget to do it in separate commits!
@Alexagrigorieff
@Alexagrigorieff 3 жыл бұрын
I thought it's "bury your shit in a hole in the ground"
@ZlothZloth
@ZlothZloth 3 жыл бұрын
After all my years, I still don't see why I should break up big hunks of code. If you've got duplicate code then, yeah, that's no good. But if it's proper code that isn't repeated, I've got no problem with it as it saves me from having to jump around in the code. It doesn't seem any easier to maintain but maybe that's because my errors nearly always give me the line number where the break happened? If it weren't for those, finding the 'object not set' error in the 500-line Init() routine would certainly be a nightmare. P.S. When you said the if statement was 100+ lines long, I thought you meant the actual logic portion, not the block of code. I about had a heart attack!
@LPFan33
@LPFan33 3 жыл бұрын
Because it's divide and conquer. It's a lot easier for nasty bugs to hide in huge hunks of code than it is in small single-purpose bits. It's also easier to scroll ignore and scroll past details you are not interested in because they will be one-line landmarks in your code rather than the actual 20 line calculation or whatever.
@vkresch3478
@vkresch3478 3 жыл бұрын
Thanks for sharing this informative video! Keep up the good work!
@ubercorey
@ubercorey 3 жыл бұрын
As a beginner, for months I've been trying to understand what was meant by clean code or eloquent code, etc. THANK YOU!
@Spiderboydk
@Spiderboydk 2 жыл бұрын
There does not exist any rigorous definition of what "clean code" means. It's largely informed by gut feeling, and any attempt to capture the meaning via rules of thumb fails half the time anyway.
@ubercorey
@ubercorey 2 жыл бұрын
Interesting, that helps orient my mind properly on this subject, thank you for your reply.
@Spiderboydk
@Spiderboydk 2 жыл бұрын
​@@ubercorey No problem. :-) This field is extremely opinionated, so always asking why and putting serious thought into peoples answers will cut through most of the bullshit. For example, the fact that Continuous Delivery uses science and statistics to inform his opinions, means he should be listened to. Also, be very suspicious of any dogma. Personally I try to avoid using nebulous words like clean. I try to find more precise words to convey what I actually mean by clean. For example "this code is easy to read/understand" or "this code is easy to edit" or "this code follows my organisations best practices" rather than "this code is clean".
@ubercorey
@ubercorey 2 жыл бұрын
I have absolutely noticed that about your way of speaking and teaching.
@thingsiplay
@thingsiplay 3 жыл бұрын
3:05 Also code like this, with single letter parameter names makes it hard to search for variable names or even search and replace automatically.
@muskaos
@muskaos 3 жыл бұрын
Also makes it hard to understand if there is a 9 month break between the last time you looked at it and now. I use human readable variable names for future me coming back to code I wrote a year earlier. :)
@nataliaovriakh8689
@nataliaovriakh8689 3 жыл бұрын
Great video! Thanks!!!
@DiegoAguilera
@DiegoAguilera 3 жыл бұрын
Really good video, thank you. I’m looking forward to watch more content from you.
@ContinuousDelivery
@ContinuousDelivery 3 жыл бұрын
Thanks
@fmitterb
@fmitterb 3 жыл бұрын
The longest function I have encountered while refactoring legacy code was around 3000 lines of code and had around 20 parameters. 700 lines of it were nearly exactly copy&pasted within the same function with minimal change.
@sexygeek8996
@sexygeek8996 3 жыл бұрын
I lost count of how many times I inherited code with massive copy-and-paste instead of functions and separate permanent branches for versions with minor differences. Everyone's concern was to do the immediate task as quickly as possible without regard to any issues that might arise in the future.
@grrr_lef
@grrr_lef 3 жыл бұрын
To add to the chef analogy: You don't want your "oranges à vif" to taste like garlic just because you did not clean your knive.
@ContinuousDelivery
@ContinuousDelivery 3 жыл бұрын
Ahh, separation of concerns for chefs - I like it! 😎
@jwadaow
@jwadaow 3 жыл бұрын
That sounds delicious.
@CynicalOldDwarf
@CynicalOldDwarf 3 жыл бұрын
"I don't want salmonella because you decided to cut the chicken and vegetables on the same block", probably an easier to understand example :)
@TheJacklwilliams
@TheJacklwilliams 2 жыл бұрын
@@CynicalOldDwarf Maybe, but a little crazy. Most learn very early to separate the two, completely. Not so much in coding.
@porky1118
@porky1118 3 жыл бұрын
I agree about many parameters. You should pack multiple related parameters into structs. For example a vector instead of (int x, int y), especially if you have multiple of them. Same for structs/classes with many fields: If some belong together, pack them into a substruct, especially if you might need multiple of them.
@wordsworth2114
@wordsworth2114 3 жыл бұрын
Comment every line! And I mean every line. I learned this the tough way from a colleague in my first software engineering job. I hated his code for it; I kept repeating to him, like you, that code should be self commenting, etc, and coming out with all the arguments against comments that we all know very well. But after 3yrs working with him (back then) I couldn't deny an unavoidable truth - his code never, and I mean never, not once, had a bug in it! How could I tell this programmer what to do, when I couldn't say the same for my code. That was tough for me to admit. But I opened my eyes, and had a go at copying his style, commenting every line ... like you say, it's important to comment sincerely, not just flippantly saying what the syntax is doing ... and to my amazement, overnight, I went from producing typically buggy code like most programmers, to producing completely bug free code just like the guy I was now copying. So what gives? What is making the difference? It's quite simple, and became abundantly apparent once I tried it. Pedantically commenting *every* line (when done sincerely, and *not* simply describing the syntax, etc), makes sure that you know what you are doing, and acts as a comprehensive self-review. It sounds like "well, durh!!" but I subsequently found it amazing how often I'd write a line of code, go to write the comment above it, then realise "ah, hang on, that's not quite what I intended to do", or realise a subtle short coming with the algorithm I was writing, etc. Often even going back to completely re-write the function when I suddenly realised the whole function wasn't doing quite what I intended, or that it might be subject to problematic edge cases that I hadn't thought of when I set out writing the function, but that had then sprung to mind when writing the comments. Even simple lines like incrementing a counter (index++). Once you come to write a meaningful comment for that increment, for example "move to the next element in the zzz list" (or whatever the context)... that prompts you to think... "ah... but what if we're now past the end of the array? have I put the check in?". And so on. All of this being identified and realised before the code has ever been run, not even from the development environment. And commenting every line, forces you to make sure each line has a clear, simple role. If you have a complex line that's doing a lot, then commenting every line forces you to break it up. And that often also reveals problems with that code that you'd written. It's funny how typically the most difficult lines to comment in this manner, are the ones where you're not really sure what you're doing. Pedantically commenting every line means there's no hiding! You can't get away with just writing a line of code in the 'hope' that it's probably correct. If you can't write a meaningful comment above a line, if you're being honest with yourself, it's usually because you don't *really* know what you're doing, and realistically you need to re-think it until you do know what you're doing. A professional programmer should not need to step through a section of code they are writing on the debugger in order to evaluate what it's doing!! A professional programmer should confidently know what each and every line of code will do when they write it!! For that professional programmer, commenting every line of code, at the time of writing, is easy. In fact, that's probably a good guide for programmers to self-evaluate how far they have come as a professional. If you are able to comment every line of code, meaningfully, as you write it, that's probably a sign of a good, experienced professional. The programmers you should be concerned about are the ones who can't - and therefore obviously won't - buy into this approach. I've subsequently had lots of arguments with colleagues who think I'm just a thick, dumb idiot for doing it. The majority throwing the same arguments back at me, that I used to throw at that original colleague all those years ago. Some try to setup code style rules to prohibit it. But I always have one challenge for them. I say I'll listen to you, if you produce code as bug free as I, and that original colleague, do. In the 20 yrs since I learned this technique from that original colleague in my first job, no subsequent colleague has yet met that challenge - though a number have listened and observed, and tried this approach and become converts. Ironically, some of those I've argued this with over the years have also argued quite vociferously that (and I quote one them) "Software is always buggy!". They don't believe you can write bug free code. They refuse to believe you. And refuse to even give it a shot. They believe they are right - that software is always buggy - and, in practice their own code invariably reinforces their claims!
@LPFan33
@LPFan33 3 жыл бұрын
oh god. I couldn't even finish this comment, it's almost as if you commented every line in your comment. If you need to write comments to evaluate what you've coded, where the hell are your unit tests?
@jamescater66
@jamescater66 3 жыл бұрын
TL:DR
@wisanuupatumphun7831
@wisanuupatumphun7831 3 жыл бұрын
Cool, just found your channel, well and short explanation, Thank you. BTW, subscribed.
@ContinuousDelivery
@ContinuousDelivery 3 жыл бұрын
Awesome, thank you!
@otmanm4095
@otmanm4095 3 жыл бұрын
Awesome ! Thanks sharing!
@ContinuousDelivery
@ContinuousDelivery 3 жыл бұрын
Thanks for watching!
@BlueEyedSexyPants
@BlueEyedSexyPants 3 жыл бұрын
1. Completely Agree. Self-documenting code is always preferable, and comments are a last resort when you've failed to simplify the problem or when something is unintuitive like an equation. 2. Completely Disagree. Long functions are not hard to read. Lots of indirection and file hopping is hard to read. If you're looking for a bug, you still have to follow all the code through all those little method calls to find out what the code is doing, and if you have to jump 17 files away to get to the actual code, you have made your code much harder to read. I'd be tempted to fire someone who put a 20-line limit on their functions and enforced it with CI. It is terrible for the long term maintainability of the codebase, and it is very, very bad practice. 3. Mostly Agree. This is almost always really gross, but the only place I've seen this be useful is when operating on compound state machines where references to multiple states have to be passed to a function, and even then, grouping them into structs is usually worth the extra pointer chasing. 4. Complete Agree with caveats. If groups of lines are used more than once, they should be factored into functions, but instead of Extract Method, consider locally-scoped functions if they are only reused inside this scope. Going back to number 2, you should have good reason to extract a method that is only used once, and that reason should be better than it "feels" too long. Remember that inlining code is a great way to find bugs when there are a lot of methods in a path. 5. Completely Agree with the Example. Creating a connection is likely something that will be used in multiple cases in the code considering that they could have ci passed into scope. That's a bad usage of a large if block. If anyone inherits a project written by Continuous Delivery, the first thing you should do is start inlining all the useless methods to find all those needless bugs that his indirection soup is causing. It will clean up the code and improve the long-term maintainability. 600 lines of code is far easier to manage than 100 methods of 6 lines each.
@LPFan33
@LPFan33 3 жыл бұрын
You know very well that simply extracting methods wouldn't lead to 17 files of indirection. Maybe if you refactor a huge function into smaller classes with single responsibilities at different abstraction levels, but then you have smaller and simpler units that you covered with tests so in fact it will be pretty easy to isolate your hypothetical bug.
@BlueEyedSexyPants
@BlueEyedSexyPants 3 жыл бұрын
​@@LPFan33 That's the theory. In practice, 17 isn't all that much of an exaggeration. I have worked in multiple systems where I've had to jump 10 or 12 files away because of code that was factored out "just in case" or "because it's best practice" or "to make our tests work." Recently in such a codebase, I inlined about 400 lines of code across 5 files into one 90-line function and in the process, discovered and fixed 3 logic bugs that hadn't yet been found as well as the original one I'd been sent in for. All of these small functions were only called in this path. All had unit tests, well-defined names, and fewer than 30 lines each, yet they were still a mess of circular calls and organizational errors because what they really needed was to operate on one shared scope. The tests I wrote to cover my one method did all the same validations as the original tests for the "simpler units." Breaking my 90 lines into four 20s and a 10 would do nothing for its clarity or testability. The mess of that 600-line function from the video doesn't get solved by breaking unduplicated code into smaller methods. It just hides the mess behind pretty names and makes the code harder to fix. Arbitrary function lengths can compound the problem of sloppy code and really do little to solve it.
@dealloc
@dealloc 3 жыл бұрын
The DocBlock comment example is a bit dishonest. DocBlock-style comments are used for documentation, not comments. It's good practice to provide explanation of APIs for consumers. It's used to provide context and understanding what is to be expected from using it. Although they shouldn't explain implementation details-as that can get outdated very quick-it should explain generally what it does, and how the input and output is related (e.g. if it has any side-effects, etc.)
@OthmanAlikhan
@OthmanAlikhan 2 жыл бұрын
Thanks for the video =)
@aquarius5719
@aquarius5719 3 жыл бұрын
Having a long method that solves one problem. What is the alternative? To use global variables to avoid passing too many parameters. And then if you check for bugs you still need to walk through many methods to find the bug. That will be a big mess. I separate only if it is reusable and/or if it is duplicate. And sometimes duplicate may force to pass many parameters, and I hate that, but has to be done. It reduces the code size to 20% of its original size. Yeah. I truly dislike those branched IF. But sometimes they need to be there.
@IceQub3
@IceQub3 3 жыл бұрын
Hi, I love your video, you helped me and my team improve our velocity a lot, thank you. I found myself to partly disagree about long functions, I do agree that long functions the vast majority of time are code smell and are long with no reason (probably because of duplication and not following CRP) But there is no one length that I find functions to be "bad" from, and I will always prefer reading code vertically than horizontally. In some application, its just make sense to have a "flow" function, one that is just doing stuff sequencially in one after the other, in my experience those function never reach 200+ lines without code smell. But I finds the practice of extracting to one time (private) functions that do not hold any domain by themselves make the code even harder to read. In one function at least the order of read is similar to the order of execution. Some people suggests to implement some design patterns like fluent code but I find it not worth it to use an abstraction for one time use as I tend to build abstraction only when I fine that I need them ( probably if a code became a repeating patttern )
@caLLLendar
@caLLLendar 2 жыл бұрын
Suggestion: 1. Extract to 30 lines of code or less. 2. Name the functions verb_adjective_noun() so that it is easy to read. I like to only have one function per file, with the name the file the same as the function. Each directory is a separate namespace. In the directory, you can see the code "folded". 3. Make one function that calls the other functions in the correct sequence.
@MagnusAnand
@MagnusAnand 3 жыл бұрын
Great as usual
@porky1118
@porky1118 3 жыл бұрын
I also try to make my functions/methods as short as possible, but sometimes it might be better to write longer methods for redability. It's not a good thing if you always have to look up some method, which is just used in this one method and does not even make sense in a different context, and then just go back to the original method.
@LarryRix
@LarryRix 3 жыл бұрын
If you have method or function names that stop making sense in the context in which they are called then you might have a naming problem. Either the name does not tell the story of what the Client caller can expect from the function or the story it tells is too abstract or not concrete enough. This is where an understanding of the Client-Supplier relationship comes into play. The Supplier methods and functions need names that tell the story of what they require to run and what they ensure they will produce for the Client caller. If the name reveals that relationship well, then you are hitting the sweet spot of proper naming! Context is also important. Having a receipt.add_product vs inventory.add_product vs order.add_product vs quote.add_product-there are different stories. One might need an abstract parent version of "add_product", where inherited versions rename the method based on the context of the inheriting class.
@porky1118
@porky1118 2 жыл бұрын
@@LarryRix I didn't talk about function names not making sense in a different context, but the function itself being so specific, it would only be used in the one place anyway. I don't get, what the rest is about. I didn't even mention inheritance.
@999Burek666
@999Burek666 3 жыл бұрын
The best channel, for development - I recommend the book "Clean code" it is really nice for targeting the problems listed in this video. You can find the book online in pdf version.
@ContinuousDelivery
@ContinuousDelivery 3 жыл бұрын
Yes, its a good book, here is a link amzn.to/3aLXGad
@thestereoclub6735
@thestereoclub6735 Жыл бұрын
These have been very good ideas for a very long time. In the paleodev era your second was "never cross a perf"...
@CosasCotidianas
@CosasCotidianas Жыл бұрын
There's not a single video of Dave that I don't find interesting or educational. I'd love to meet him some day.
@cosmicdust2192
@cosmicdust2192 2 жыл бұрын
I had to work on a codebase which had all the mentioned problems. It was tier 1 service and codebase was in such a state that refactoring was impossible without significant development and testing effort. Continuous refactoring is so underrated in my opinion.
@lepidoptera9337
@lepidoptera9337 2 жыл бұрын
Refactoring is simply spinning your wheels. Every time you do, you are spending time on fixing mistakes that crept in at the architectural level on the code level. Oh, wait... there are no mistakes on the architectural level, right? You never had an architect to begin with. You simply began coding without any top-level structure in mind. That's why you keep refactoring.
@laci272
@laci272 3 жыл бұрын
This video is so good, I'm embedding it in our onboarding flow.
@ContinuousDelivery
@ContinuousDelivery 3 жыл бұрын
Thanks
@raycarlbrown-amory3509
@raycarlbrown-amory3509 Жыл бұрын
Fantastic
@spaghettihair
@spaghettihair 3 жыл бұрын
combining your first and second tip: if you find yourself separating your code into blocks with little comment headers, that's a perfect opportunity to turn those comments into function names.
@ContinuousDelivery
@ContinuousDelivery 3 жыл бұрын
Yes
@rumble1925
@rumble1925 3 жыл бұрын
Check out the video series object oriented programming is bad by Brian Will. He has a few good points on not breaking up code into tinier pieces unless necessary
@ericpmoss
@ericpmoss 3 жыл бұрын
+37 on reducing duplication, and shortening arg lists. As to the first 3 points, I see the seeds of truth behind these ideas, but I'm not sure I'd take them the same direction, exactly. Take function length. When is a function too long? Arbitrary limits like 20 lines simply push the problem into a different dimension, making many of them too divided up. I think what you're really trying to get at is when a *concept* won't fit in the normal area of vision -- so long that it goes off a page and can't be all seen at once, and/or so wide that one can't see an entire line in one glance. Next take comments. The real value of a comment is to explain anything surprising and anything that can't be grokked faster from the code itself. Repetition is not a virtue. If your args are already typed, you don't need to say any more. If an arg is a percentage, that part is clear; what isn't clear is what it is a percentage OF, and why we care. Also comment-worthy is who might call this function and why, if it's not already obvious. e.g. "def cosine (radians)" computes a cosine of a value entered in radians, not degrees. It's usable anywhere so it needs nothing else unless it is imprecise, e.g. a 256 value lookup that rounds to 3 places and ruins any results needing more than 10 bit precision. Then variable names. Shortest is sweetest until you have to spend time guessing its meaning and use. This ties into my function length comment because x, y, and z are exactly right if you are talking 3-D rectilinear coordinates, and adding verbosity only serves to make lines longer and harder to read. There is a balance, of course, but the optimum is usually closer to the short end. There are other points, but I'd say the biggest is to dispassionately re-craft your code as often as possible to chip away anything that's not aiming at the goal.
@LarryRix
@LarryRix 3 жыл бұрын
Please, define "too divided up" and give an example.
@monochromaticspider
@monochromaticspider 3 жыл бұрын
Great advice, but there's one thing missing. How to talk your boss into accepting the time usage of building half-decent code instead of quick and dirty solutions with endless klocs of repeating crap that becomes an incomprehensible mess about three days from when it was finalized? Particularly if your boss "use to" do "some programming", it really can be a PITA to get a reasonable time allotment to get the job done right. Sure, it will save problems "in the future", but who knows when that future will be? Who knows who is going to be the boss responsible at that time?
@LPFan33
@LPFan33 3 жыл бұрын
In a perfect world: Explain them how cost of change goes up if code is not maintained/clean. That productivy will go down and therefore their costs for new features goes up. In reality it will be easier to just increase your estimates on your tasks and use the extra time budget to do refactoring.
@T33K3SS3LCH3N
@T33K3SS3LCH3N 3 жыл бұрын
On the topic of comments, my experiences make me appreciate comments that: 1. Provide me any context that's not obvious yet - what was it orginally designed for, what features were left out (and which would be reasonable extensions that just weren't necessary yet at the time?), what seperates it from potentially similar looking functionalities that could appear elsewhere? 2. Explain the function of the code of low level stuff that's annoying to decypher - yes this is the style of code we're told to avoid, but it's often just unavoidable somewhere. It's fine as long as it's properly capsulated and explained. Ideally we should never have to go to these places, but sometimes we do and then it's nice to have some guidance. This is also exactly the place where comments can help during the original development. The absolute worst is this auto-generated crap that just repeats the literal level: "public bool AutoF {get; set;} //public bool property AutoF". Especially in software that is full of jargon that new coworkers will need to ask otherwise.
@TimSchraepen
@TimSchraepen 3 жыл бұрын
Bit disappointed the first improvement wasn’t “write less code”. ;)
@MiguelFelipeCalo
@MiguelFelipeCalo 2 жыл бұрын
It's pretty much the bi-product of this video.
@mikeo9863
@mikeo9863 2 жыл бұрын
I'm really pleased it was about pointless comments. universities are still teaching BAD practices
@brianbutton6346
@brianbutton6346 3 жыл бұрын
Impeccable!!
@wilwerrodriguez1787
@wilwerrodriguez1787 3 жыл бұрын
this video was really amazing
@ContinuousDelivery
@ContinuousDelivery 3 жыл бұрын
Thanks
@pascalmartin1891
@pascalmartin1891 3 жыл бұрын
I find the presentation excellent, but I believe that an arbitrary size check has many downsides. Make the solution as simple as possible, but not simpler than the problem requires. I see separation of concern as my #1 tool: divide to make each problem simpler. However an extensive split of code may cause the graph of methods (and classes) to become the implementation's complexity. The art is to find a balance between the two. Each method should leave the object in some consistent state, which may mandate a minimal size. I have seen code where methods were an incomplete action, co-dependent with other methods, for the sake of shortening each one. This is the quick and easy way to meet, or game, a (deceptively reassuring) mechanical size check. Otherwise, I try to limit myself to one screen page: code that you can see all at once is easier to maintain.
@TimLondonGuitarist
@TimLondonGuitarist 3 жыл бұрын
Interesting, I try to do most of the stuff you mention but I need to try harder. Re tdd: I got into programming mainly writing stuff for academic research, no time there for writing test code as the purpose of the sw changes every day. To this day I only do integrated testing but try to test everything in the codebase through a range of integrated tests.
@LPFan33
@LPFan33 3 жыл бұрын
But the whole reason for tests is precisely to protect yourself from breaking things when "the sw changes every day".
@TimLondonGuitarist
@TimLondonGuitarist 3 жыл бұрын
@@LPFan33 Not if you your code is well organised. When I make changes I know exactly what final ouput they can influence,. Side effects happen sometimes if the code change affects processes at the same level as those for the target for improvement. So I test related output at that level (integrated tests if you like). The number of outputs that could be affected by a change should be very small:
@Pedritox0953
@Pedritox0953 2 жыл бұрын
Very nice video
@JorgetePanete
@JorgetePanete 3 жыл бұрын
I have to admit that the first time I jeard some advices for code I did not u derstand the reasoning behind some of them until it was obvious while practicing. For exampke, the 22 parameter function, an advice would be to wrap them in an object, at first this sounded like extra code to me, but now generally the objects that hold those parameters are already there to be used
@Layarion
@Layarion 2 жыл бұрын
7:40 question about "Cyclomatic Complexity"; if I have an If condition that reads like if(Thing1 == null) return; is this alternative more readable? if(Thing1IsEmpty) return; Or am i overengineering at this point?
@codeman99-dev
@codeman99-dev 3 жыл бұрын
5:00 There is one excuse for long functions/methods that appeared in both in my academic and professional life. That is the core rendering loop. The thing that really determines every pixel. That's not to say that a sprite should be in the same location as the collision detection. Just that very few languages are expressive enough to write small rendering loops. There were red flags in both cases though. 1. It was really hard to balance where new code should live. 2. Often the loop became "god code", something that should not be modified, especially by the uninitiated. 3. It was very difficult to follow the mutable state through even just one iteration of the loop.
@m.h.6470
@m.h.6470 2 жыл бұрын
I agree with everything except the max 20 lines per function. I develop a web system in php and I try to follow the tips in this video, since I started developing more than 20 years ago as a teenager. But: In the system I currently develop, there are functions of hundreds of lines of code, that functionally belong together, without repeating patterns (if there were, I would have them extracted into functions by now). Splitting these functions up, would just cause dozens of parameters on every function, as the code is so interconnected. In general, these are functions, that create part of the output page of the web system, but also data analysis or data restructure algorithms can get very lengthy.
@Edouardkick
@Edouardkick 2 жыл бұрын
Well, if a method needs many parameters, make it a class. 20 lines of code for a method is still too long if you're talking about clean code. Saying that splitting the code into functions would cause too many parameters is nonsense. Just apply the "extract method" refactoring technique.
@m.h.6470
@m.h.6470 2 жыл бұрын
@@Edouardkick believe me, if you knew the code I am working with, you would agree with me, that what you are saying simply isn't applicable to the code. There is no way to make it 20 lines or fewer without ripping apart code that functionally belongs together. We are not talking about low level functions or algorithms. Those, I agree, can be quite short without issues. I am talking about code that is processing thousands, if not millions of lines of data into a readable format in a web browser. That includes charts, diagrams, tables and so on, all of which need at minimum 20-30 lines of configuration before they are even displayed. And yes, that does include putting the settings into classes, but that still requires lines of code!
@seriousjan5655
@seriousjan5655 3 жыл бұрын
Once I heard from my more experienced colleague simple rule which I use until today: function should easily fit one screen (lenght). I use it until today as an indicatior that I should modify function I am working on
@ContinuousDelivery
@ContinuousDelivery 3 жыл бұрын
Yes, that is a good guide, automating the check is even better, trust but verify😁 😎
@seriousjan5655
@seriousjan5655 3 жыл бұрын
​@@ContinuousDelivery That's for sure. I benefit from the colleague's rule for 10 years but I have never got idea to automate it ...
@ankursatle
@ankursatle 3 жыл бұрын
Everything as code! 😀
@Martinit0
@Martinit0 3 жыл бұрын
Boss, for this new project I will need that 32:9 portrait screen
@paulfontaine7819
@paulfontaine7819 3 жыл бұрын
I agree on 4 of the ways to improve code, but not on the long methods. I see much code with many small functions where I have to jump around from the code in one function to the other in attempts to try to understand what those functions do. It would be much faster if I had the code inline. I prefer to have one long function in that case. With blocks of code preceded by some comment adding info about what the purpose is, maybe in more words than a function name.
@wordsworth2114
@wordsworth2114 3 жыл бұрын
I prefer to look at it in terms of structure than lines of code. It does sometimes happen that you really do just have a simple, uniform sequence of many steps... no loops, no conditionals, etc, and in these very occasional cases, sure, I'd agree that leaving it all in one function would be most appropriate. But once you start to get multiple loops and / or multiple conditionals, then no, these need to be split into multiple functions. In most cases a section of code with its own conditional and loop is typically something that should be pulled out and identified as its own clearly defined function. Having multiple such sections of code aggregated into a single 'big' function runs the risk of the 'global' variable problem - i.e. what should be local variables, effectively become global, because everything is all in the same local scope. Variables you define for the first part of your long function will still be in scope for the next sections, which isn't good practice, etc. More generally, long functions that haven't been broken into smaller functions is usually a sign of an inexperienced programmer who hasn't yet fully grasped the need for, and challenge, of properly architecting software. If you have multiple loops and conditionals that you feel you need to have all grouped together in a single large function that you feel doesn't naturally break down into smaller natural functions (and most likely classes as well) of their own, then you probably haven't fully understood the problem that you're trying to solve.
@bahram.jahanshahi
@bahram.jahanshahi 3 жыл бұрын
It's so much fruitful, thank you so much then
@ContinuousDelivery
@ContinuousDelivery 3 жыл бұрын
Thank you
@davemasters
@davemasters 3 жыл бұрын
Do you fail the build at the commit stage or acceptance stage in the pipeline when running static analysis? I would think it's too slow for the commit stage?
@ContinuousDelivery
@ContinuousDelivery 3 жыл бұрын
I prefer to do it in the commit stage if I can, so finding tools that can give me that answer fast enough. In Java Checkstyle and Findbugs are a decent start, Lint and Lint-like things are also good. Also, turn up the warning level of your compiler to max, and fail commit if you get a warning.
@reinerjung1613
@reinerjung1613 2 жыл бұрын
This felt a little like reading our checkstyle and pmd configuration which we use in our Java projects. Unfortunately, we do not have similar comprehensive check tools for C and Fortran, but in case someone knows some tool, let me know. One other point: Usually, when I inherit code from others, I start reading it and in the process I usually refactor it. The only thing I am not doing extensively is TDD which is impossible when you inherit code from others, but also in my own work. However, I will improve in that area ;-)
@ContinuousDelivery
@ContinuousDelivery 2 жыл бұрын
Lint will take you most of the way toward "Checkstyle for C" en.wikipedia.org/wiki/Lint_(software)
@admiralspyro9722
@admiralspyro9722 3 жыл бұрын
This tips come naturally to Coders with bad OCD ...
@HansBezemer
@HansBezemer 3 жыл бұрын
Write Forth. With every repetition, every IF..ELSE clause there is a stack accident waiting to happen. That'll learn you to write well-factored code. ;-) Use tables with function pointers. That takes the heat out of complex logic - it works as a dispatcher. As a matter of fact, my own Forth compiler is built on three tables. Adding a command is as easy as adding an entry to a table. I used the same techniques when writing a Basic interpreter in Forth and recently I could take out the entire GC module and replace it with a new one as easily as changing an engine. Just bolt the thing to the chassis, hook it up to the transmission and you're done. Worked first time.
@Countryen
@Countryen 3 жыл бұрын
Thanks for the tips / information. I have mixed feelings about the topic. I want to share my point of view, maybe that helps someone thinking like me: I hardly find bad code that is well documented/commented. Either it's good and documented or bad and not documented (bad in terms of long functions, names like x,y,z and repeated stuff). Even the one you show isn't commented. Also, in most libraries/frameworks, all members are commented/documented (annotations) (like in C# the XML-comments). They really help when trying to use the API/system, and most languages ask/want you to do it like them - so are those excluded for your advice? I think comments/documenting should concentrate on API and everything that others can see and need to see, but not on implementation details (like lines of codes). Important is that the information is never ONLY in the comments, but repeating the info should not be bad. Since they are just comments, you can easily remove/ignore them later. For me personally, I like to comment, it's fun and it helps me to code and to read later (especially in scripting and "main functions"). I also disagree that just reading the prototype of "displayPercentage(...)" is more obvious than the comment saying "Displays the the specified percentage 'p' of the supplied value 'v'." The name of the function isn't clear enough. For me, if you want to do this, you have to go full way (displayPercentageOfSuppliedValueV(...)). But that hardly happens, at least in my experience. Lastly, the thing I don't get is why everyone who wants to code suddenly wants to develop instead? "Our job as programmers is to solve problems, not to write code" But when you begin coding or ask yourself why you started coding, I think many will tell you that they just like to write code - and not thinking about refactoring and naming things to become a system. I don't think that we can ignore why it's called "coding" in the first place and not "problem solving".
@mbartelsm
@mbartelsm 3 жыл бұрын
I have to disagree on the last point you make. I don't think I have ever met anyone who's said "I like coding" and meant that they just like pushing keys on a keyboard. Much the same way someone who says "I like woodworking" doesn't mean they like using a saw to chip random blocks of wood off a trunk. Coding, by necessity, implies some degree of thought about the quality of what you are typing.
@MrAbrazildo
@MrAbrazildo 3 жыл бұрын
2:00, I disagree, because nowadays every command does many things. For instance, if you are searching something in an array, you can put a comment not the kind of "finding something", but for why are you searching that - not technically, but semantically. 2:30, here, I would write a comment about what is 'r', and why it's calculated like that. And I would do that at the right of the line, to avoid growing it downward. 3:45, I think it's not always possible: sometimes it's too intricate, and you will want to break it in parts, even harder to explain. 4:25, a majority of my f()s can be seen entirely in 1 screen. However (6:03), there are some of them that take 3 or more. And their content works as something private, that should not make sense to be exposed to the rest of the project, in a form of other f()s. Of course I'm not talking about reusable things (7:07), but about only 1 goal (7:55) that requires many steps, many initializations, many private and temporary data.
@shavais33
@shavais33 3 жыл бұрын
I'm using C++ for my project for a bunch of reasons that I won't bore you with. I'd like to write short functions, and I'd like to refactor into smaller functions, but it's just so bugsome to have to write a declaration in a header file for every single little function. And I hate having headers that are chalk full of all these little tiny functions. I just want the header to show the top level functions. All the little private functions that the top level functions call should not be in the header file. They're just clutter at the header level. But C++ won't let me program that way. I have to create header declarations for all those little private functions.
@StreetsOfBoston
@StreetsOfBoston Жыл бұрын
Not sure if a similar comment was already made to this video about code-quality, but here goes: When writing code, always keep this in mind: Code is written to be read by *humans*! Not by computers! Compilers throw away the code you've written and produce binary garble to be consumed by computers. If code were just for computers, we would still write all code in binary or punch cards :)
@porky1118
@porky1118 3 жыл бұрын
I only comment: * functions/types I defined, if the name is not obvious (or if I use them to generate documentation, also the obvious ones) * difficult segments, mostly math, which I often forget myself * things that seem like some mistake, but actually have to be this way ("don't remove this assignment. It does not just redefine an existing variable, but accessing the original variable implicitly invokes a non-performant calculation")
@razerx100
@razerx100 2 жыл бұрын
I follow most of the things talked about in here except long code in a single function. If I don't have duplicate code, I don't make a new function. But still I follow the rule that a function should do a single thing. Sometime that single thing requires lots of stuffs. Like suppose I have to bind 10-15 different class binds to render a single thing. I can make a huge complex system to make the binding process shorter. But that breaks the keep it simple stupid, rule. Also sometimes it impacts performance. I would rather make a huge messy pointer arithmetic, template meta programming filled code, if that is more efficient than short clean code. Also sometimes to make some code shorter you need to write a function with 10+ arguments. Like supposing populating a struct with 10 different members. I would rather do that manually.
@Iskelderon
@Iskelderon Жыл бұрын
Extra function calls used to slow down code when taken to an extreme, but we're no longer in the early 1980s.
@ddanielsandberg
@ddanielsandberg 3 жыл бұрын
6:03 Refatoring. Yes, sir! Now, where did I put my potato chips again? 😁
@ContinuousDelivery
@ContinuousDelivery 3 жыл бұрын
😎
@sylvereleipertz955
@sylvereleipertz955 3 жыл бұрын
Is having like 6 to 8 parameters in a constructor of an "entity" (class representing a database table) is bad ? Considering that these fields have "not null" constraint. That is the only case where i think it's OK to do so.
@LarryRix
@LarryRix 3 жыл бұрын
Sometimes, what you are passing to your method or function as parameters are really properties of a class you have not yet defined. Long parameter (or argument) lists might be cleaned up by creating classes with those parameters as properties. This puts those properties into a more reasonable context where you can control the state of the object using rules and prove those rules by TDD + BDD. The other solution (of course) is based on the "code smell" that the function or method has a poor "separation of concerns". What is really needed are separate functions or methods, each with their own goal or purpose, and then just the arguments (or parameters) needed to get that job done. The calling code can then decide which methods or functions to call based on its needs as a Client of the others. You might find that the answer to large parameter lists is also a combination of both of the points above-that is-you are missing some class or classes, where the parameters can be properties of them-AND-you have poor separation of concerns as well. One thing that usually happens is that the receiving method or function is far too long (as Dave points out in this video). Therefore, a long method or function ought to be a clear sign that a refactor needs to be done, where new classes and smaller methods and functions will be the result, which will (in turn) reduce the number of method or function arguments being passed around-or at least carve them up and send them to their appropriate handlers!
@sylvereleipertz955
@sylvereleipertz955 3 жыл бұрын
@@LarryRix Thank you for your time and answer.
@LarryRix
@LarryRix 3 жыл бұрын
@@sylvereleipertz955 you are welcome! :-) Dave's video is quite compelling and full of great viewpoints.
@disgruntledtoons
@disgruntledtoons Жыл бұрын
1. Your code will never be better than the data model on which it is based. 2. Well-written code tells the reader what the code does, but cannot tell the reader what the code is supposed to be doing. Comments are required to supply this information. 3. Let each function perform one task. 4. Let each task be performed by one function.
@nickbarton3191
@nickbarton3191 Жыл бұрын
If OOP, before you refactor into small functions look to see if you can refactor out a new class. Could be that you're trying to do too much in one unit (separation of concerns). A few times now that I've unrefactored functions so that I could extract a new class. That maintaining a connection problem seems a prime candidate. 600 lines in a class seems too large nevermind in a method. BTW, you refactored the "c" out of the word.
@PaulSebastianM
@PaulSebastianM 3 ай бұрын
Refatoring! 😂 Thank you Dave, for that small bit of amusement.
@notinlist
@notinlist 3 жыл бұрын
About refactoring: I do not think about "refactoring" as a separately identifiable knowledge to be learned. You learn what good code is. You learn what bad code is. You learn what isomorphic transformation is. Now you now everything. If you find a bad code, you turn it into a good one. The refactoring step in TTD is not different in any way.
@ContinuousDelivery
@ContinuousDelivery 3 жыл бұрын
Mostly I agree, refactoring isn't, or shouldn't be, a separate thing. But I meet a lot of programmers that don't think about it and are scared to change code. Sure, that usually means that they don't have enough tests, but also there are lots of changes that I comfortable making, in confidence that I won't break anything making them. So learning some of the small steps, the techniques, of refactoring from something like Martin Fowler's book (amzn.to/30ntgaK) is a good idea.
@danm6189
@danm6189 3 жыл бұрын
@notinlist I respectfully disagree that refactoring is not a separate thing, there is inherent complexity and craft in choices made for stepwise refactoring to minimize effort and risk, especially when tackling code that requires more work or crosses current test boundaries... Knowing what you dislike currently and the end state you'd like to get to does not come close to covering this optimally, imho. In my experience as a pair, many people who are not yet well practised in refactoring struggle at times, to the extent of failing slowly and requiring reverts on early attempts.
@HoD999x
@HoD999x 3 жыл бұрын
duplicated code: i follow the rule that every idea must be "symbolically accessible". meaning non-trivial things have to be a function or a class.
@jimhumelsine9187
@jimhumelsine9187 3 жыл бұрын
I regret that I have but one thumbs up to give to this video.
@ContinuousDelivery
@ContinuousDelivery 3 жыл бұрын
Thanks Jim 😁
@ArunprasadRajkumar
@ArunprasadRajkumar 3 жыл бұрын
I believe function helps to express the intent for the block of statements than acting as reusable component. Reusability is a byproduct of a function, not necessarily a goal.
@ContinuousDelivery
@ContinuousDelivery 3 жыл бұрын
Yes, that is a good description. I agree with you that using functions helps us to express the meaning of our code much more clearly.
@BBdaCosta
@BBdaCosta 3 жыл бұрын
Well said, very good tips
@ContinuousDelivery
@ContinuousDelivery 3 жыл бұрын
Thanks
@vaibhavarora7782
@vaibhavarora7782 3 жыл бұрын
I really liked CI giving error on code smells, damn I never thought of that, was always looking for better code review tools instead 😁
@szokone
@szokone 3 жыл бұрын
There are tools that can be applied on local build and will prevent code smells even leaving your workstation. We should catch those ASAP
@vaibhavarora7782
@vaibhavarora7782 3 жыл бұрын
tell me some I am only aware of basic lining of ecmascript, typescript. Need more control, like functions line of code limit. any place to refer?
@vaibhavarora7782
@vaibhavarora7782 3 жыл бұрын
got it - eslint.org/docs/rules/max-lines-per-function
@ContinuousDelivery
@ContinuousDelivery 3 жыл бұрын
I think that adding it to CI is a good step.
@szokone
@szokone 3 жыл бұрын
@@vaibhavarora7782 Yes Lint can be used for JS/TS I guess. For backend there are solutions like Detekt for Kotlin. Probably for many languages, there is something helpful.
@VidkunQL
@VidkunQL 3 жыл бұрын
I find those images of code very difficult to read, they're so small. I'll take your word for what they say, but you could have illustrated the same ideas with cartoon blocks rather that actual eye-straining text. Or you could sacrifice the constant presence of a human figure taking up half the frame.
@01001000010101000100
@01001000010101000100 3 жыл бұрын
My comments are documentation. I have a memory issue (like damaged RAM chips under my skull), so unless I document my code it's not very useful to me. Documented code provides code completions and popup descriptions that allows me to use the module in real projects without depending on my broken memory. The documentation of each module contains what is it for and how to use it. I know it can be reverse engineered by just analyzing the code, it's self-explaining, however it takes too much time. Code completions and popups in VS are way faster. Sometimes during writing the documentation I realize that something is wrong about in my interface or whole design and I change the code to be more usable from the interface side.
@oldcountryman2795
@oldcountryman2795 2 жыл бұрын
Yep. And no matter how easy it is to follow the code, the code doesn't tell you WHY you did it that way. I have code with comments like this: _//I know this looks silly and redundant but it's necessary to avoid a memory leak in the constructor of class z in the xyz library_
@01001000010101000100
@01001000010101000100 2 жыл бұрын
@@oldcountryman2795 I agree. That's the exception that comments other than documentation are useful. I sometimes add something like FIXME or TODO or HACK tags to revisit the code later and fix the thing so it wouldn't need comments. Usually the cause for weird things in the code is something else (like a library, OS behavior) buggy, when it get fixed you can remove the workaround if you have it documented.
@DiogoMudo
@DiogoMudo 3 жыл бұрын
Magic numbers instead of enumeration/macros. If(variable ==1 || otherVariable == 5)
@livefromhollywood194
@livefromhollywood194 3 жыл бұрын
11:30 "Adopt the discipline of allowing yourself one conditional per function or method." I'm assuming this means 1 if statement. What?! I don't think any of my code could meet this requirement. There are too many places where I need very short if statements looking for error conditions to fix or throw on.
@mbartelsm
@mbartelsm 3 жыл бұрын
I think that constraint might be a bit too extreme. However, one way to make it work would be to distribute error checking to were it's really needed. If you have
@lawrencemanning
@lawrencemanning 2 жыл бұрын
I took that as: limit yourself to one level deep, not necessarily one condition per function. I dont agree with either notion, but the bulk of this video seemed to be reasonable advice, especially on comments!
@Favourites669
@Favourites669 3 жыл бұрын
I thought I had seen some real turds before but a function with 623 lines of code? 22 arguments? 300+lines of code inside an if? Holy shit. Great video and channel!
@emmaccode
@emmaccode 3 жыл бұрын
POV: You are new to programming and somehow got an internship, but the Senior developer is onto you.
@guntherthomsen3864
@guntherthomsen3864 3 жыл бұрын
The senior developer is not onto you. He might have issues with your code, which is not unexpected, if this is your first position as a professional software developer. Even if you're very talented, learned a lot in school and started to program early in life and have hence some practice, there are some experiences you are unlikely to have made if you haven't maintained code over an extended period in a team. Try to engage that senior developer, ask him what exactly is wrong and why and how to improve the code. Try to learn the most you can, that's what the internship is about.
@emmaccode
@emmaccode 3 жыл бұрын
@@guntherthomsen3864 I thought it was a good meme
@yutubl
@yutubl 3 жыл бұрын
a) Code comments in "repeation" style may bore out the reader & distract from important & problematic parts, thus better keep the Dont Repeat Yourself-Principle. b) Code comments in "teaching style" may help yourself & colleages in unfrequent changed/reviewed code base e.g. already finished/delievered customer projects or stable systems core. c) Code comments can be reduced if they reference to external description (documents/database entries): requirements, specifications, design, implementation (doxygen), issue tracking, FAQ, readme, installation, testing. That way the context can be given w/o much duplicate code comment copies, a good searchable intranet/content management system helps finding external information. d) Code comments may be deleted if they refer to changes -> shifted them to well disciplined VCS checkin/commit/submit commenting.
@Sergio_Loureiro
@Sergio_Loureiro 2 жыл бұрын
Do you apply the limit of n. of parameters also to constructors?
@ContinuousDelivery
@ContinuousDelivery 2 жыл бұрын
Yes, I try to.
@lepidoptera9337
@lepidoptera9337 2 жыл бұрын
If you need very complex initialization then a factory pattern is for you. If nothing can be automated about the initialization of 200 parameters, then you know that you are already in hell and you might as well ask Satan for a new assignment in the glowing ember pit. :-)
@Sergio_Loureiro
@Sergio_Loureiro 2 жыл бұрын
200 parameters?! That's crazy. The max. I've ever seen a function have as parameters would be 15~20. And even this is troublesome.
@lepidoptera9337
@lepidoptera9337 2 жыл бұрын
@@Sergio_Loureiro That was my point. There is a level of complexity, even in initialization, that requires automation. Not sure I have ever seen 200 in my life, either, but I think I have seen something on the order of 50 or 60 in a plot function once. Somebody tried to cram everything and a kitchen sink into that poor function call. It is not all that hard to get to impractical numbers of parameters. Look at GUI elements like buttons, for instance. Location, size, colors for background, borders, highlights, style, fonts etc. It adds up quickly and personally I am becoming frustrated if I have to deal with even a dozen parameters.
@Layarion
@Layarion 2 жыл бұрын
2:32 oh thanks, now I crave orange juice.
@augustincalin
@augustincalin 3 жыл бұрын
I always say that rule #0 of a clean code development is: "make the life of the fellow developer easier". All the others are derived from this. Rule #0.5 is "be consistent". If, at some moment somebody else (not you, of course!) did a sh*t and you don't have the time to fix it, then either use his sh*t or create your own similar sh*t AND create a new working item for future: "fix the sh*t". When it comes to comments is easier: if, in the middle of a method you feel the need to put a comment to explain what are you trying to do, don't put the comment! Extract a method instead.
@slipoch6635
@slipoch6635 2 жыл бұрын
pfff, 623 line function, I had to debug a vb (I know, I know) library, it had 3 functions each of which had 40 params and over 1000 lines; It was essentially the same code in each with a few minor differences too. After refactoring I got it down to 500 lines total in the library in multiple small functions. ;)
@ContinuousDelivery
@ContinuousDelivery 2 жыл бұрын
I love the smell of deleted code in the morning 🤣
@Whyoakdbi
@Whyoakdbi 2 жыл бұрын
This guy remind me of the with from the Curious Droid channel, but for programming :D
@tomng92
@tomng92 3 жыл бұрын
Comments are useful, simply as visual markers. Also, it's a pipe dream to say 'write self-documenting code. Code can never replace comments.
@ContinuousDelivery
@ContinuousDelivery 3 жыл бұрын
Sorry, but I think that you need to look at some better code.
@FreedomMoped
@FreedomMoped 3 жыл бұрын
I like comments (in moderation) , but now include a readme.txt file with some simple process, structure or other documentation which is very useful for getting to the right place quickly. Self-documenting code is a nice idea but almost always needs additional context/ clarification/ knowledge, and you don’t necessarily get the option to “look at some better code”, you get what you get, and demo examples are usually ridiculously simplified.
@anubhav3944
@anubhav3944 3 жыл бұрын
At last, you can also some good and better code for better understanding of your video
@jukkanikki3395
@jukkanikki3395 2 жыл бұрын
One can't live like this in some cultures and codebases. If you are in such place: time to go forward - don't learn to tolerate code that you can't change and hate to work with.
@minastaros
@minastaros 3 жыл бұрын
I have seen a function with 11,000 lines. Several levels of if and switch... But, honestly, also me, 20 years ago: "why should I want to write header files, when I can put everything in one single c-file?" And: "every line of code needs to be commented." How things (and comprehension) have changed by 180° in the meantime...
@CrapE_DM
@CrapE_DM 3 жыл бұрын
Was expecting a fake out with the second commenting example where he made you look at the file header comment.
@ContinuousDelivery
@ContinuousDelivery 3 жыл бұрын
😉
@NotMarkKnopfler
@NotMarkKnopfler 3 жыл бұрын
If you want good code, give your engineers time to _think_. Do _not_ expect them to sit there and write pages of code. It will almost certainly be sub-optimal and should be thrown away. Often the first draft is nothing more than exploring the problem domain and determining the correct approach. Let them sit and think and experiment. It looks like unproductive time from a PHB viewpoint, but it is very productive in the long run.
@ContinuousDelivery
@ContinuousDelivery 3 жыл бұрын
💯 I say the same thing in this video: kzbin.info/www/bejne/a5iWlX5oecyKY80
@nem0men
@nem0men 3 жыл бұрын
You misspelled refactoring at 6:15
@donfuchs4652
@donfuchs4652 2 жыл бұрын
I had a massive laugh about refatoring
@MiningForPies
@MiningForPies 3 жыл бұрын
TDD has never worked anywhere I’ve ever seen it implemented 😞
@MrXperx
@MrXperx 3 жыл бұрын
I have a similar opinion but writing unit test cases have saved my bacon time and over.
@MiningForPies
@MiningForPies 3 жыл бұрын
@@MrXperx I like unit tests and I like integration tests. I’ve just never seen TDD work in the real world.
@CynicalOldDwarf
@CynicalOldDwarf 3 жыл бұрын
@@MiningForPies What are the issues that you run into?
@MiningForPies
@MiningForPies 3 жыл бұрын
@@CynicalOldDwarf it’s not flexible enough. If you don’t do some design work upfront you end up throwing away tests, constantly changing them and in larger terms it becomes a nightmare to manage. Worked with guys who would kick off if you started with a class rather than a method (because no test had been written that meant a class was needed) some of the most dogmatic and terrible developers I’ve ever worked with,
@StephenOwen
@StephenOwen 2 жыл бұрын
From the book, Clean Code: "comments are only needed when we are unable to express ourselves through code"
@johanrg70
@johanrg70 2 жыл бұрын
And now we have badly written code with no comments at all, thanks Bob!
@MrAbrazildo
@MrAbrazildo 3 жыл бұрын
Having too many f()s or classes is for me also a bad thing. The only reason for that is if they do actual different things or are reusable. Trying to create words for expressing ideas through f()s can lead to messy scenario, requiring too many travels throughout the project, losing time and (silently) energy too. 9:00, functional programming, which uses to not memorize configurations, but happens to encounter some highly configurable f(), uses to incur on that. 9:24, unforgivable!
@MrXperx
@MrXperx 3 жыл бұрын
Wow wow wow wow wow.
Are These Software Myths TRUE or FALSE?
16:54
Continuous Delivery
Рет қаралды 39 М.
Is This Why You’re Bad At Programming?
20:09
Continuous Delivery
Рет қаралды 84 М.
小路飞姐姐居然让路飞小路飞都消失了#海贼王  #路飞
00:47
路飞与唐舞桐
Рет қаралды 95 МЛН
Be kind🤝
00:22
ISSEI / いっせい
Рет қаралды 21 МЛН
狼来了的故事你们听过吗?#天使 #小丑 #超人不会飞
00:42
超人不会飞
Рет қаралды 60 МЛН
When Test Driven Development Goes Wrong
21:11
Continuous Delivery
Рет қаралды 72 М.
You Must Be CRAZY To Do Pair Programming
24:15
Continuous Delivery
Рет қаралды 66 М.
5 Common Mistakes In User Stories
17:28
Continuous Delivery
Рет қаралды 88 М.
What All New Software Developers Need To Know
27:46
Continuous Delivery
Рет қаралды 132 М.
Avoid These Common Mistakes Junior Developers Make!
17:54
Continuous Delivery
Рет қаралды 156 М.
Agile Uncertified | Philosophy Over Rituals
15:56
Continuous Delivery
Рет қаралды 129 М.
How To Be A GREAT Programmer
17:41
Continuous Delivery
Рет қаралды 74 М.
How To Estimate Software Development Time
16:47
Continuous Delivery
Рет қаралды 164 М.
The REAL Reason Cyberpunk 2077's Software FAILED!
15:50
Continuous Delivery
Рет қаралды 588 М.
A Guide To Managing Technical Teams
17:49
Continuous Delivery
Рет қаралды 108 М.
как спасти усилитель?
0:35
KS Customs
Рет қаралды 517 М.