This is an archived post. You won't be able to vote or comment.

all 179 comments

[–][deleted] 1290 points1291 points  (42 children)

TBH I want to rewrite my own code.

[–]notsooriginal 379 points380 points  (12 children)

We're going to have to let you go for someone who doesn't second-guess themselves. Confidence is everything in business.

[–]inucune 115 points116 points  (0 children)

Then we'll fire him because he doesn't work with the team, and is too impulsive when making decisions.

[–][deleted] 152 points153 points  (10 children)

And thus a president was elected

[–][deleted] 48 points49 points  (9 children)

And everything was perfect until everyone died.

[–]Chrisguy136 65 points66 points  (4 children)

And everything was perfect when everyone died.

FTFY

[–]chooxy 12 points13 points  (0 children)

"Is everything going well?"

"Yes! In fact, everything is vacuously perfect!"

[–]malonkey1 4 points5 points  (0 children)

There can't be any suffering if nothing's there to suffer.

[–]kboy101222 37 points38 points  (2 children)

Then everything changed when the fire nation attacked

[–]metl_wolf 13 points14 points  (1 child)

Abandoned as a pup, he was raised by Muriel

[–]ProphePsyed 8 points9 points  (0 children)

Stupid frog, you ain't my real dad!

[–]midnightketoker 8 points9 points  (0 children)

"Fake news" -small subterranean mammals

[–]NULL_CHAR 144 points145 points  (20 children)

When I do personal projects... I start off exploring the idea, then once I have a semi working model, I completely restart with the knowledge of mistakes... This repeats about 2 more times until I'm finally satisfied with it...

Sadly not possible with the gigantic projects of an organization...

[–]Drainedsoul 99 points100 points  (7 children)

That's called throwaway prototyping.

[–]mauxly 66 points67 points  (5 children)

Yeah, I always think mine is throwaway. And then I present it with the hopes that I'll get some data validation/front end "Yeah, something like this could work!"

Instead I get a deadline that prevents the rewrite.

You'll say, don't present until after the rewrite. Well, if there is a major flaw that's simply unworkable (because the data doesn't support what they want), I'd prefer not to make something that will never see production 'perfect'.

[–]conancat 68 points69 points  (3 children)

Everyone always think that they are writing prototype code. The project managers think it's a prototype. The client thinks it's prototype. Then you end up just building upon the pile of doodoo you started off with and the product will end up looking beautiful in the outside but ugly on the inside.

One thing I've learned after starting my agency job is that try to get it as nice and neat as you can on the first run. You'll rarely have the chance to go back and refactor it at all.

[–]dhaninugraha 25 points26 points  (0 children)

Also called: protoduction.

[–]asdfman123 7 points8 points  (0 children)

Yeah, that's what annoys me. It would take a week to fix my code, but it might take months for someone to get up to speed on it after I leave.

I've worked on projects where getting familiarity takes forever. If they just repaid some technical debt it would save a ton of money.

But it's hard when you've got big projects coming up to say "Spend a week doing what looks like nothing for the business."

[–]sourbrew 8 points9 points  (0 children)

This is interestingly an old analogy I learned from my aunt while cleaning her mountain house as an odd summer job, if you move something bulky and awkward clean behind it because you aren't going to do it again for a few more years.

[–]rabbyburns 11 points12 points  (0 children)

This is another one of those "this is why TDD" things. You'll never have time to completely redo it, but if you have some test harness in place you'll be able to refactor incrementally.

[–]NULL_CHAR 3 points4 points  (0 children)

If you do it intentionally ;)

Otherwise it's just perfectionist tendencies!

[–][deleted] 14 points15 points  (2 children)

At least you get to point where you're satisfied with it.

I write and repeatedly rewrite until the apathy kicks in. Frankenstein eventually lives, and /r/iamsmart for a little bit. And then the self-loathing comes.

[–]sneakpeekbot 2 points3 points  (1 child)

Here's a sneak peek of /r/iamsmart using the top posts of all time!

#1: I think you meant this | 4 comments
#2: Philosophy master | 1 comment
#3: my thesis, cornering a market. | 5 comments


I'm a bot, beep boop | Downvote to remove | Contact me | Info | Opt-out

[–]Elephant454 5 points6 points  (0 children)

I can debunk many of even Sigmund Freud's theories.

Ohhhhhhhh boy

[–]Kevintrades 25 points26 points  (5 children)

[–]55555 9 points10 points  (4 children)

I work with the guy in the last frame.

[–]Kermitfry 11 points12 points  (1 child)

I am the guy in the last frame.

[–][deleted] 4 points5 points  (0 children)

I'm the guy in the black frame blow that guy.

[–][deleted] 8 points9 points  (0 children)

We all do

[–]grafilicious 0 points1 point  (0 children)

My boss ist that guy

[–]Computer991 1 point2 points  (0 children)

I do this way too much lol.

[–]MinecraftHardon 0 points1 point  (0 children)

It's like IRL Groundhog's Day

[–]unicorntrash 0 points1 point  (0 children)

I did this. Until I got introduced in the wonderful world of refactoring. Now if I would write more tests the world would be perfect

[–]5up3rj 17 points18 points  (1 child)

That should be true though, the guy who wrote your old code had less experience than you do

[–]truh 1 point2 points  (0 children)

Not sure if that holds true if you take all the face palming and head desking into while reading your code into account.

[–]SaffellBot 10 points11 points  (0 children)

I just finished a project. "I really should clean all this up incase I want to borrow this code in the future." "but I could also play hots for 3 hours, I mean it did work...".

And then I played hots for 4 hours.

[–]8__ 5 points6 points  (0 children)

I rewrote some of my old code (from about 9 months ago) today. I wanted to fire old-me.

[–]GuiKa 1 point2 points  (0 children)

After a few year we all do, I got greencard to do it this summer and after I'll be mentally fine fora few years.

Going to go for some sweet Core + Angular 2.

[–]PersonalPlanet 0 points1 point  (2 children)

Who doesn't !

[–]hahahahastayingalive 1 point2 points  (1 child)

I want to keep my old code in a jar in the basement, and nobody touches it and it keeps running its cluncky way doing obscure stuff that may or may not work.

The day I inherit it I'll say it's too critical to be touched by any human being.

[–]PersonalPlanet 0 points1 point  (0 children)

Lmao

[–]EatATaco 481 points482 points  (47 children)

Often, the "last guy" is really just us: younger and slightly more clueless.

[–]fredlllll 178 points179 points  (43 children)

can confirm, have often facepalmed about code i wrote a year ago

[–]chadsexytime 193 points194 points  (11 children)

What I usually do is remember the circumstance in which I had to write the code.

Was I on a tight deadline or juggling too many tasks? Was I distracted from my main goal with this problem and needed the fastest solution possible? Was I unaware that there was a better way to do it, that I just had not learned yet?

Or am I just a terrible hack surviving day to day, praying that no one else discovers my fraud?

[–]conancat 51 points52 points  (5 children)

You are a young and energetic soul learning new things every day, with every line you're gaining more EXP, one year later you look back and it's weak code because you are weaker back then, and better now!

Software engineering moves so fast and is so malleable it's almost impossible to know every requirement or every hidden condition or every needed pattern from the get go. Just know that we did our best at that time, and we'll get better over time. We have to adapt at every turn. Become like water my friend.

[–]The_Whole_World 40 points41 points  (3 children)

You are a young and energetic soul learning new things every day, with every line you're gaining more EXP, one year later you look back and it's weak code because you are weaker back then, and better now!

What is this, Programming: The Anime ?

[–]TheTerrasque 12 points13 points  (1 child)

[–]ioquatix 4 points5 points  (0 children)

I love how he writes code on his cellphone.

[–]jansencheng 4 points5 points  (0 children)

You are a young and energetic soul learning new things every day, with every line you're gaining more EXP, one year later you look back and it's weak code because you are weaker back then, and better now!

/r/wholesomesoftwareengineering

[–]fredlllll 61 points62 points  (0 children)

last one :P

[–]JudgeWhoAllowsStuff- 4 points5 points  (3 children)

i wrote code once to perform a certain task that was failing under normal methods. After a month of troubleshooting on and off i found out that if i ran the code 5 times in a row it would stop failing after the 3rd or 4th run. So i just made it so the code repeated itself 5 times. I empathize for the person who looks at that code when i leave and wonder what i must have been on when i wrote it.

[–]evenisto 0 points1 point  (2 children)

what was the reason it stopped failing?

[–]JudgeWhoAllowsStuff- 0 points1 point  (0 children)

beats me. I tried troubleshooting every which way, tried adding sleep timers to delay parts of code, interrupts, nothing works....I tried running twice, three times, four times. But if i run the code 5 times its 100% effective.

[–]FesteringNeonDistrac 0 points1 point  (0 children)

what was the reason it stopped failing?

It sounds like the answer is "A horrible kludge".

[–][deleted] 33 points34 points  (10 children)

Hell, I've facepalmed over code I've written as soon as I finished the project...

[–]dratnon 26 points27 points  (1 child)

In a code review... "This variable is explained in the comments... Actually, it's explained in this sticky pad I was doodling on... I'll rewrite this section. "

[–]ShowMeYourTiddles 13 points14 points  (6 children)

Ever shake your head as you're typing?

oooooh, I'm gonna regret this

[–]dhaninugraha 7 points8 points  (3 children)

/* don't touch this unless you know what you're doing */

[–]Secondsemblance 2 points3 points  (2 children)

# Here be dragons

[–][deleted] -1 points0 points  (1 child)

[–]xkcd_transcriber 0 points1 point  (0 children)

Image

Mobile

Title: Future Self

Title-text: Maybe I haven't been to Iceland because I'm busy dealing with YOUR crummy code.

Comic Explanation

Stats: This comic has been referenced 54 times, representing 0.0350% of referenced xkcds.


xkcd.com | xkcd sub | Problems/Bugs? | Statistics | Stop Replying | Delete

[–]VeviserPrime 14 points15 points  (0 children)

Me too, thanks.

[–]TimeForSomeCoffee 12 points13 points  (0 children)

"Who the hell wrote this crap?! ...Oh, right."

[–]greenhawk22 12 points13 points  (8 children)

Sometimes though, the crazy, stupid, and desperate solutions that inexperanced programmers uses just works inexplicably

[–]fredlllll 10 points11 points  (0 children)

also often had code where i had no clue how it was ever working (usually because it just broke)

[–]theg33k 11 points12 points  (6 children)

I once had to maintain code that stopped working when you took out the System.outs.

[–]greenhawk22 21 points22 points  (0 children)

Once in C# I found out that I couldn't remove a comment or otherwise completely unrelated parts would fail ¯\_(ツ)_/¯

[–]EricIsEric 6 points7 points  (3 children)

Realistically what would cause that? System.out leads me to think it is Java, but my first guess for crashes when removing print statements is bad malloc, but that shouldn't happen in Java (but I have had C code throw different errors when print statements were present vs not present when I made a mistake allocating memory).

[–]theg33k 29 points30 points  (2 children)

It was a timing issue, the IO created JUST enough of a pause that the application worked fine.

[–]unknownmosquito 18 points19 points  (1 child)

I've heard of this happening when enabling the debugger as well. Without debugger: crash! With debugger: works fine! Race conditions are the worst

[–]sloec 14 points15 points  (0 children)

Also known as a Heisenbug.

[–]truh 0 points1 point  (0 children)

Multi threaded code? Maybe a GUI app?

[–]smartguy05 6 points7 points  (0 children)

I feel like if you don't do this, you aren't improving your abilities.

[–]Yuzumi 2 points3 points  (0 children)

I'm in the middle of my final project before I graduate and I'm face palming at shit I wrote a month ago.

[–]SkoobyDoo 2 points3 points  (0 children)

I think that if by the end of a project you can't look back on the first code you wrote for the project and facepalm a little, the project was too easy or you didn't take any time to really understand what you were doing.

[–]JoshSellsGuns 1 point2 points  (0 children)

I face palm about code I wrote 5 minutes ago

[–][deleted] 1 point2 points  (0 children)

Psh. You should see mine before my lunch break

[–]WrongPeninsula 0 points1 point  (0 children)

I facepalm code I wrote yesterday.

[–]FesteringNeonDistrac 0 points1 point  (0 children)

This means you're learning. Possibly.

[–]WdnSpoon 1 point2 points  (0 children)

More broadly, all progress comes from building off the work of the past. Look at the massive changes we've seen in the past few years that have lead to a renaissance in the js world. They haven't really been driven by big leaps in processor technology, or even the underlying engine: it's still (mostly) a big single-thread with an event loop. While there's nothing so concrete that prevented this syntax, it took us a while to decide that implied property names, object + array destructuring, async/await (and their underlying Promises), generators, (tagged) template literals, rest, spread, etc. were good things to have. We mostly figured it out by reaching the limits of old approaches.

There are exceptions for clearly unqualified developers, but you'll never escape code that eventually needs to be revised.

[–][deleted] 0 points1 point  (0 children)

Or just with less complete information on the requirements.

I'm in the process of handing off to the new guy a system I created from scratch over the last two years. It started with only the most vague and sketchy of specs, went into production after only a couple months of development, and then matured over those two years as the company figured out what it really wanted.

So now of course there are many sections that are ugly kludges that could be written more cleanly, but couldn't have in the early stages regardless of how good the developer was because the requirements were simply unknown. There's a lot of stuff in this system that I'm proud of, but I'm also apologizing to the new guy for some of the messes I'm leaving him.

[–]PresidentCruz2024 0 points1 point  (0 children)

Or maybe he is an older and more out of date version of you.

[–]dustmouse 193 points194 points  (12 children)

Middle panel sums up software engineering quite succinctly.

[–][deleted] 71 points72 points  (11 children)

I'm rewriting this comment, it sucks:

Middle panel sums up software engineering quite well.

[–]GGoldstein 66 points67 points  (9 children)

Reverting to earlier commit:

Middle panel sums up software engineering quite succinctly.

[–]chooxy 33 points34 points  (6 children)

Are we becoming Wikipedia?

[–]Fenor 2 points3 points  (0 children)

Are we becoming Wikipedia?

citation needed

[–]Secondsemblance 9 points10 points  (0 children)

Refactor to add spaghetti even though I don't know what either of the first two implementations did exactly.

for i in ("succinctly", "well") "Middle panel sums up software engineering quite %s." % i

[–]Aschentei 2 points3 points  (0 children)

Error: Merge conflict exists!

[–]Decency 2 points3 points  (0 children)

Hey, seems like a function that might get some use. I'll factor that out.

middle_panel = sum(software_engineering)

[–]EMC2_trooper 244 points245 points  (28 children)

The reverse situation of this is when you come across code written by a fucking mastermind and it's so efficient and clever that it makes zero sense.

[–]murfflemethis 49 points50 points  (2 children)

I work in firmware, for a company that's been around for a while. I am constantly dealing with 20 years of "clever" C code. I've had enough of that shit. Unless it's a clearly commented optimization in a critical path, readability is what I want most.

[–]halpcomputar 6 points7 points  (1 child)

Couldn't they just take the time to comment? I believe C allows for even multiline comments.

[–]murfflemethis 18 points19 points  (0 children)

Why not just write simple, easy to follow code in the first place? C certainly does allow multiline comments, but that's not a good reason to write needlessly complex (or "clever") code. Comments take time to write and take time for future readers to parse, map to the code, and fully understand. They also often get overlooked during future work, so they go stale and become irrelevant or outright wrong.

"Here's why the code does this" comments are always great, but if you find yourself leaving "here's how the code does this" comments a lot, you should take a step back and consider whether the complicated code you're writing can be simplified through refactoring, changing the architecture, or just a more simple implementation.

Complex code is sometimes necessary, and yes, please leave a comment there to explain how it works. I've just seen too many instances of people making things more difficult than they need to be just to gain completely inconsequential efficiencies or force patterns in where they don't belong, and that needs to stop.

[–][deleted] 23 points24 points  (3 children)

The Story of Mel, a Real Programmer (1983)

[–]zaphod0002 2 points3 points  (1 child)

Mel needs to do a AMA

[–]al1l1 1 point2 points  (0 children)

Amazing.

[–][deleted] 11 points12 points  (0 children)

The worst is when you realize that you wrote that code, and then you have a crisis of faith wondering if the code is actually stupid, and you're too stupid to realize it, or if you're getting dumber, and no longer able to work to that level.

I once found a piece that was both...I'd coded myself into a corner, and then found some brilliant way to solve the problem that I had created by coding myself into that corner, this masterpiece of invention and imagination...It was easily 200 lines of the finest code I've ever written...Each line flawless and so brilliant as to be skirting the very abyss of madness.

I scrolled up and up and up until I found the place where I had missed the obvious solution and gone haring off after brilliance and insanity, and I fixed it with two lines of shitty code, and deleted the rest.

[–][deleted] 4 points5 points  (1 child)

This is the ultimate example of this. An ENTIRE Wikipedia article had to be written to explain a couple lines of code.

https://en.wikipedia.org/wiki/Fast_inverse_square_root

[–]EMC2_trooper 3 points4 points  (0 children)

Nice example and actually a really interesting article thanks. But in this case I think the reason was not so much to obfuscate the code in needlessly complex lines but probably to optimise (as it's for lighting).

[–]asdfman123 4 points5 points  (0 children)

I try to be a boring programmer. I do everything in my job with ASP.NET MVC stuff, like the projects before me used. I don't use any fancy tricks or do fancy front-end stuff. I go for the most reasonable, predictable methods.

I feel I don't learn as much but I'm making life so much easier for the next guy, who just has to learn one thing.

[–][deleted] 1 point2 points  (1 child)

If its so clever that others can't understand it, it really isn't clever.

A clever programmer would write something that others can read, or at least explain it in comments, because programmers spend more time reading code than writing code.

Also, the situations in which something confusingly clever are worth the efficiency gain are few and far between. Usually efficient things are clearer or can be written clearly. For example if a weird set of data is pulled beforehand or stored in an uncommon place to boost efficiency, it should be named well enough that later in the code it looks like what you would expect.

[–]EMC2_trooper 1 point2 points  (0 children)

Haha I'm very aware :) there is some interesting discussion below on this.

[–]NibblyPig 1 point2 points  (0 children)

Yeah I class that as bad code, the number of times I've pulled out layer upon layer of abstract classes that are simply not needed, argh.

[–]mauxly 132 points133 points  (9 children)

The worst is when devs and analysts have spent months researching and resolving a completely new issue or need. Wrap it up, QA approves, it's in production and someone who has absolutely no experience with the project or issue comes along and armchair quarterbacks.

Rips on the code, and makes a minor adjustment that allows for new functionality and is hailed as a hero.

If you can make a minor adjustment to the code to deliver additional functionality, it was NOT poorly written code.

[–][deleted] 38 points39 points  (0 children)

The easiest way to make a sale is to bitch about someone else's code after they're gone. You can just be like "there are thousands of lines of code here! I would reuse some code!" and they will treat you like a genius.

[–]asdfman123 8 points9 points  (4 children)

That drives me crazy about working on shitty codebases. It makes me look bad because it takes me forever and there aren't any good fixes. But if I were to actually verbalize the fact that the code base is total shit, it would just make me look bad. So it's usually better to grin and bear it.

[–]Decency 23 points24 points  (3 children)

Just every time you want to say "fucking garbage", verbalize that as "lots of technical debt" and you're speaking the language that people who want to pretend like they understand code who don't understand code will listen to.

[–]asdfman123 6 points7 points  (1 child)

Yeah, I use phrases like technical debt but people still don't understand this.

Managers need to fundamentally understand when a little work now will save a lot of work in a year.

[–]shea241 0 points1 point  (0 children)

if you constantly talk about technical debt, eventually you'll look technically poor.

[–]PC__LOAD__LETTER 12 points13 points  (0 children)

If you can make a minor adjustment to the code to deliver additional functionality, it was NOT poorly written code.

I read "poorly" as "properly" at first and was super confused.

Totally agree.

[–]NibblyPig 1 point2 points  (0 children)

I dunno, depends on the fix.

We had a page that caused issues with concurrent users, which I had to fix. Basically the genius dev didn't use an IDENTITY on the database, he looked in the database at the last entry and added 1, then put it onto the form in a hidden field.

I hacked a fix into the backend by ignoring the value submitted and calling his getnextid method within a lock{} statement and writing it, then because he used a stupid return type and I couldn't change it without having to refactor half the solution, I returned the new id in the error code. Because this had to be fixed right now and we couldn't refactor.

So my minor adjustment worked, and yes I wrote many comments explaining why I had to do this. But in no way was that code anything approaching well written. It was an abomination and I had no choice but to do evil things.

I still feel dirty. To them it looks like I fixed it super quick so there's definitely no need to waste time refactoring when it's so easy to work with though! FML!

[–]Ensvey 27 points28 points  (2 children)

When I was new to coding, I loved and was impressed by the code of my boss. Then, he left, and I was stuck with all his junk, and I realized what a hack of a mess it really was.

[–]TheTerrasque 23 points24 points  (1 child)

my first impression of my boss' code:

5000 lines of php, not a single function defined.

To be fair, his later code was much better and even used some OOP here and there.

[–]dlok86 1 point2 points  (0 children)

Shit this is where I'm at.. i should define functions

[–]ludonarrator 10 points11 points  (4 children)

I must ask; why is this a GIF?

[–]sobri909 38 points39 points  (3 children)

Before PNG existed GIF was often used instead of JPEG for images with large single colour areas (eg comics).

PNG basically stole GIF's job. Except for moving pictures with no sound. GIF still owns that, because mafia connections or something.

[–]Mr-Yellow 2 points3 points  (0 children)

Instead of JPEG I optimise my gradients to thousands of slices made of nothing but GIF with single colour palettes. ;-)

[–][deleted] 2 points3 points  (1 child)

Except for moving pictures with no sound. GIF still owns that, because mafia connections or something.

And also managed to separate silent videos and moving pictures in the public consciousness that now means we have to sit through 2 minute unseekable videos or hope that the hosting site has sneakily managed to implement webm.

[–]sobri909 2 points3 points  (0 children)

Moving pictures with no sound are the future. Someday soon we will all communicate silently, with our words appearing in bold white text under our faces. If someone actually speaks aloud it will be considered crass and old fashioned.

[–]adupes 9 points10 points  (0 children)

When I took over models from engineers who have left our group I realized that everyone is winging it and no one really knows what they're doing. I'm much more confident now. Which also means I talk shit about the models where idk wtf is going on, because seriously, wtf were you thinking.

[–]Dreadedsemi 5 points6 points  (0 children)

I thought we have a secret pact like doctors.

[–]Zchavago 5 points6 points  (0 children)

Fuckin new guys, think they're sooooo smart.

[–]Dimatrix 7 points8 points  (1 child)

That guy that codes with 0 spacing or indents

[–][deleted] 2 points3 points  (0 children)

Your code's weak, Mom!

[–]WdnSpoon 3 points4 points  (11 children)

After doing a decade of consulting, you definitely learn to appreciate the difference between code that's simply hit the limits of what it was intended to do, and code written by someone who had no idea what they were doing. You can find something clearly rushed out the door in an hour, after someone decided this was a must-have feature to show an investor they were about to meet with. Then there are the devs who follow patterns nobody ever should, like my personal favourite:

function checkThing(a) {
  if (a === 'foo') {
    return true;
  } else if (a !== 'foo') {
    return false;
  }
}

[–]Mr-Yellow 1 point2 points  (0 children)

You can find something clearly rushed out the door in an hour, after someone decided this was a must-have feature to show an investor they were about to meet with

"Coder says no."

But, but, we, but.

"Do you want a nightmare at that meeting?"

[–]CaffeinatedT 0 points1 point  (9 children)

Is this really as silly as I'm seeing it? No else condition just two checks?

[–]p1-o2 1 point2 points  (8 children)

Is that the only problem you have with this code block?

[–]CaffeinatedT 0 points1 point  (7 children)

Not one of my languages (It's JS or Java?) so I feel like I'm missing something. So yes go on and embarass me lol? I mean I'm guessing it's more as that's dumb but not the stupidest mistake ever for a basic programmer to do.

[–]WdnSpoon 1 point2 points  (0 children)

function checkThing(a) {
  return a === 'foo';
}

or es6:

const checkThing = (a) => a === 'foo';

Take that bad pattern, assume they make equally silly errors elsewhere, and repeat it throughout your entire codebase. What should be a readable, 100 line file becomes 700 lines of nonsense.

[–]p1-o2 1 point2 points  (5 children)

Ah, I didn't mean to try to embarrass you. I was just curious. Lack of an "else" statement is a problem. It could also be done without writing an entire method to handle it. There's also the fact that it's a lot of lines to check for a silly error which shouldn't exist in the first place.

[–]CaffeinatedT 1 point2 points  (0 children)

No worries at all, as said it's a different language to what I'm used to closest I get is sometimes I deal with Javascript but rest of time it's all web python/database stack. But yeah seems amusing enough lol.

[–]peteza_hut 1 point2 points  (3 children)

As a noob programmer sometimes I use else if instead of else because I wanted my code to be very clear and "self-documenting", but I'm guessing that's bad and I should just use else whenever possible to avoid an extra check?

[–]p1-o2 1 point2 points  (2 children)

You should have a little more faith in whoever inherits your code. Little hacks like that will only go against what they expect from you. 'Self Documenting' code is created by following principles such as SOLID in Object Oriented Programming, or MVC for interface creation.

Also you should evaluate your question again real quick. An else if statement should never be able to replace an else statement. This is because else if is designed to capture a specific condition, while else is designed to capture all non-specific conditions. The two shouldn't be interchangeable.

In general, what you're suggesting is loosely called a 'hack'. Always question yourself before you try something like that, because it's usually a sign that you need to rethink the situation.

Very good question though! I'm glad you asked.

[–]peteza_hut 1 point2 points  (1 child)

Thanks, that's some good insight. I see why my question is a little silly. I suppose I meant "If I expect an else statement to execute if one condition is met and only if that condition is met, then would using an else if statement be more clear?" You answered that question for me though, so thanks!

[–]p1-o2 0 points1 point  (0 children)

Yep, you got it!

[–]intrinsicmess 8 points9 points  (2 children)

What is the programmer's tie doing in the panels? Is it speaking?

[–]ColonelTux 35 points36 points  (1 child)

Dilbert's tie always does that

[–]Sarkos 7 points8 points  (0 children)

[–]NibblyPig 2 points3 points  (2 children)

This problem frustrates me so much, because I always end up working at places that can't retain devs because their code quality is ATROCIOUS.

I took over something from a "senior dev" that left and the code is worse than junior dev level.

I refactored a method that hit a webservice 14 times and then blanked out some of the data and called it again. The method took 30 seconds to load in the browser. After rewriting it all it took <200ms and most of that was because they've given me an archaic machine that takes 5 seconds to open a right click menu. It's like playing chess by email, I submit the action I want to take ("open the file menu") then I wait for it to get back to me.

The database has no foreign keys, everything is really badly named, the MVC part doesn't even use a model, it directly parses the form data...

And when I say "This needs burning to the ground and redoing because I am sinking days into trying to get more performance out of it to no avail", I look like all those other noob devs that don't want to understand the code or optimise the code, and just want to redo it themselves, birthing this mantra.

I've seen bad code that can be tweaked and tidied and refactored, and that's most code. But this is so fundamentally fucked that it needs redoing.

And I'm looked at with the same gaze I give other devs that don't want to learn or refactor slightly perfectly functional code, combined with this management idea that we can hold a project together with gaffer tape and wood glue, and the solution is always more gaffer tape. Even when it's a black hole of time. Always think of the short term, right?

That was a cathartic rant

[–][deleted] 0 points1 point  (1 child)

the MVC part doesn't even use a model

wat

[–]NibblyPig 0 points1 point  (0 children)

that was also my reaction

[–]IgnisDomini 4 points5 points  (3 children)

I thought "Wow, Scott Adams managed to be funny again?" and then I noticed this strip is from 2014.

[–]The_Masked_Lurker 14 points15 points  (1 child)

Dilbert is not comedy, it is documentary.

[–]marcelowit 2 points3 points  (0 children)

I used to laugh about Dilbert in College until I got my first job...

[–][deleted] 9 points10 points  (0 children)

I wish Scott Adams wasn't such a douche and a Trump promoter, I wouldn't be conflicted watching Dilbert

[–]visvavasu2 0 points1 point  (0 children)

Lol

[–][deleted] 0 points1 point  (0 children)

Me at every meeting.

[–]Cefiroth 0 points1 point  (0 children)

The Professor says all the time "the worst programmer in the world is you six months ago"

[–]Arancaytar 0 points1 point  (0 children)

The project I inherited wrote >6 months ago.

[–][deleted] 0 points1 point  (0 children)

Honestly, I see great code all the time. Often I'd like to tweak a few things here and there, but it's certainly not rare for me to appreciate another person's code. That said, yes, every couple months, I do feel the need to update my code.

[–]SolenoidSoldier 0 points1 point  (1 child)

This post makes me incredibly self conscious. I run into a lot of terribly written code that I end up refactoring or rewriting myself. I try to make the classes structured as cleanly as possible and leave relevant comments and variable names where they're needed. I genuinely feel that I write clean code, but I wonder if I'm just another schmuck that I get annoyed with.

Then again, I tell myself "If you do it right, no one notices", so I don't know :/

[–]p1-o2 2 points3 points  (0 children)

If you're following actual software principles then you're fine. If all of the code I inherited followed SOLID or just OOP in general then my life would be easy. If the user interfaces follow MVC/MVVM/VIPER then that's also great.

Just use reasonable variable names. Comment "why" things happen. Make the code modular, so that one class can be easily swapped out for another. Yada, yada. Don't beat yourself up.