r/learnprogramming • u/BullCityPicker • Mar 22 '22
Don't be that guy.
I just took over a project for a guy who left. Don't be this guy:
ZERO comments in your codebase.
One and two character variable names with no discernable pattern.
Comment characters used to comment out big chunks of code for no discernable reason.
No error checking.
Reliance on data files that you forgot to include or explain, going in to meaningless data frame names.
Making outrageous claims about how much your code improves things with zero baseline performance.
People like this think you're an idiot because you can't make their code work, and get to be all smug. We will track you down and find you. You will need references someday....oh my.
369
u/In0chi Mar 22 '22
Don’t be the kind of company that lets this guy make even a single commit like that to the main branch.
129
u/v0gue_ Mar 22 '22
Yeah I agree, this one is on the company/owner of the codebase.
78
Mar 22 '22
I suspect 1 man show and no version control.
1
u/BullCityPicker Mar 23 '22
Yep. I'm in a data science group. If we were a real software development group, it would be less likely that crap like this goes on.
→ More replies (1)40
u/Rote515 Mar 22 '22
My entire company’s codebase is like this, it’s absolutely astonishing, 3k employees, no comments 1 letter variables everywhere, and lol we only have a main branch
19
u/vladamir_the_impaler Mar 22 '22
we only have a main branch
That was the drink-spit-out moment for me when I read your comment.
→ More replies (2)5
4
16
→ More replies (1)9
1.2k
u/HashDefTrueFalse Mar 22 '22
This was his job security. Guess he didn't need it anymore... :)
If you can actually read any code I write, you might be able to replace me. Unacceptable.
110
u/neekyboi Mar 22 '22
The day I documented the process and spent KTing the codebase, I got terminated for no reason whatsoever and was replaced by the guy I KTed. So lesson learnt.
50
u/Attackontitanplz Mar 22 '22
KTing? Knowledge transfer?
4
u/HealyUnit Mar 22 '22
I assume it refers to the K/T Extinction event. As in, your code is so bad that it just needs to go extinct.
3
u/BullCityPicker Mar 24 '22
I wonder if there was any KT going on during the KT event? "Hey little furry thing with breasts, let me tell you everything we've learned during our time on Earth....oh, never mind, I have a brain the size of a walnut. Sure is cold today."
7
→ More replies (3)4
477
Mar 22 '22
I met a guy like this at AT&T. Only person who knew this absolutely ancient system. Never did any documentation. Refused to cooperate with anyone asking for details. Reason? Job security. He was old. He knew the second someone figured out how to work the system or replace it he was gone.
194
u/HashDefTrueFalse Mar 22 '22
So you're saying it works... :D
I've met similar. An absolute bastard when they leave too! Like maybe you could have pulled a Junior onto the product and at least attempted to leave some documentation or knowledge behind once you knew you'd be leaving, instead of spending your 3 month notice period doing feck all mate! Cheers.
→ More replies (13)46
u/BassDaddy420 Mar 23 '22
This is what my uncle does with some heavy machinery in steel mills. Literally sits and deciphers coding languages from the 80’s. Doesn’t have a timeline, doesn’t give a timeline to his superiors, pretty clutch
→ More replies (1)10
88
u/ipreferanothername Mar 22 '22
i worked with some jackass who only used VB script and ran it through excel -- said he was a 20 year dev. showed him VSCode and tried to get him into powershell; no go. tried to get him to have the boss buy him a VS license because....i mean, to be fair, he did automate a lot of work. nah, excel was fine.
and he wouldnt share ANY of his work -- i wrote powershell and javascript left and right, documented it, stored it shared with the team, and even walked them through the complex scripts.
this guy? no. hid all of his work, and ran the VB he did through the excel debugger. he still works that way. i was doing all sorts of work he couldnt figure out how to do and could not get him to budge on the ridiculous way he did anything.
37
u/HashDefTrueFalse Mar 22 '22
Awful teamwork on their part. Far too much liberty given by techical management too. I felt sorry for you just reading that.
Dometimes they're just too set in their ways. You can't change them. Move onto bigger and better things. Guessing you did.
17
u/vladamir_the_impaler Mar 22 '22
Move onto bigger and better things. Guessing you did.
THIS, nail on the head.
17
u/exploding_cat_wizard Mar 23 '22
You know, given your username, that phrasing makes me a bit nervous...
→ More replies (1)97
u/YellowSlinkySpice Mar 22 '22
This happened at my work. Although the guy couldn't handle the stress of his programs not working so he quit.
Not sure what he is up to.
He was our first Computer Science grad, the worst programmer we hired. (We have since hired other computer science grads and they are fine)
38
15
Mar 22 '22
Stuff like this makes me wonder, what is the interview process like if they’re getting through?
→ More replies (1)15
Mar 22 '22
Well I wasn’t part of the process the last time we had one. Apparently they talked a good talk.
→ More replies (2)9
u/wjrasmussen Mar 22 '22
So what was the whole point of bringing up Computer Science grad?
→ More replies (6)41
u/duh374 Mar 22 '22
Speaking as a comp. sci grad, there is a huge variance among graduates even from the same program with the same GPA. Simply having the degree with a certain GPA isn’t a guarantee of ability, which is i think the point of the guy you replied to.
I’ve personally interviewed CS/CE grads that can’t code their way out of a paper bag. I’ve also met programmers with only a GED that can explain Operating System fundamentals in detail. This is one field where the degree might get you the interview, but will almost never land the job.
29
u/gregzillaman Mar 23 '22
I've noticed the deeper you go into a comp sci degree the closer you get to theoretical math.
Where as, what most companies need is a tradesman whose trade is computer software.
→ More replies (7)37
u/unmannedidiot1 Mar 22 '22
If the system is so fucked up you risk being replaced so easily I wouldn't blame the guy acting like this but the system itself.
58
u/HashDefTrueFalse Mar 22 '22
Not sure whether I need to say this or not, but my post was a joke, of course.
Honestly though anybody can be replaced at any time. It's rarely what you know that keeps you in a role, it's often who you know and how well. If higher ups have the appetite or desire to replace you, none of this job security through obscurity shite matters. Management are famous for shooting themselves in the foot when hiring/firing and expecting everyone else to figure out the way forward, after all. I've never seen the guy nobody likes get the promotion because he's just so clever. I have repeatedly seen those who make effort to have great banter with higher ups get promoted over colleagues much more qualified.
Job security is mostly an illusion. You're only ever around until they don't want you around.
→ More replies (1)20
u/vladamir_the_impaler Mar 22 '22
We had a guy who wasn't an asshole, but he definitely architected systems to where he was basically the only one who could make things work and this did indeed result in job security for him.
Everyone non-technical thought he was just some badass running everything and that we really needed this guy when in reality he had designed things to be this way and none of the other devs cared enough to either say anything about it or try to change it.
Two days after this guy would go on vacation shit would start failing and breaking and they'd have to call him and get the low down on how to fix what was broken. I swear this guy must've had dead man switches on things to where if he didn't run certain manual processes every few days layers of the system would just stop working, and more would fail as more days passed.
After some years went by and modernization as well as some other changes took place I think they finally got tired of dealing with this BS and ended up hashing out why things were breaking when he wasn't around and how to re-do things so that it didn't happen anymore.
He's now in management and I've heard they are trying to get rid of him.
→ More replies (1)7
Mar 22 '22
I remember thinking this in school too but in reality you get enough job offers that you don't need to do this.
→ More replies (3)→ More replies (1)2
3
Mar 22 '22
On the other hand: being good at understanding and debugging obscure code like that is a really useful skill worth learning.
Not only it will help you easily take over the job when that guy leaves the company, but it will also help you understand your own code years after you stopped working on it because, more often than not, you (and me) are that guy 🤣
2
u/BullCityPicker Mar 22 '22
Yeah, so is knowing how to unclog a toilet. You're right, but I DO get to bitch while doing it.
363
u/vondpickle Mar 22 '22
Me: don't be that guy!
Also me: oh, that's me.
243
u/el_floppo Mar 22 '22
Came here to say the same. I was refactoring some stuff the other day thinking "Who the fuck wrote this garbage?" before realizing it was me.
63
Mar 22 '22
Home renovation is much the same way. Man the last person to do this was an IDIOT, which was also me, and still true.
12
Mar 22 '22
"What moron drilled a hole for the icemaker line 1 in. from the bottom of the joist?"... Fuck me I did that when we moved in. I'll have to move it, put up some stupid steel plate and pay a structural engineer to sign off on it in 10 years when we want to sell the house.
→ More replies (4)32
Mar 22 '22
I think we all do that when we revisit our past work. I am still waiting for the day I can look back and be like, damn, that is a fine piece of as…erm code right there.
16
u/OGPresidentDixon Mar 22 '22
I do this. I'll be looking at a beautiful chunk of code and my git lens extension will say "You, 3 years ago." 🥲
I'm pretty far along in my career tho and I used to have a lot more energy lol. Life caught up to me and I no longer can hack all night while continuously refactoring.
Also my variable & function names are like sentences now because I've used up most of the concise combinations of words that exist for what I'm building.
20
→ More replies (1)5
u/wjrasmussen Mar 22 '22
We do. Most often it is, for me, when I tried to do "something clever" that bites me.
→ More replies (1)9
u/CoderXocomil Mar 22 '22
I view this as a form of self-compliment. You have gotten better, so the old you doesn't look so good.
174
u/lolitoxico Mar 22 '22
For all learners here, most of the time :
Readability > Performance > Short code.
Learners in school often brag about writing the same program than their classmates with less lines
And sometimes those learners get hired and still have this habit.
don't
56
Mar 22 '22
something like
char (*(*x())[5])()→ More replies (3)26
28
u/Independent_Feed5651 Mar 22 '22 edited Mar 22 '22
This.
Code which is easy to understand and easy to change is the most important rule.
That doesn’t mean trying to “future proof” your code with additional tech debt. That doesn’t mean adding unnecessary comments. It means laying your code out in a way which allows a newcomer to understand what you’re doing almost instantly… via: layout (project files and class layout) and naming (files, classes, functions, variables).
Performance seems important.. but if you build an app in a semi-intelligent way, most performance gains can be had using simple data structures which can be inserted in later if necessary.
Also.. my pet peev: using design patterns which over-complicate and over abstract a simple app. If a majority of devs think your design pattern choice was unnecessary.. then it was.
→ More replies (1)→ More replies (1)11
61
u/CoderXocomil Mar 22 '22
I love devs who make messes until even they can't maintain their code. Then they move on to "bless" other companies with their unique coding style.
On a more serious note, I often wonder how these devs make it through code reviews. I absolutely would reject PRs written how you describe. I have inherited code like this but never worked with someone you describe.
35
Mar 22 '22
There is a high probability that code reviews weren’t a thing, or worse, the reviewers thought it was fine.
21
u/Saint_Nitouche Mar 22 '22
Rubber-stamp PR culture is real. Devs see getting someone else to sign off on their code as a chore and not a useful way to improve or catch errors.
As a result, they don't write meaningful PR descriptions and blindly approve everyone else's PRs. It's a vicious cycle.
7
u/CoderXocomil Mar 22 '22
That is the person you don't want to be. Don't rubber-stamp PRs. They only hurt you and the codebase. Instead, take the time to do a good PR and provide meaningful feedback. Don't be mean, but anything you let slide is something you have to maintain in the future.
→ More replies (1)0
86
u/regaito Mar 22 '22
It was hard to write so it should be hard to read!
/s
14
Mar 22 '22
It should be hard to write so it's easy to read, take some pity on your future self, and on your coworkers
I know it's /'s, but I still wanted to say :-)
138
Mar 22 '22
We use self-documenting code. Comments where needed of course, but if we need a lot of comments, the code needs to be rewritten to be clear and concise.
All of the other bullet points, I would have no qualms about taking that developer out back and beating them with a sack of oranges (if it was past their first offense).
33
u/Traches Mar 22 '22
Comments are for explaining why, not what, and only when it's not obvious.
"We're doing it this way because if we do it the obvious way it causes some subtle bug over here that you won't notice till the CI fails"
13
u/vi_sucks Mar 22 '22
I think even when it's semi-obvious,it should be explained.
Because what is obvious to you now may not be obvious to some new guy 3 years from now.
→ More replies (18)59
u/imnos Mar 22 '22 edited Mar 22 '22
Agree. Our codebase has next to zero comments. Tips for writing clean and readable code:-
Naming. Name your variables, functions, classes descriptively. A variable named
xtells me nothing about what it's there for, and likewise with a function calledget. What are you getting?getAllUserstells me exactly what that function should be doing. If it needs to be something longer likegetAllExpiredOrganisations- nothing wrong with that. It's still super readable.Try to break down your code by responsibility, following the Single Responsibility principle (look up SOLID principles if you don't know). For example, if you have a class or module that's 10000 lines long - chances are it can be broken into multiple logical classes. Then if you need to extend this to do another similar task - you can probably reuse some of the classes you've refactored.
Likewise with a function that's 100 lines long. Many language style guides enforce maximum lines per function (Ruby recommends no more than 5 for example). This keeps your code nice and modular, makes it easier to read, easier to reuse, and easier to unit test each piece individually.
Please don't try to be clever by doing fancy one liners that make the code unclear.
Lastly, a relevant quote from Jeff Atwood's blog which I think helps to enforce the above:-
"Always code as if the person who ends up maintaining your code is a violent psychopath who knows where you live."
https://blog.codinghorror.com/coding-for-violent-psychopaths
→ More replies (33)3
u/BeardSprite Mar 23 '22
To hopefully achieve this, here's some guidelines that I've been using with decent success:
If you absolutely can't find a name that is readable, descriptive and exactly captures what you're trying to do... chances are there is a problem in how the functionality is currently structured OR you haven't fully understood the problem yet
If you added a single line to the top of each class/module/function, describing its responsibility, stop and think whenever it gets too long or the word "and" occurs
If something is so long that you have to scroll multiple times, or even at all, and it isn't just data that just takes all the space, chances are the problem can be divided up further to make its solution easier to understand
Comments should explain the why, not the how, and have the goal of reducing the "WTF factor" of the code (number of times an unfamiliar reader will utter or think "What the f*ck" while reading it for the first time)
Not sure about self-documenting code, but surely a large number of comments can be eliminated by restructuring the code. The rest should have a purpose and not be sprinkled in redundantly.
→ More replies (8)15
u/Meborg Mar 22 '22
yeah this. If you add comments that have to explain a line in our codebase, you basically gotta rewrite your code. Method names should be self explanatory, variables should make sense. If you need paragraphs, you basically need more methods. Very rarely that comments in between lines of code are needed.
WHILE building something, I add comments nonstop. It's all todo stuff, or outlines, or pseudocode.
15
u/Bluedragon_00 Mar 22 '22
I'm self teaching coding please don't be too harsh for asking a super 101 question. Method is a new term to me. Methodology on how you should be coding? Or is it a technical function of code I havnt learned yet?
Context: When I first started I had no idea what assigning a variable was. Im currently practicing For Loops.
22
Mar 22 '22
Method basically reffers to a function that is defined inside of a class / object, you will get to it once you get to around to learning basics of OOP
→ More replies (5)→ More replies (5)4
15
13
12
u/corruptedOverdrive Mar 22 '22
Oh boy do I have a story for you.
Landed at Health Partners as a contractor. First day the current lead dev tells me he's only been there three months. Almost the day he was hired, they fired the senior most dev. I'll call him Xander.
I was told Xander was a sort of a prodigy. He'd been at HP for a few years and just unilaterally decided they had to standardize everything. He completely rebuilt, and developed a dozen sites on his own. He single handily created a design pattern library and a full blown design system. He was working 12-16 hour days. This was his magnum opus. His ultimate project he undertook all on his own.
Xander did all of this is under 10 months. But then the cracks started ed showing. The fraying at the seams was becoming apparent. He'd sit in meetings and as developers or designers were pitching ideas, he'd just stand up and start shouting at them. "You have no idea what you're doing!!" "You can't possibly make my code any better!! You are all beneath me!!"
His god complex had set in. After three months of constant, unpredictable behavior, they finally fired him.
The guy I was now sitting in front of listening to this story told me it was now up to us to untangle what he had left behind. None of it was actually built. None of it was actually approved. He had done all of this on his own servers and domains and presented it over a month or so to senior leadership. They were impressed of course but had no idea what to do with all of this.
It was a gruelling 18 months putting it all together and there were some moments where you could really admire his thinking on a scale this big all by himself, but it also drove him to the edge of insanity.
It was an eye opening experience on taking too much work on and the importance of protecting your mental health at all costs.
6
u/Gilgamesh-42 Mar 22 '22
Ha, couldnt even understand my 2 week old code without a ton of comments and 3 tons of slash
4
6
u/tr4nl0v232377 Mar 22 '22
Any tips how to not be that guy when I'm just starting out?
5
u/Plasticonoband Mar 22 '22
Have someone review your code and give you feedback. That's really it. Just make the mistakes quickly and with an expert to tell you what to do differently. Accept that you're going to repeat mistakes. Experienced devs generally like helping newer folks out.
→ More replies (4)3
u/vi_sucks Mar 23 '22
Write comments that explain your thought process. Even when you think it's obvious, do it anyway.
Give your variable and functions meaningful and clear names.
Write your code as if you'll have to give it to your least techie relative and they'll need to be able to understand what it does.
→ More replies (1)
10
u/TranquilDev Mar 22 '22
Don't need comments if your code's readable. - Says the guy who thinks his codes readable by anyone.
10
u/ruat_caelum Mar 22 '22
https://www.stilldrinking.org/programming-sucks Read this if you haven't it's a masterpiece.
2
2
u/rexvansexron Mar 23 '22
this reads like an after nut clarity experience.
oh how special little snoflakes we all feel like but still living the same shit through.
5
u/OvulatingScrotum Mar 22 '22
lolol when I started to code, I used to give random names to variables. like "blah" and "blahblah". I learned to stop doing that shit when I struggled to read my old codes later on, because I had issues with figuring out the purpose of those variables.
2
u/saintpetejackboy Mar 23 '22
Yeah, I went through this phase, too. I think it is common when you start out. I tried to get all philosophical and shit with my variable names and it is just a waste of time. My current trend is just unsetting a variable or reducing it to zero and using the same variable name I used elsewhere if it describes the same thing in a different context. I don't really recommend doing this, but it helps in a procedural context to maintain consistency and deliberately check the value of a variable in numerous places. I have already kicked my own self in the ass a few times over it when it caused some problems, so I will probably try to break the habit during my current project.
→ More replies (2)
5
u/dipdipperson Mar 23 '22
We've got someone like this at my job. He's an absolute turd of a person and a complete asshole to everyone around him. Despite this being Sweden with very strict labour laws, we could get rid of him relatively easily, but...
He's one of the founders of the company and owns a large share of it (but was voted off the board for being a complete fuck head). That doesn't mean that he's immune to getting sacked from his job at the company, but...
He built the platform on which we deliver our services to our clients. The code is pretty much what OP describes, zero comments, even less documentation, cryptic naming conventions, etc etc etc. If we got rid of him there's no way we could maintain it. We'd have to stop delivering our services to our clients while we build a new platform, that will of course have to cater to the design quirks of the then- obsolete platform, because so many of our applications are built with them in mind.
During that time, we'd have to suspend services to all clients for God knows how long. That's an immediate loss of millions of dollars and we'd likely lose all our clients' trust and future business.
The guy is severely overweight, in his late 50s and has a temper problem, so the heart attack is simultaneously inevitable and not very far away, at which point we'll just have to do what I detailled above.
Come to think of it, I should update my CV.
26
u/OddBet475 Mar 22 '22
Comments are an absolute last resort. Don't be the opposite and comment the death out of your code. It should be understood without.
There's a place for comments (maybe) but that should be extremely rare. Use meaningful naming, the KISS and do not repeat yourself principles and we can all live without comments. I work in a 25 odd year old code base and comments hurt more then they help, they can't be trusted and may be misleading. People don't fix comments when changing code.
4
u/__Mauroo__ Mar 22 '22
I'm new to programming so i have a question. Isn't writing a comment before ever function/part of code to explain what it does a good idea if you know someone else will have to look at your code? I think it might take some time, especially if you have already tested that function/part of code and know it works
5
Mar 22 '22
Write comments whether you want to justify certain “weird” choices or if you want to explain a particular complex business logic procedure.
4
u/g4rthv4d3r Mar 22 '22
The idea is that the name of a function should be descriptive enough so readers know what it does without having to read its comment.
Block comments to explain what a paragraph of code does is an indication that this paragraph should be moved into a private function.
In general, comments should not be used to describe what the code does, they should be reserved to explain why you're doing something a specific way vs another, which means explaining your design decisions.
Additional benefit is that extracting functional blocks into functions allows you to unit test then separately.
7
u/wjsoul Mar 22 '22
I think what most people in this thread have already said, often times, its not beneficial to over comment. If you name your functions/methods and variables in a way such that it explains itself, you'll find that most of the time, you don't really need comments.
An example would be something like this:
wait_for_it_to_rain() cover_yourself_in_oil() fly()Every one of these functions describes what they're supposed to do, you do not need any comments to explain them.
→ More replies (1)3
u/vi_sucks Mar 22 '22
Yes. Write comments. Please, for the love of all that is holy, write comments.
4
u/vi_sucks Mar 22 '22
Ugh, this is a bad philosophy.
I've worked in a code base from the goddamn 70s and let me tell you, seeing comments in that shit is a godsend.
People swear up an down "code should be self-documenting" "revision history will tell you what you need to know".
Sure, and then you port the codebase from SVN to Git and lose everything older than the last two years. And now you dont know of that line of code that says
Boolean billingUnpaid = verifyBillPayStatus()
Is a typo or valid code. Was the dev intending to return true when billing is unpaid? Was he intending to return true when billing is paid and simply wrote the wrong variable name? You don't know! Nobody knows! Until the users test it and fail it because it doesn't "work like it used to"
→ More replies (3)11
u/Inderpreet1147 Mar 22 '22
If people don't update comments while updating code, that's on them and the reviewer honestly
→ More replies (4)
1
u/Rote515 Mar 22 '22
That’s my company’s entire codebase… no I’m not kidding, 3000 employees almost 0 comments almost all 1 letter variable names. Kill me.
1
u/BullCityPicker Mar 22 '22
How did that happen? Let me guess.....some frat boy decided it was much cheaper to offshore it to someplace where they don't speak English, and "x1....x205" was a reasonable naming convention?
→ More replies (1)
1
u/perpetualeye Mar 22 '22
I tend to delete a whole bunch of code and rewrite it
1
u/BullCityPicker Mar 22 '22
You are very wise. It's always much better the second time, but it's hard not to fall into "keep slapping bandaids on it" trap.
1
u/IdempodentFlux Mar 22 '22
Do you think comments are needed if the function names are super clear/read like a sentence?
1
u/BullCityPicker Mar 22 '22
I suppose I could be convinced by a good counter argument. Adding in a good example is a nice bit of documentation. For example, if you're passing in a column of data, are you literally passing in the column reference, or the name of the column as a string to be de-referenced later? If there are flags controlling behavior, do you list what the legal options are? Are there conditions, like null values, that would cause the function to fail if the data passed in isn't 'clean' enough?
→ More replies (3)3
Mar 22 '22
Overcommenting is a beginner's mistake that can reduce code legibility. I often see beginners write
x = x + n; // add n to x. Comments should be used sparingly to explain how code should be interpreted and what it needs, and the code should itself be legible. Add as many comments as it takes for someone who can read code to understand your code, and not more. So, yes, if the function is short and tidy and does not have secret side-effects or byzantine demands, you can do without comments.
1
u/CantorIsMyHero Mar 23 '22
If I can't name my variables single character alphanumerics, why even be a programmer?
1
u/BullCityPicker Mar 23 '22
That's like saying, "If I can't drive recklessly, and shoot people, what's the fun in being a cop?"
→ More replies (1)
1
u/red_keshik Mar 23 '22
No error checking.
This is just bizarre. No one does code reviews ?
1
u/BullCityPicker Mar 23 '22
Yeah, we're a data science team, not real programmers. I have a fair amount of 'real programming' in my background, but not many others do.
1
u/MeeseAndMen Mar 23 '22
If he was as underpaid and overworked as the rest of us, good for him. No offense bro but company money/time not yours
1
u/BullCityPicker Mar 24 '22
Yeah, but now I'm faced with a lot of frustrating work, and my boss is going "hey, you got handed the project and a bunch of running code...". No, actually it doesn't run.
1
u/Professional-Sun-684 Apr 19 '22
Good readable code doesn't need any comments in their code base. Code doesn't lie whereas comments can/and often do especially when they are not maintained
1
u/BullCityPicker Apr 20 '22
Comments to establish what a function does, what the arguments are, and known failure cases?
I’m so happy for you your code is so perfect in needs no embellishments in pesky English. I’ve just spent the last two weeks rewriting a pile of shit from a guy who had the same attitude just to get it to run.
1
u/Professional-Sun-684 Apr 26 '22
Since a function should focus on 1 thing and is about +/- 5lines long, the function name should explain what the function is doing.
Arguments should have self-explanatory name. For example if your function is to set up a connection and you need an IP and port as argument then name those arguments IP and port instead of x and y.
Failure cases are handled by different exception handler depending on the failure. Custom logging messages can be added to explain what happened or what went wrong. But still custom logging messages are not comments.
I highly recommend the book "clean code by Robert Cecil".
Also: I never said my code is perfect. I said my code is very readable written and is self-explanatory. readability > performance. Don't compare the guy who left you a "pile of shit" with me as you do not know me and never saw a piece of code I wrote.
2
u/BullCityPicker Apr 26 '22
OK, I apologize. You really can't believe what "that guy" put me through, and I was pretty angry. Unlike you, there were lots of 'x', 'y', and other very, very short variable names, which were obviously reused for dissimilar purposes through the code base. I'm still trying to figure out what he did.
I never saw a formal rule of thumb for function length; 5 lines seems way to short. I try to keep mine under one screen on an IDE. I looked into some of the packages I'd written. My code averaged about 22 lines per function, and had eight lines of comments per function, if you can live with that.
3
u/Citan777 Mar 22 '22
I had to work with a guy kinda like that for a while, officially a "xxx expert / senior developer". Gave me a whole new vision about the impostor syndrome...
2
u/ThisIsNotWhoIAm921 Mar 22 '22
was he hired with the senior developer title? Did he act insecure about his code?
3
u/Citan777 Mar 23 '22 edited Mar 23 '22
Weeeeeell... (sorry for the text block, don't know how to give details without context).
I had been hired to lead a "team of developers" upon refactoring a semi-sensitive content website from old&abandoned framework to a more modern and perennial one. Contract was 3 years, which seemed damn overkill to me given the apparent specs.
Turns out a few "details" were left out...
1/ Clustered organization with development team, product manager and "traditional project manager" all in different departments and cities.
2/ My team was in fact no developers. At ALL. People that basically did support on scripts and minor modifications but never had training or real experience on projects, let alone web.
3/ Management decided to go for new framework (Drupal), new methology (Scrum/Agile), and give Product Owner role not to me (although I really was the best fit for this since I had the two visions, technical and business) but someone that knew nothing about web.
As you can guess, most ingredients of the recipe for epic... Fail! Still, in 3 years, was really feasible. 8 months focusing on training team to web development, in parallel spending time to think about architecture from user stories, then developing in iterative ways, perfectly manageable.
Long story short, it obviously didn't go that way, since management never admitted they did had a "casting problem" thus never gave my people any time to learn.
So after a few months they brought a "Drupal expert / senior developer" the project manager had already worked with on a previous project.
This guy quickly enough gave off several alert signals, but since he had a decent reputation and misunderstandings can always happen my and my OPS really engaged to work with. Because he managed to make some things work "for sprint demo" (whether that was actually workable production code or not), while my team was (understandably) completely crushed under the sheer amount of layers to grasp simultaneously and thus unable to produce, in a few months project manager made him the decisive guy (we later got three more people that were actual senior developers, although Javaist, from there we started making true progress but it was too late to change management dynamics).
Was he a professional? I'll let you judge. Among a few pearls...
- Zero interest in following best practices and git branching everyone had decided together.
- Always pushed code straight on mainline, forcing OPS to develop some weird process to prevent automatic builds on Jenkins if a local build without errors wasn't first made.
- Systematically made commits mixing A, B and Z, and only after several clashes started giving a reference to ticket (but still no indication on what's done, and sometimes mixing topics from different tickets).
- Fulfilled a mission to "align header text on left" *by increasing font size*, then complained it was not its fault layout broke later when we decided to increase font size globally because was not readable enough (we do agree that any decent person would have used text-align right?).
- Wrote several modules, A depending on B, then commited without specifying the dependance "in Drupal" resulting in build crashing, held OPS responsible for "not adjusting pipeline to make modules activate in the right order" (FYI, module definition takes care of that, it's the second thing you learn in Drupal development, it's definitely NOT ops's responsibility).
- Forked code from mainline to work on the backend part, straight up modified code *that was still used for the frontend* in spite of my numerous warnings NOT to do that, and of course never ever updated that code from frontend branch (I'll let you imagine the wreckage it resulted in when we finally could grab control of project again).
- Rarely commented code, was fine with generic variable names or typos in "human-readable" variable/function names, was fine with 4+ nesting level, "Utils" classes with completely unrelated things inside...
- And "of course" never wrote any single test (didn't even know how to write it).
- Fun fact: I had made some architectual analysis before project started, which had several flaws but was still decent enough on some critical points. More importantly, that guy ignored it fully to do things "his way" instead of simply demonstrating how his way was better (or mine was plain wrong), which was nothing more that I asked for.
Consequently, the backend that was supposed for 300 active authenticated users crashed server with... 10 people. On a mainframe with 2 web servers (each 16 core, 32Go), 1 cache proxy (similar specs) and 1 database server (similar specs). For what amounted to, in spite of weirdly complex validation process, a glorified documentation production.
Disclaimer: even if Drupal is reputed for being resource-hungry for authenticated, this is *not* normal. xd
Fun fact, bis repetitae: after some refactoring under my architecture choices, and huge work of rewriting code to make it less bloated and more reliable, we optimized database requests and caching so much that performance graphs were basically staying bottom line so we could divide platforms by a factor of 4 without users feeling any difference. xd
EDIT: sorry for what's nearly a pure rant. I just didn't completely make peace with this experience yet. Nearly cost me my sanity and broke several people in my team due to absolutely outrageous behaviour of management. Plus several *millions* of public money wasted because that guy was an expert factured ~1500 on a daily basis. For MONTHS.
→ More replies (2)
3
Mar 22 '22
The guy who I replaced in my current job has no comments anywhere and kept telling my coworkers to “google it” when they had questions about the code base or concepts with the framework we’re using.
3
3
u/Dom1252 Mar 22 '22
you know what is worse? there was a dude working in our company who created some cool programs... of course he had to run it compiled because "it would otherwise be too slow" and delete source code "because it was a mess and no one should use it, even the compiled thing" meanwhile there's bunch of people trying to reverse-engineer it because it's actually awesome
2
u/saintpetejackboy Mar 23 '22
I had people "steal" my code before, and it just sucked for them because I suck at programming and what they stole was about 23 hours of solid work and several grams of caffeine behind the version I hadn't published yet, which ended up being an insurmountable gap for them, to the end of both respective projects. It is akin to writing a great song and somebody rips it off. Are you a talented song writer, or did you have all your eggs in one basket?
Fortunately for me, I was able to keep sucking at programming for dozens of projects or more since then and I doubt the thieves that originally stole my code have yet to come up with an original thought between the lot of them.
These days, you would need Dwayne "The Rock" Johnson and a machete even to read my jungle of code. Stealing it is out of the question, you would go mad at the mere suggestion of some of the dumb shit I do.
3
u/noob-newbie Mar 23 '22
Yes, also get hand over a project with very less validation. Like never check if the object is array or not, and keeps calling array functions.
Whenever these kinds of bugs appear, the coworker who is responsible in the communication between dev and client always ask me when did this happen, can I trace which commit caused this issue, I feel a little bit annoying.
3
u/whitedragon101 Mar 23 '22
I love comments but at my current company the lead developer discourages their use. He says:
“comments can become out of date. Your code should tell a story, structure it in a way that you can read the code and understand it. If a piece of code is complicated give it its own method and name the method for what the code does.”
3
u/samanime Mar 23 '22
One of my favorite quips:
Always write code as if the person who has to maintain it is a psycho with a chainsaw that knows where you live.
Words to live by.
3
u/Metalor Mar 23 '22
ZERO comments in your codebase.
To offer a different outlook on this one, ideally you shouldn't need comments in your codebase as it should be written in a way that other developers can read it, aka 'self documenting code'. I appreciate this isn't always possible.
This way of thinking ties in with the 'one and two character variable names' - name it what it is. Same goes for method naming, name it what it does. It sounds easy but it isn't. Most of the time you're in the context of what you're doing and that can influence what you're naming things whereas it may not be so obvious to someone who's coming in fresh.
Also, I like the saying "code can change, comments don't" meaning that comments may not evolve as the codebase does so those comments eventually become lies.
3
2
2
2
2
u/kagato87 Mar 22 '22
No error checking...
I've been on my team about this from the support side. Assume your code will try to ingest bad data at some point. It'll happen sooner or later.
Maybe it'll be a bug in the code.
Maybe it'll be an oversight in an ancient API endpoint that we can't depreciate because one large customer still uses it.
Maybe it'll be some cowboy trying to fix something from the sql side.
Maybe it'll be that shiny new API inserting a zero in that one field instead of a null, making another API freak out because zero isn't a valid iI'd
(I was the cowboy in that list. Most of my fixes worked but one didn't. Quick enough fix once I was told what I'd missed but... Still haven't lived it down.)
3
2
u/HappyRogue121 Mar 22 '22 edited Mar 22 '22
Comment characters used to comment out big chunks of code for no discernable reason.
I do this occasionally
I do this sometimes
Messagebox.show("I might do this")
I'm just a hobbiest, but I definitely do this.
2
u/saintpetejackboy Mar 23 '22
I do this all the time.
My favorite is when I have a similar block I already wrote, or dissimilar but it has all the variable names I need, so I copy it, comment it, and then use it as a reference to type up a new block real fast. Test it, doesn't work. Trial and error. Go to lunch. Fix it. Forget.
Two weeks later I am back in the code and see this commented out block that has nothing to do with the surrounding code. This happens mote than I would like to admit.
The comments in my code are more like boobytraps or a Deadman's switch. Woe be unto ye who takes heed to the code I commented out simply because it didn't work and never went back and deleted it.
2
u/baby_sharkz Mar 23 '22
Except you don't know what the situation was at the company and if they were rushing or pressured to finish something. Commenting out chunks of code is probably because they were planning to use it or needed to leave a reference to previous work.
Can we just be kinder to each other? This post is just mean because the op is angry.
2
2
u/Khaotic_Kernel Mar 23 '22
I've dealt with this issues like this for years whether it be for grad school or my first job. That's why I stress the importance of good documentation for a project. Hopefully if people get called out on these actions it will go away, though, that requires holding the people accountable, which companies/organizations don't always do.
2
u/ZakDahlia Mar 23 '22
I'm really interested in the field of computer coding, I'm not great at it by any means. Literally am barely learning C++, in fact if it weren't for a certain redditor I would more than likely be failing. That being said, things like this really help me. When I turn in assignments I never use // for notes, and that's what really stood out to me. Im super new to this as I'm going back to school in my 30's and thank you for letting me know early on what not to do. I do not mean this facetiously and am very grateful I am subscribed to this sub reddit.
2
u/Able-Panic-1356 Mar 23 '22
I once saw a guy submit an assignment where he used half the letters in the alphabet as variable names. I think the teacher probably had a heart attack. I don't even know what he would have done if he needed 27 variables... Maybe excel style?
2
u/dphizler Mar 23 '22
Not defending the previous person but I see a lot of self righteous criticism towards others around here.
We don't know the circumstances in which this code was written. Maybe after a few years of writing perfect code at this company I'll give more weight to your criticism of this one person.
2
u/toxicblack Mar 23 '22
It’s good to have a senior that’s willing help correct things like this and not just chew you out
3
u/DaredewilSK Mar 22 '22
The first one is unnecessary if the other ones are in check.
0
Mar 22 '22
[deleted]
→ More replies (1)5
u/daneelthesane Mar 22 '22
I agree. I am reading "self-documenting code" right now that doesn't tell me a goddamn thing unless you are already sharing brains with the guy who wrote it. Sure, a lot of code can be self-documenting, and that is an ideal, I guess, but there are also people who love to make things as obscure as possible, as short as possible, etc. Picking the right names for variables and methods doesn't help if the syntax doesn't tell you what is going on, or you don't know why.
2
Mar 22 '22
Oh my god, that would suck to just read through, trying to understand all of that pile of mess...
2
u/laravel_linux Mar 23 '22
I dont like comments either. If ur classes, methods, variables and all got clear names and ur code is not a spaghetti mess i dont see why you would fill the codebase with comments. That goes in the documentation
1
u/afl3x Mar 22 '22
Lol sounds like a third party adapter I just had to write tests for.... 15k lines.
1
1
1
1
1
1
u/geoffreychallen Mar 22 '22
On the other hand, you have Marc Andreessen's mantra when developing Netscape, as described in Clive Thompson's book Coders: "Worse is better."
1
Mar 22 '22
Not programming related but the guy I work for is the same way.
- No company data off-site backups / even on tape/drives
- Demands AOL as email usage
- No communication skills
- Claims is retired yet doesn't give company to next of kin, no selling it, or keeping it going, everything has been half assed.
etc.
1
u/dergruneapfel Mar 22 '22
If you’re going to comment out chunks of code, then that’s fine, but you should have an updated version of that source code without any commented-out blocks. This is one of the many reasons why Git is so useful. You can go through several revisions of source files until everything works, and your code is readable by anyone. You can also look at your old “rough drafts,” with commented-out code, to remember why what you wrote didn’t work properly.
1
u/marty_76 Mar 22 '22
But using two-character variable names reduces memory usage! Therefore more efficient.
/s
2
u/greebo42 Mar 22 '22
ah, I remember a time when that was true!
oh, PDP-11 BASIC (circa early '80s), I don't miss you!
→ More replies (1)
1
1
u/Flakz933 Mar 22 '22
Happened with me too, took over an API project that uses a lot of auto generated code, so many people don't understand it and when I do understand it, it takes a week or two to get code reviews to push code up, more BS that road blocks me
1
1
u/vladamir_the_impaler Mar 22 '22
and get to be all smug
That is hilarious and somehow makes me angry at the same time...
How sad it must be to actually operate and think like that...
1
1
u/purplebrown_updown Mar 22 '22
Most companies should have a code review where you explain your code and have other understand it. It’s tedious but it helps.
Also, a good marker is if you can come back to your code a month or two from now will it be easy to use? Even harder, if you come back a year from now, will it be able to run?
1
u/LiveWire11C Mar 23 '22
I keep all my notes in a separate doc. If you are cool/nice, you get the notes. If you are a jerk or asshole, no notes for you. It's also job security sometimes.
1
u/saintpetejackboy Mar 23 '22
I only ever ended up writing elaborate comments on projects nobody ever probably seen. The code I put in production everywhere is probably a nightmare, that is no lie. Most if it has sparse comments and often inconsistent naming of functions and variables, especially my older projects. It doesn't take too many projects where your database columns have different names than your variables elsewhere before you develop some kind of internal standardization.
Some of my code isn't really worth commenting, to be perfectly honest. Not because it is too simple, but because it involves non-procedural logic but relies heavily on the structure it inhabits. I often intertwine "dynamic" code with static templating as part of my design process and had a ton of trial and error of how far down to segment my own code over the years... comments alone aren't going to help the next person understand why I didn't choose their favorite framework for my project.
Three days on, you realize you accidentally swapped $agentAccess for $accessAgent in numerous instances and the code works as it is. If you make a comment like:
// This is the same variable $accessAgent === $agentAccess
This doesn't really tell the whole story. The next person just innocently "fixing" the code by changing that reference to $accessAgent or whatever is going to cause a fatal error - for whatever reason, the parallel isn't even defined at that point in the project and I could never figure out why, so I doubt the next person is going to solve it, especially not with that useless comment.
Not saying you shouldn't comment your code. Don't waste time writing shit nobody is ever going to read. Nobody even reads the docs. The comments in your code are more like a personal margin to graffiti in than some divine road map for a future expedition, in my opinion.
1
Mar 23 '22
Got to say this is why I make no illusions about my (lack) of skill with coding. If my job security is shooting my mouth off about skills I don't have might as well quit now. I don't get why people do this.
1
u/Mrphamvanman Mar 23 '22
I'm learning coding in a rush because I really need a job. And I never write a comment line in my code :(((.
1
u/minaj_a_twat Mar 23 '22
Sounds to me like someone that lied on a resume and got to high over their head
1
1
u/SamuraiZero4 Mar 23 '22
The only reason I don't comment my code is because I'm still in school and feel like its meaningless, but maybe I should start just to build the habit.
1
u/Obvious-Effort1616 Mar 23 '22
Well sometimes i feel sorry when i started learning to code i used to be like that but now i dont because i m grown up coder and i understand how to manage codes, documentation and commits.
1
u/psichodrome Mar 23 '22
I'm literally doing this all day today. It's been a wild ride.
At least mine's commented, though most comments are "To Do: ..."
1
u/StarLan7 Mar 23 '22
I try not to be that guy. I don't do all of the above but one prblm that I do is not put enough comments in my code. I am tryna improve on that.
1
u/Tintin_Quarentino Mar 23 '22
Comment characters used to comment out big chunks of code for no discernable reason.
Is above equal to "big chunks of code commented out for no discernable reason"?
2
u/jay_thorn Mar 23 '22
Yes.
To OP, “Comment characters used to comment out …” how else are you going to “comment out” something.
1
u/swdbdm Mar 23 '22
People have been doing this since the 1st line of code was matched to a 2nd line. There are good coders great coders lousy coders and destructive coders. Normally the last 2 are very good at talking code just not actually doing good coding. I have taken millions of lines of code out and rewritten or just left it out and see what breaks then fix it. Just have a beta system ready. Good luck.
1
u/dutchmaster77 Mar 23 '22
Sucks to inherit this kind of code. Will also add tons of functions that are not actually used but no comments or documentation explaining why it’s there
1
1
1
u/False_Preparation_99 Mar 23 '22
I think this is his final revenge before leaving this company.
→ More replies (3)
1
1
u/svamlade Mar 23 '22
I don't understand why some people are so crabby when someone asks a question; it's not like they have to answer it. If you truly think it's a stupid question, why don't they just not answer it?
1
u/ramp_guard Mar 23 '22
Question: How did that guy get his job and what arguments would you give that could speak for him keeping that job?
→ More replies (3)
1
u/firestepper Mar 23 '22
I have a hard time knowing when to comment... i guess it's better to just comment more than you think?
1
u/theRealJuicyJay Mar 23 '22
Don't be that guy? Management doesn't give time to comment and document code and its my fault? Nah fam
1
u/Cdog536 Mar 23 '22
Comment your code in a way that sounds like you are talking to the computer and telling it what to do. This is the best way to comment in my opinion and helps you debug quicker. It’s also a great way to write pseudocode
Write clear variable names. Make them long if needed. Make it fucking clear and follow a naming pattern pertinent to sub sections.
1
u/tmckeage Mar 23 '22
Add "Name all your classes after Loony Toons characters because you think it is funny."
1
1
u/meatballx Mar 23 '22
This literally sounds like the owner/primary architect of the company I work for. We have a check-in system that regularly gets bypassed in favor of hot-patching untested code to production. Our development environment doesnt even remotely match production due to this.
1
u/Hijinx_Galore Mar 23 '22
*Noobie here - I start interviewing for my first job next week.* The situation described instantly annoyed me. I promise to not be a smug asshole in my coding, even when I achieve Master Splinter level.
1
Mar 23 '22
I just left a job that only hires juniors and has no experienced management. This is just how it works. They keep cycling through devs and never making progress on anything.
1
Mar 23 '22
We’re coding very simple programs in pyhton in math classes. We’re talking, “make a program that finds the points where f(x) = 0, for graphs following ax2 + bx + c”. Not too hard math, not too hard to code. Our teachers are just the usual math teachers, that had a 2 day course in coding. I watched a 2hr youtube video and I am now the go to guy for coding questions in my classroom.
Anyways, this is our teacher. When she posts solutions for the problems we’re supposed to do, she never comments, and never names the variables. When she defines a function, it never has a related name. She tries to show us that what we name everything doesn’t matter, and by doing that half the class is falling behind.
And speaking of bad teaching she tried teaching us how to make codes that add vectors together. She showed us how lists and arrays work, but then proceeded to not use them when solving the task. When I did the task using lists she was annoyed i didn’t take notes of what she was saying, and the way I was doing it was somehow making it harder for all the other students to learn her way.
If you’re going to teach me python, atleast have the teachers know what they’re doing. I’m not blaming her, she is lovely. She got two days to learn what she had one year to teach us.
1
u/zmbiehunter0802 Mar 23 '22
I just inherited a codebase and it's pretty rough. Barebones comments, if any. Rogue files that are unclear as to their relevance, and to top it off, management made changes to the raw files on the server on the master branch rather than using GitHub. So now the repo is out of date, and I'm doing my best to avoid having to blow out the server and re-clone it so I can actually perform changes. Oh and I'm doing this while learning the framework it's written with, as the sole developer on staff.
1
u/Freeman421 Mar 23 '22
I think this was less being smug, and more so an attempt at job security....
1
u/someStudentDeveloper Mar 28 '22
I knew a guy who wrote some COBOL code, and since he was the only person who knew the language, he was untouchable. Even after he retired, the company contracted him to come back periodically when we had to run it. Of course, his hourly rate was outrageous.
When covid19 unfolded in early 2020 there was a similar situation in NJ https://www.cnn.com/2020/04/08/business/coronavirus-cobol-programmers-new-jersey-trnd/index.html
1
u/Electrical_Flan_4993 Apr 11 '22
Can you post some of it? Curious if you are seeing wpf handlers and lambdas
1
u/HerLegz Apr 12 '22
Sounds like a phenomenal leetcode and interviewer. Interview folks for the job they're going to do and then surprised they do it exactly the way they showed. Engineering is upside down af right now.
119
u/biggamax Mar 22 '22 edited Mar 22 '22
Going to play the Devil's advocate here. Although it's likely the coder/work you're slagging off publicly deserves it, you're coming in after the fact and armchair quarterbacking. Criticizing the guy/code is low hanging fruit. Getting to work and improving the situation (instead of venting on Reddit) is where you can show real value.
What you haven't told us:
- What requirements was the dev working against?
- What timeline did the dev work under?
- Did the dev have enough help on his/her team?
- Was there intentional tech debt for a good reason that was beyond his/her control?
- Was the dev spread thin on many tasks, or was this code his/her sole responsibility?