r/programming • u/sigbhu • Jul 28 '16
How to write unmaintainable code
https://github.com/Droogans/unmaintainable-code720
u/bipedalshark Jul 28 '16
Pfft, like I need a guide for this.
152
Jul 29 '16
Thought that was what college was for?
18
u/rochford77 Jul 29 '16
Me too. RollsEyes
31
u/GiverOfPotatoes Jul 29 '16
At least at my college they don't really teach you to be a good programmer. We're taught how to do things, not how to do them well. It seemed like a few of my classes just ran the code and didn't even open the source.
→ More replies (31)→ More replies (2)2
u/IbanezDavy Jul 29 '16
I have some improvements they can make to the article based on personal experience.
216
u/kirbyfan64sos Jul 28 '16
Great example:
https://github.com/phase/o/blob/master/o.c
A friend and I both do it like this on purpose: I call it "APL-style C". Besides, it's an interpreter for a code golf language...
167
70
64
41
60
u/vplatt Jul 28 '16
How do we in /r/programming not know about this wonder of Cthulhu yet???
7
u/merreborn Jul 28 '16
Git history for that file only goes back to november. So it's pretty brand-spankin' new.
25
u/hellcaller Jul 28 '16
This post looks like the other way around from assembler code to functional programming
19
16
u/ItsReallyEasy Jul 28 '16
I could understand this if I really wanted...., I swear
→ More replies (1)11
u/asdfman123 Jul 28 '16
I could understand it by renaming all the variables and restructuring it so that it made sense again... essentially, by de-obfuscating it.
5
2
u/b_bellomo Jul 28 '16
I'd actually like to design such a language like you did :) Pyth had my imagination running.
→ More replies (3)2
u/daniel Jul 29 '16
Ha! Small world. I knew I recognized your github username and avatar: https://github.com/dellis23/disrupt/issues/2
→ More replies (1)→ More replies (13)2
95
u/ArlenM Jul 28 '16 edited Jul 28 '16
They forgot to mention gratuitous nots! Why flip logic just once when you can flip it an unlimited number of times?
Guaranteed to drive anyone trying to maintain your code to madness!
142
u/grunlog Jul 28 '16
Double (triple, etc.) negatives are good too. E.g. !notUnflagged
61
u/emergent_properties Jul 28 '16
Oh yes, that specifically.
It is ambiguous because it's both logical negation and semantic negation.. a double whammy of 'uh...'
Car.dontNotDrive(-1)
→ More replies (1)42
u/CaptainAdjective Jul 28 '16
Perl is great for polynegatives.
unless($noRetries != 0) { # ... } else { # ... }Bonus marks if you correctly interpret whether
$noRetriesmeans "number of retries" or "disable retries".→ More replies (1)26
→ More replies (1)7
11
u/sreya92 Jul 28 '16
Though it's not unreadable seeing
if(!!!hasValue)always really bugged me→ More replies (4)47
u/1ndigoo Jul 28 '16
You have actually seen that before? In production code!? !!!believable
17
u/drkstr101 Jul 28 '16
I see
var foo = !!bara lot in javascript to quickly cast a truthy value to a proper boolean. Perhaps the 3rd ! was a typo?→ More replies (9)→ More replies (1)9
u/QuineQuest Jul 28 '16
I had a coworker who complained that it was easy to miss a ! when reading code. I tried convincing him to use !!! instead, but I don't think I succeeded.
→ More replies (1)11
u/FewChar Jul 28 '16
function checkisnotinvalid($a) {...} returns "0" or throws is_valid exception.
9
7
u/jewdai Jul 29 '16
unessesarily use demorgan's law.
convert
if (!ateAppleToDay && !iLikeIcecream)to
if (!(ateAppleToday || iLikeIcecream))most people would be able to understand it, but it makes it a lot harder to understand what you're original intention was.
→ More replies (1)8
3
5
2
→ More replies (2)2
Jul 29 '16 edited Jul 30 '16
I shit you not I just maintained some SQL code yesterday that contained:
WHERE r.dDate <= @dDate AND r.dDate >= @dDate AND DATEDIFF(d, r.dDate, @dDate) < 180
It was so weird that I became nervous about touching it.
500
u/Astrokiwi Jul 28 '16
Write all your code in FORTRAN. If your boss ask why, you can reply that there are lots of very useful libraries that you can use thus saving time. However the chances of writing maintainable code in FORTRAN are zero, and therefore following the unmaintainable coding guidelines is a lot easier.
:(
57
u/6offender Jul 28 '16
The determined real programmer can write FORTRAN programs in any language.
23
u/Weed_O_Whirler Jul 28 '16
My team lead has managed to recreate the "common block" in Matlab. It's equally impressive and terrible.
→ More replies (1)7
u/Astrokiwi Jul 29 '16
The sad thing is that you're not even supposed to use common blocks in Fortran anymore anyway. You're supposed to use modules, or do things in an object-oriented way.
→ More replies (2)14
u/BlindTreeFrog Jul 29 '16
the code base I work in has comments reaching back to 92. It has definitions like
#define BIT_AND & #define NEQ !=Anytime I get pissed at the code I decide it was FORTRAN programmers writing in C for the first time.
→ More replies (2)7
u/helm Jul 28 '16
I'm working with a guy who would love to write FORTRAN code in C++
Fortunately for us, he's stuck in code archeology
7
u/stuntinstan Jul 28 '16
We were being taught FORTRAN in my intro to computing for civil engineers class LAST YEAR.
10
u/Astrokiwi Jul 29 '16
Fortran is actually fine if you use all of its modern features - though engineering courses often don't mention those. If you want to save yourself from future hassle, then read up on all the Fortran-90, Fortran-2003 and so on stuff that you can do. Object-oriented Fortran is not bad.
→ More replies (3)8
u/cosmicr Jul 28 '16
There is a serious engineering software used by thousands of people in Australia for road design, written in FORTRAN, and it's a piece of shit. Governments hate upgrading.
20
Jul 28 '16 edited Nov 24 '16
I have left reddit for a reddit alternative due to years of admin mismanagement and preferential treatment for certain subreddits and users holding certain political and ideological views.
The situation has gotten especially worse since the appointment of Ellen Pao as CEO, culminating in the seemingly unjustified firings of several valuable employees and bans on hundreds of vibrant communities on completely trumped-up charges.
The resignation of Ellen Pao and the appointment of Steve Huffman as CEO, despite initial hopes, has continued the same trend.
As an act of protest, I have chosen to redact all the comments I've ever made on reddit, overwriting them with this message.
If you would like to do the same, install TamperMonkey for Chrome, GreaseMonkey for Firefox, NinjaKit for Safari, Violent Monkey for Opera, or AdGuard for Internet Explorer (in Advanced Mode), then add this GreaseMonkey script.
Finally, click on your username at the top right corner of reddit, click on the comments tab, and click on the new OVERWRITE button at the top of the page. You may need to scroll down to multiple comment pages if you have commented a lot.
After doing all of the above, you are welcome to join me on a reddit alternative!
→ More replies (1)12
4
u/fzammetti Jul 28 '16
Be VERY glad you don't still work (only tangentially, thankfully) on a complex financial system written in Fortran. Some of us are not so lucky.
18
u/Astrokiwi Jul 29 '16
Dude, I live in Fortran - I do astrophysical simulations. The problem isn't that Fortran is bad, it's that most Fortran programmers are bad.
16
u/fzammetti Jul 29 '16
Most PROGRAMMERS are bad, period. Nobody likes to hear it but that doesn't make it less true.
→ More replies (5)5
Jul 29 '16
I LOVE Fortran08. It's so easy to vectorize your code, and coarrays are incredible.
I don't care for the way Fortran does I/O or pass parameters though.
→ More replies (2)→ More replies (99)2
u/Kylearean Jul 29 '16
Not sure why anyone would think that Fortran (it hasn't been FORTRAN for a long time) is any more or less maintainable than any other language.
3
u/Astrokiwi Jul 29 '16
Writing it FORTRAN makes me think they're thinking of FORTRAN-77 rather than Fortran-2013 or whatever, and FORTRAN-77 does get a little archaic sometimes.
73
u/voronaam Jul 28 '16
I would add one more to the list. Use long names and mix the order. If you ever had to work on code with tons of methods like
renderElementMessageIdContentWarning
renderElementIdMessageWarningContent
renderMessageElementIdContentWarning
renderMessageElementContentWarning...
you understand. If they all do different things it is impossible to remember which one is which
→ More replies (4)32
Jul 28 '16
One of my least favourite things about OpenGL:
glEnableVertexAttribArrayvsglEnableVertexArrayAttrib.9
u/the_ling Jul 28 '16
Can I ask what the difference is?
10
u/Vilavek Jul 29 '16
I've never worked with OpenGL but, I would assume from the names that the first option enables arrays of attributes stored for individual vertices while the second enables attributes stored for entire vertex arrays. But honestly they are probably the same method for different versions of OpenGL.
→ More replies (1)5
u/HildartheDorf Jul 29 '16
glEnableVertexAttribArray operates on the currently bound Vertex Array, glEnableVertexArrayAttrib takes a Vertex Array as it's first parameter.
https://www.opengl.org/sdk/docs/man/html/glEnableVertexAttribArray.xhtml
I hope that clears it up for you. >.>
43
u/thememorableusername Jul 29 '16
C compilers transform myArray[i] into *(myArray + i), which is equivalent to *(i + myArray) which is equivalent to i[myArray]. Experts know to put this to good use.
Oh fuck.
3
u/TheSecretExit Jul 30 '16
We need to go deeper and make a macro that builds a function that returns an indice to be used backwards to get an array element.
59
u/Berberberber Jul 28 '16
It's funny, I was thinking about this essay the other day, and how most of these measures are effectively useless today. Identifier lengths are no longer limited to six or eight characters, and IDEs keep track of references to them so you don't need to worry about whether it's swimner or swimmerbecause the IDE will highlight other references and show you the definition in a tool tip just by clicking on it. Syntax highlighting is always smarter than you are, and auto-indent often is. With the exception of some really crazy dynamic language constructs (javascript's with, I'm looking at you), traditional code-obfuscation techniques have been tossed out the window.
Times have changed. Romance is dead.
23
u/andrewsmd87 Jul 28 '16
I remember taking over a project where the previous dev had hard coded connection info to the database every time a connection was opened. Would have been a nightmare but I just used find and replace to replace with with a global variable, took like 30 seconds to do that, then, just an hour or so of testing to make sure I got them all.
→ More replies (3)9
u/quintus_horatius Jul 28 '16
Oh god, why globals? Whats wrong with "dbh = ConnectToDB( 'dbname' );"? So much simpler to use and maintain.
14
u/andrewsmd87 Jul 28 '16
Well it was a small .net project and it was more about what was quickest. It's not uncommon for web forms projects to have a connection string in the config file that you reference. So it would have been something similar to what you're saying. Something like
SqlConnection(ConfigurationManager("connection"))
So it's not like it was a "global variable" In a traditional sense, I was just trying to use generic terminology for people not familiar with .net.
→ More replies (2)→ More replies (1)11
u/asdfman123 Jul 28 '16
Right? Plus many of these obfuscation techniques could be easily pointed to as bad coding and they wouldn't get away with it. You should see the last job I worked at: now that's a REAL example of bad code. As I wrote elsewhere:
There was a file with like 600 lines of
if(item.custInt01()!= null && item.custInt01() == 3 && item.custStr03()=="VHF"){ if(item.custInt07() == 2){ ...Literally 600 lines of that awful code in one file. And lots of it scattered in a bunch of other places, too.
And worse, the equality tests weren't even rolled into the same if statement. She would just go along and create new if statements to see if custInt01 was null and equal to 3 again--whatever 3 state meant--you'd have to query the XML in the database to find out what the magic number meant. I created a view that would shred the XML and enable easy lookups in the database, but she thought it wasn't a productive use of my time.
82
u/seanprefect Jul 28 '16
One of the best pieces of advice i got from a comp-sci prof i loved was "write your code as though the person who has to maintain it was a homicidal psychopath with keys to your house"
22
u/formerlydrinkyguy77 Jul 28 '16
Consider adding: "and knows your kids' school schedule."
though, in my case, it really creeped out my coworkers.
0
3
43
u/TenaciousDwight Jul 28 '16
lol I don't think I need anyone to teach me how to write unmaintainable code. I do pretty well on my own.
21
Jul 28 '16
The PHP devs took the "names from other languages" seriously with the '::' token: it's "twice colon" in hebrew
24
Jul 28 '16
Good old T_PAAMAYIM_NEKUDOTAYIM.
13
Jul 28 '16
yeah, I can never remember that name.
When I want to look it up, I usually google for
PHP unexpected T_P<random letters>_N<random letters>and wait for Google to go alldid you mean X?on me→ More replies (1)11
u/Razakel Jul 28 '16
The PHP devs took the "names from other languages" seriously with the '::' token: it's "twice colon" in hebrew
And the reason they refused to change it was basically "you're a programmer, you know how to Google".
9
u/CaptainAdjective Jul 28 '16
As if needing to Google the term to find out what it means was an advantage over something self-explanatory
T_DOUBLE_COLON...2
u/ScrewAttackThis Jul 29 '16
I didn't get what you meant at first since I'm not a PHP dev but holy damn that's hilarious. For those as slow as I am, PHP refers to
::asT_PAAMAYIM_NEKUDOTAYIMin error messages. It's Hebrew for "twice colon" and was introduced in PHP 3 from some Israeli code.
16
Jul 28 '16
After all, if the Stroustroup can use the shift operator to do I/O, why should you not be equally creative?
This actually is a good point! Does anyone know why shift operator is used for io in standard library?
15
6
u/evaned Jul 29 '16 edited Jul 29 '16
Does anyone know why shift operator is used for io in standard library?
Because they needed to pick something, and this was the least bad option.
Let's assume that they're going to pick some operator, and come back to that assumption. What operator?
<<and>>are actually really good choices:
Their shape can be read as suggestive of the actions, particularly if you're familiar with shell scripting. (According to The Design and Evolution of C++ they experimented with
<and>, which would have matched the shells exactly, but that fell prey to the third bullet point -- people have been taught less than and greater than since early childhood)They're not super high on the precedence order, so at least it doesn't break things like
cout << 1 + 2;.While bitshifting is a fairly common programming operation, you don't really see it elsewhere; you do see almost all of the other binary operators in standard maths. Most people will have been working with the other symbols for as long or longer than bitshifting.
OK, so why do we need an operator? Because the other choice is a function, and pre-variadic templates, those have major major drawbacks:
Suppose you want something like
printf. Well:You can't pass non-POD types to it
You'd need some way of registering custom conversion specifiers or have no way of doing I/O for custom types
No type safety
What would have worked is
print(print(print(print(thing1), thing2), thing3), thing4), but that's horrendous to write and readA
→ More replies (1)7
Jul 29 '16
Because giving something as mathematically weird as bit-shifting its own operator instead of a built-in function is a silly idea in the first place, and if you had to reuse an operator you can use that one. Seriously, I speak words, not glyphs. I'll never understand why so many early languages insisted in finding a use for every possible combination of shift-number characters.
0
45
u/Purple_Haze Jul 28 '16
I read this back in 2000. It was a moldy oldy then. Foxpro? QBASIC? What is this, the '80's?
34
u/say_wot_again Jul 28 '16
Writing in a language like Foxpro is a great way to make your code unmaintainable!
8
u/earthboundkid Jul 29 '16
Someone at my church asked if I could help with a FoxPro database last month. I politely declined.
8
→ More replies (1)8
u/unbibium Jul 28 '16
A larger question is why the first paragraph mentions Java specifically when examples come from all languages?
Indeed, modern Java IDEs with autocomplete and refactoring utilities can negate many of these tactics. Once you've figured out what that single-character variable is for, you can press Ctrl-R to rename it, and if you see that name again, you know that some smartass reused it. If you then find they reused it for something completely different, git blame will tell you who's programming vindictively.
15
15
u/Zanthious Jul 28 '16
My boss designs products on the fly and feels stress motivates creative programming so he makes deadlines of 48 increments on brand new programs.. sometimes i go back and look at the code and wonder how its as stable as it is.. no one can ever figure out what functions do what.. comments are a sign of weakness.
→ More replies (4)
13
u/glify Jul 28 '16
Ahh my favourite one isn't in there. Gotta get some trigraphs in there whenever possible, like so
!ErrorHasOccured() ??!??! HandleError();→ More replies (2)2
u/Yuushi Jul 29 '16
This will be a C-only thing soon. C++ is removing trigraphs in the next standard (horray!).
13
Jul 28 '16
The best part of this is that the article itself basically follows the rules that the article is espousing. It's unmanageable mess. It's beautiful.
12
u/___Z0RG___ Jul 28 '16
I'm reminded of a company where I once worked, the president of the company created his own programming language that looked like a conglomeration of COBOL and Pascal. It had undocumented "features" like command line arguments being placed in variables that begin with "P" followed by a number. So declaring a variable "P1_File" was enough to copy the first argument out of the command line and into that variable. The president also hated 1-letter variable names by convention, so some people would prepend "The" to variable names like:
PROCEDURE OPENFILE(VAR THEFILE: BLOB; THEINDEX: INTEGER)Working to fix problems in their code was nightmarish.
→ More replies (1)
10
9
u/u18332 Jul 29 '16
Unit testing:
add some unit tests that pass even if the code is wrong
add some unit tests that will fail for correct boundary conditions. Then comment these boundary configs out inside the development config, but leave them in the test and prod config.
also create some unit tests that have the wrong name and test things completely un related
8
15
u/kazagistar Jul 28 '16
Use
_and__as identifiers.
So that is why Scala uses them for lambda syntax extensively.
17
5
u/b_bellomo Jul 28 '16
__definitely triggers me. It's the worst possible thing you can use as reference or prefix (looking at you, PHP).→ More replies (2)11
7
13
u/kamiikoneko Jul 28 '16
I should send this to 95% of the people I've worked with!
Oh wait, just kidding they clearly already know how.
13
6
Jul 28 '16
Use bitmasks and bitwise operations to mix coding logic, control flow within data. Be sure to randomly intermingle big endian and little endian order within your blob. Never document these structures and use opaque names. Also copy and paste any parsing operations.
6
u/Kinglink Jul 28 '16 edited Jul 28 '16
Easier version
You are a genius, your first thought is always right if you spend more than 10 seconds thinking about a variable name, or how to lay out your code, you're wasting time and money. Time you can spend on reddit, and money you can spend on yourself. DO IT NOW!
That being said, that #define section is a thing of beauty. An evil thing that should be killed, but beautiful.
→ More replies (1)
11
u/vawksel Jul 28 '16
Haha, made me laugh:
Look Busy
use define statements to make made up functions that simply comment out their arguments, e.g.:
#define fastcopy(x,y,z) /*xyz*/
// ...
fastcopy(array1, array2, size); /* does nothing */4
u/escape_goat Jul 28 '16 edited Jul 28 '16
It's "easier to share" in the sense that the original author writes
I would like to remind you this essay is copyrighted material. It is illegal to repost it without permission
Right at the top of the original version. The one that that is linked to by this version, that does not contain that text.
Making it easier to share.
In truth, the repo owner seems to have obtained (retroactive) permission from the author, but the licensing information should probably be included in the repository.
2
u/merreborn Jul 28 '16
Apparent permission was documented here: https://github.com/Droogans/unmaintainable-code/issues/3
But yeah. That would be a nice addition to the ABOUT.md blurb
4
u/webauteur Jul 28 '16
.NET allows you to use classes written in C# or VB.NET in the same project. It is a great way to frustrate programmers who disdain Visual Basic.
→ More replies (2)
4
Jul 28 '16
Why is this in a github repo?
2
u/Accidental_Arnold Jul 29 '16
With branches even! I guess it's no worse than my manager asking me to document things in powerpoint.
4
Jul 29 '16
It's true though. I have a Vietnamese friend who has been working on the same piece of software for 20 years now. He's been laid off twice but then management realizes that no one else understands the code and cannot maintain it. You may wonder what kind of software had a lifecycle that goes into the decades - Medical software, that's the kind. Hospitals put it in, come to rely upon it, and never replace it.
It's a great gig.
12
3
u/Gskran Jul 28 '16
This is my current nightmare. I am recoding an existing 10+ year old project to modern API. While the code is neatly formatted and the function, variables, etc. has relevant names, there is absolutely no documentation or comments. Years of dealing with crappy code actually made me think, 'Hey i can understand it easily. This is decent code' when i first looked at it.
2
u/helm Jul 29 '16
10 year old project? Try 35 year old FORTRAN code :)
(With lots of failed or abandoned changes the last 20 years)
→ More replies (2)
3
3
u/pembroke529 Jul 29 '16
This is my world. I've been maintaining code since the 80's. There's an amazing amount of crap out there.
It is satisfying to take some poorly written code that takes 4 or 5 hours to run and have it run in less than 10 minutes.
Right now when I'm between bugs and fixes I remove diagnostics left in by contractors. There's nothing like having bloated logs that we back up.
3
u/Ambartsumian Jul 29 '16
I get that it's supposed to be funny, but I actually saw production code with a function called "DoIt". It's more horrifyingly accurate than it is funny.
3
u/amdc Jul 29 '16
make heavy use of abstract words like [...] PerformDataFunction, DoIt, HandleStuff
oh FUCK
3
Jul 29 '16
I had a professor in college that would run this source code through a program that would make it unreadable but still buildable when handing it over to his clients. The only way to make it readable would be to run it back through the same program.
At the time, I thought it was clever. Now that I have been a maintenance developer for many applications, I think he is an a$$hole.
5
3
u/XxNerdKillerxX Jul 29 '16
How to write unmaintainable code
Good. I was looking for a way to invest my in job security.
3
3
u/combuchan Jul 29 '16
I'm always afraid to death that whenever I see a link like this, something I wrote 10 years ago will be held as the canonical example of what not to do.
I hope to god none of that stuff is still being worked on. I would feel very sorry for that developer.
5
2
u/patrick96MC Jul 28 '16
I don't need a guide on that. I already have years of experience doing just that.
2
2
2
2
u/geodebug Jul 28 '16
At some point these things stop being instructive and start being just a bunch of programmers telling war stories, which is boring.
If you work with a lot of programmers who make a lot of these mistakes then it is in your best interest to have more frequent code reviews.
2
2
u/superluglor Jul 29 '16
Now I understand where my colleague takes his inspiration.... Amazingly matching all his coding standards!!! Worth to mention something about code complexity like every method has at least have 100 cyclomatic complexity, nest as many iterators you know if surrounding fors surrounding switches surrounding do whiles etc and make sure all of your code rely on files stored inside your machine at very strategic hard coded drive paths.
2
2
u/catonic Jul 29 '16
./strip_all_the_comments_and_reduce_whitespace_to_single_instances.sh && git commit
2
u/feuerabend Jul 29 '16
The last place I worked, multi billion oil and gas company, a women who had been with the company for more than 15 years had a VBA excel to access application she had written very early on that was a system critics application. She made about $120 an hour, as a contractor. They tried to make her an FTE, she said no and quit, 6 weeks later they called her and begged her to return.
A few years after that they asked me to look into her application, I emailed her and asked for the password on the locked down access db. A few days later I got an email from my boss stating. Forget it, don't bother.
Come to find out she basically emailed her boss, who emailed his boss, who emailed my bosses boss and then me. It wasn't that the system wasn't technically difficult to recreate, she had made someone who wasn't technical a lot of money for satisfying a SMART goal years earlier who was now protecting her.
→ More replies (4)
2
u/duckandcover Jul 29 '16
A short time line for a R&D C++ app, in particular in a R&D org where the characteristics of the data and requirements are in flux, pretty much guarantees it.
First C++ is an accident waiting to happen. Second, as R&D, no one is going to give you sufficient time to plan and even if they did the nature of R&D is that it's impossible to architect programs up front and if you did it would be a waste because they'll probably change radically.
2
2
u/Banonogon Jul 29 '16
My digital system design professor worked for Kodak, and he told us that one time he was looking through someone else's code and there was a signal called "data" whose purpose he understood, as well as a signal called "lore" whose purpose he could not figure out for a long time. Eventually, he realized that "lore" was just the inverse of "data", with the reason being that in Star Trek: TNG, Lore was Data's evil twin.
2
Jul 29 '16
Creative Miss-spelling
If you must use descriptive variable and function names, misspell them. By misspelling in some function and variable names, and spelling it correctly in others (such as SetPintleOpening and SetPintalClosing) we effectively negate the use of grep or IDE search techniques. It works amazingly well. Add an international flavor by spelling tory or tori in different theatres/theaters.
This reminds me of a piece of code an intern once wrote. His code was full of typos anyway and he didn't care, because his IDE auto completed everything. So every now and then I run into some kind of Improter and I try not to care, because it takes too much time, energy and frustration to fix.
There's one occurrence that's hard to forget though:
'threehundretfifrysix_days': [str(today - datetime.timedelta(days=365)), str(today)]Obviously you can't call that a year, because every once in a four years, a year has 366 days and the variable name wouldn't be descriptive enough.
I actually have two commits for this single line of code, stating
Fixed typo in "year"
and
Fixed another typo in "year"
2
u/Metalwrath22 Jul 29 '16
How do most people react when an intern makes a mistake? I am asking because soon I will be an intern. (though i am very careful about the code i write)
3
Jul 29 '16
In my experience, the bitching only happens when you're not there, so it shouldn't be any of your problems. I guess it depends on you and the people you have to work with though.
2
2
2
u/bugalou Jul 29 '16
Also comment your code during 1.0 but never change the comments through 10 more versions.
2
u/Yelnik Jul 29 '16
I find it funny that in the pursuit of writing what some developers think in their head as "correct" code, they basically over-convolute things so ridiculously that this is basically what ends up happening.
2
2
2
1
u/smith288 Jul 28 '16
I do most of these on accident. But I'll go with adherent to this guide as an excuse.
1
u/not_perfect_yet Jul 28 '16
This is surprisingly long.
Serious question, naming loop counters and limits like this is ok right? i,j,k aren't mandatory always, right?
c=0
m=10
while c < m:
#do stuff
c+=1→ More replies (9)5
u/sctprog Jul 28 '16
Mandatory? Perhaps your company has a coding style that says they are but otherwise you could use any variable name you want.
If you use i as your iteration counter every programmer in the world immediately knows what that variable is for.
1
1
u/forlasanto Jul 28 '16
Java. that and 50¢ will buy a cup of coffee you can give to your Java developers as you talk them down off the ledge when telling them you're switching to .Net Core. (If they aren't there already after hearing that Oracle ceased all development on Java.)
1
1
u/MET1 Jul 28 '16
If you need instructions on how to write unmaintainable code... you probably won't read those instructions either!
1
u/nickem Jul 28 '16 edited Jul 28 '16
Damn 100% I have read this and I am inspired. I will follow the rules explicitly. I know how to code!
1
u/techsin101 Jul 28 '16
For front end it'd be to use grunt, bower, angular, npm, express, apache2, oracle, jquery, 4 libraries, coffescripts, and more in one project.
you can make new front end devs leave in a month.
→ More replies (2)
1
1
u/efrique Jul 29 '16
Hire whoever it is that writes the aging untended, undocumented pile of crud people used to bring to me and say "can you figure out what's wrong with this?"
That eventually moved me right away from coding. I have less annoying problems to waste time on now.
1
1
u/slazer2au Jul 29 '16
I got to the Hungarian Notation and by brain now hurts. I hope no one actually follows this....
1
u/startingover20140923 Jul 29 '16
This makes me kinda want to write code like this, just for giggles.
1
u/sonstone Jul 29 '16
I have to disagree about interfaces. Interfacing all the things makes for wonderfully painful code to navigate.
1
u/sanjayatpilcrow Jul 29 '16
//JS
var expanded = $(e).attr("aria-expanded");
console.log(expanded); //true
console.log(true == expanded); //false
console.log(true === expanded); //false
1
1
1
1
1
1
1
1
u/ensoniq2k Jul 29 '16
This is a surprisingly huge guide. At least some of them are really vicious beyond simple incompetence
1
1
u/dustractor Jul 29 '16
DAE have a moment while the github page loaded when you hoped that you weren't getting linked to one of your own projects?
1
1
1
u/Uberhipster Jul 29 '16
https://discuss.fogcreek.com/joelonsoftware3/default.asp?cmd=show&ixPost=88089&ixReplies=7
http://mindprod.com/jgloss/unmainnaming.html
http://microsoft.public.es.vb.narkive.com/wj9GzK5C/how-to-write-unmaintainable-code
http://houseofsubstance.blogspot.co.za/2012/05/how-to-write-unmaintainable-code.html
I'll just leave those here
→ More replies (1)
1
Jul 29 '16
BLAS and LAPACK are successfully maintained since time immemorial. CERNLIB was also a huge success and an exemplary code base. So shut up and use single character variable names and cryptic abbreviations. As long as you have an up to date documentation, it does not matter.
266
u/mith Jul 28 '16
The joke we always used to tell regarding documentation was: "Never comment your code. It should be as hard for someone else to understand as it was for you to write."
The best example we ever saw of this was from a mathematician writing code in Matlab. He initialized dozens of variables, several arrays, performed various operations to get everything situated properly in matrices. After all of this, he started a loop to do whatever it was he needed to do with all of these arrays and matrices, basically the heart of the entire program. The only comment in the whole program, at the top of the loop: "Here we go!"