4 ms·
How To Write Unmaintainable Code
- bcRIPster 13y agofrom page... zOMG this is evil! CODE THAT MASQUERADES AS COMMENTS AND VICE VERSA Include sections of code that is commented out but at first glance does not appear to be. for ( j=0; j < array_len; j +=8 ) { total += array[j+0]; total += array[j+1]; total += array[j+2]; /* Main body of total += array[j+3]; * loop is unrolled total += array[j+4]; * for greater speed. total += array[j+5]; */ total += array[j+6]; total += array[j+7]; } Without careful attention , would you notice that three lines of code are commented out?
- EpicEng 13y agoI would, unless perhaps I were reading it in notepad. Thank god for syntax highlighting.
- TrainedMonkey 13y agoOr you could just use virtually any IDE with comment highlighting. Quite a few of patterns mentioned are either mitigated or defeated by good IDE.
- zalew 13y agoif by IDE you mean an editor, you don't need an IDE to have syntax highlighting.
- pubby 13y agoTrigraphs make it more evil: // will the next line be compiled??/ no it won't!
- danudey 13y agoEven better: make the non-executed line of code break things in subtle ways if compiled without -trigraphs.
- prawks 13y agoI did, but only because I said to myself "Who in the hell writes a block comment there? Can you even do tha- Oh." Not sure if that counts as careful attention, but it's usually clear something could be wrong when someone writes something in a very odd way.
- deleted 13y ago[deleted]
- lkrubner 13y agoI like this one: Object oriented programming is a godsend for writing unmaintainable code. If you have a class with 10 properties (member/method) in it, consider a base class with only one property and subclassing it 9 levels deep so that each descendant adds one property. By the time you get to the last descendant class, you'll have all 10 properties. If possible, put each class declaration in a separate file. This has the added effect of bloating your INCLUDE or USES statements, and forces the maintainer to open that many more files in his or her editor. Make sure you create at least one instance of each subclass.
- interstitial 13y agoThey must of got that idea from Magento.
- RyanZAG 13y agoUnderscore, a Friend Indeed Use _var and __var in identifiers. Even better when it's sometimes __ and sometimes ___ - you can never tell which it is at a glance. (Python is great for this one!)
- interstitial 13y agoI'm going to copy and paste this into any empty or default text README.md's I find in projects I'm assigned to work on. Perhaps Github should also post it as the default README.md for any new project.
- acheron 13y agoA classic. My favorite is "Properly-written code never fails, so exceptions are actually unnecessary."
- strictfp 13y agoA new one, somewhat related to exceptions: "If you don't know what to do, just return null and pretend like nothing happened! This way you can put all the blame on the caller. Your code effectively becomes flawless!"
- AsymetricCom 13y agoThese are all great suggestions, because it's very often (always) that management assumes they know what your software does given the output.
- wrongc0ntinent 13y agoThis should be translated in a few languages I can think of.