(The context here being: working with problematic legacy code and getting to the point where you have new code (paths) that do(es) the same thing but without the issues, so that the old code, and its issues, can just be discarded)
Also, deleting code you wrote earlier in the project because you've made a more general applicable implementation, hence the old code isn't used any longer.
I see some kind of VCS as a baseline project requirement, and in that case commenting out code is a very big anti-pattern.
And even without it, should an obsolete version of a codepath forever remain in your codebase, even long after it's become sufficiently inconsistent as to be irrelevant?
yes. I've been deleting a lot of unused code recently and it feels so good. except for that moment when you realize that the code you deleted is used in another module but this is not documented anywhere
I'm a big fan of both having a calm + non-interrupted refactoring session or discussing with colleagues about alternatives of how to implement something or just naming conventions to plan to use.
My name is Lewis Menelaws. I am a developer and entrepreneur located in Sarnia, Ontario focusing on creating great things for the web. Currently I am Lead Developer and Co-Founder of TMRRWinc.
The pleasure of finally being able to get it or to make something work. Having all those tabs open to just have them closed is some of the best feelings ever... Especially when it looks like this:
+1 for the last one. I've been working as a junior/front end dev on a freelance project with a C#/asp.net developer who has 12 years of experience. Reading his code and studying it until I understood how all the functions worked was a complete game changer!!
I've been a professional C, Perl, PHP and Python developer.
I'm an ex-sysadmin from the late 20th century.
These days I do more Javascript and CSS and whatnot, and promote UX and accessibility.
There are comments and comments. The comments explaining what the code does are usually a symptom that the code is convoluted and difficult to understand even for the person who is writing it.
On the other hand, there are comments like:
# This solves a bug in the library Fubar that prevented the Baz
# from being executed. See: https://github.com/fu_bar/baz/issues/454
Or:
# Temporalirly removed as per request in Issue #1243
Currently developing futuristic smart-device, IoT connected, highway construction site safety system in EU.
Used to work on infrastructure, application architecture and cloud engineering.
A lot of truth to this, but an exception can and should be made when something merits an explanation of why it is the way it is. Comments should be few and far between in well-written code, but still used when there's an actual need. For me that's usually just when I had to dig to find a way to make something work when a more intuitive solution wouldn't work in that specific case.
Indeed, some business concerns are just impossible to explain by code itself and as you've said, logic that by some black magic doesn't work.
The key is to know if comments are up-to-date with the code as refactors come and go and not everyone updates the comments.
I've been a professional C, Perl, PHP and Python developer.
I'm an ex-sysadmin from the late 20th century.
These days I do more Javascript and CSS and whatnot, and promote UX and accessibility.
While I agree with not using comments where the code can demonstrate its own purpose and mechanism, I don't like absolutes like "don't use comments". An RFC number or something can be very helpful, or a link to where you found the code you just copy-pasted.
I read Stephen King's book On Writing, he described the development of the story as carving something out of stone. You just start hammering the hell out of the block then it just starts resembling an image (something like that).
My reaction was "Haha, that's what I do when I write code"
Only when I read that book I realised that that might be the reason why I don't look forward to finishing projects - hammering away is fun.
Refactoring, getting rid of code, Visual Studio Code that sometimes does magical stuff, having tests passing and how easier things are now that I'm using a 24" inch monitor again instead of the Macbook's 13" :D
I absolutely love getting to build things from the ground up. Some of my favorite things I've done at my job were things I had to start from scratch. I enjoy most coding tasks, even fixing bugs, but my favorite by far is seeing a feature or product I helped make with no code to start out with.
Top comments (89)
Deleting code.
(The context here being: working with problematic legacy code and getting to the point where you have new code (paths) that do(es) the same thing but without the issues, so that the old code, and its issues, can just be discarded)
Yes!
Agreed!
Also, deleting code you wrote earlier in the project because you've made a more general applicable implementation, hence the old code isn't used any longer.
Yeah I saw that as included in the previous, since I don't see 'legacy code' as inherently being 'code written by somebody else' :-).
When we come up with this kind of comments:
I would suggest just comment out codes rather than delete (or have versioning in place).
I see some kind of VCS as a baseline project requirement, and in that case commenting out code is a very big anti-pattern.
And even without it, should an obsolete version of a codepath forever remain in your codebase, even long after it's become sufficiently inconsistent as to be irrelevant?
Or deleting old code that just exists, is no longer used!
yes. I've been deleting a lot of unused code recently and it feels so good. except for that moment when you realize that the code you deleted is used in another module but this is not documented anywhere
ikr
oh so true...
Yep... This too XD
If I have momentum on something and I'm locked in with my ideal monitor setup I feel like Batman at his dashboard. So much power at my fingertips.
When things aren't going so smoothly:
I'm a big fan of both having a calm + non-interrupted refactoring session or discussing with colleagues about alternatives of how to implement something or just naming conventions to plan to use.
The pleasure of finally being able to get it or to make something work. Having all those tabs open to just have them closed is some of the best feelings ever... Especially when it looks like this:
True story. Pleasure of clicking on "close tabs to the right" π
The good-old picket fence!
+1 for the last one. I've been working as a junior/front end dev on a freelance project with a C#/asp.net developer who has 12 years of experience. Reading his code and studying it until I understood how all the functions worked was a complete game changer!!
It doesn't happen often because there's usually a catch when it does, but when code works the first time, I get really giddy :D
I usually feel extra nervous...
Yes, if all the tests pass immediately, that's a moment to step back and think reaaaaalllll hard.
True. The feeling when you write code and the computer does what you intended.
I really like writing code comments, although I don't do it too often. I'm still learning how to make them meaningful first.
I was taught that you should not use comments. To avoid comments your code should be written in a way that can be read like a comment.
I wrote a little article showing the difference of code that needs comments and other that it doesn't.
There are comments and comments. The comments explaining what the code does are usually a symptom that the code is convoluted and difficult to understand even for the person who is writing it.
On the other hand, there are comments like:
Or:
Those make perfect sense to me.
Works very well in commit messages when you have Bitbucket integrated with Jira. Hell of a difference!
A lot of truth to this, but an exception can and should be made when something merits an explanation of why it is the way it is. Comments should be few and far between in well-written code, but still used when there's an actual need. For me that's usually just when I had to dig to find a way to make something work when a more intuitive solution wouldn't work in that specific case.
Indeed, some business concerns are just impossible to explain by code itself and as you've said, logic that by some black magic doesn't work.
The key is to know if comments are up-to-date with the code as refactors come and go and not everyone updates the comments.
With this I fully agree, that's something I've been trying to improve on myself.
While I agree with not using comments where the code can demonstrate its own purpose and mechanism, I don't like absolutes like "don't use comments". An RFC number or something can be very helpful, or a link to where you found the code you just copy-pasted.
So am i.While i agree with Jose Tomas that try to make your code self-interpretation as possible.I'm trying!
I read Stephen King's book On Writing, he described the development of the story as carving something out of stone. You just start hammering the hell out of the block then it just starts resembling an image (something like that).
My reaction was "Haha, that's what I do when I write code"
Only when I read that book I realised that that might be the reason why I don't look forward to finishing projects - hammering away is fun.
I love working on the heavy parts.
Refactoring, getting rid of code, Visual Studio Code that sometimes does magical stuff, having tests passing and how easier things are now that I'm using a 24" inch monitor again instead of the Macbook's 13" :D
I absolutely love getting to build things from the ground up. Some of my favorite things I've done at my job were things I had to start from scratch. I enjoy most coding tasks, even fixing bugs, but my favorite by far is seeing a feature or product I helped make with no code to start out with.