152

Actual code by my (former) coworker. No wonder he's not here anymore

Comments
  • 6
    Just to make sure you know x)
  • 53
    With PHP you can't be sure enough..
  • 5
    This is pretty good compared to the legacy shit I have to deal with at times.

    As @bitwise said, we all started somewhere pretty similar.
  • 17
    @Bitwise Never understood why people feel the need to mock someone's code. Sorry we're not fucking Einstein from the start.

    I had a comment the other day, and it was something along the lines of "people tend to forget where they come from and the fact that they were new to this at some point as well."
  • 2
    just use atom, thx
  • 6
    The first lines of code I ever wrote were in VBA and I was completly oblivious to the concept of variables. So my calculator used labels to store the temporary results for chained operations.

    Of course now-a-days I now better than that, but it still gives me perspective about the journey I embarked on nearly 10 years ago.

    So please don't shame others for their mistakes, much rather embrace those faults as an opportunity to help other advance in their efforts.

    #spreadcleancode
  • 8
    @Stuxnet well it's devRANT...so this is just another valid reason for ranting imho..

    Getting fired over sth like this.. well I think we all'd be fired if we didn't learn from our mistakes..
  • 5
    Who the hell mixes double and single quotes like that!
  • 1
    Damn and i still don't have a job
    *crying inside*
  • 3
    What does this even do....
  • 5
    @NULLmaster Absolutely nothing
  • 3
    I didn't say he got fired, I said he wasn't working here anymore.

    And the guy had 3 years of experience with PHP at the time he wrote that.
  • 1
    Does PHP have properties? If so, the setter could have some desired side effect he wanted, but didn't want to change the value when it was one of the values he checked for.

    Still inefficient and bad design, but then the code would at least do something 😅
  • 5
    @Bitwise @Geoxion

    OK far fetched, but theoretically the array index could contain an instance of a class with a magic __toString() method, which in turn returns "User".

    Comparing that instance to a string with == yields true in PHP (not when using ===)

    So the code would replace stringable objects with primitive strings, in which case the code is not a no-op. 😝
  • 4
    My humble thoughts:
    If you need to fire someone, make sure to gift the person with a review on their mistakes. I would be happy to know what was bad and how I could improve.
  • 1
    I have done worst than this 🤣🤣 i remember i have written if($myboolean == true ) $anotherbool == true 🤣🤣 that's embarrassing
  • 0
    @Bitwise Would still be pretty bad code though 😶

    I consider all code containing "else" or "elseif" bad.

    "If" is fine, it's used to execute something conditionally, but "else" is a useless keyword which literally breaks one of the primary rules of OOP: the single responsibility principle.
  • 0
    @Null0x90 Yeah, I was kind of waiting for a default case at the end to cover everything. Was disappointed.
  • 1
    @bittersweet So in short, code shouldn't have logical branches? I think you've lost me here...
  • 0
    @Bitwise I really like your approach in your first comment. Need to get someone in there to teach better habits.
  • 0
    @ArcaneEye @Kaji

    Of course you need branching logic.

    But one method/function should have only one responsibility. When you see an "else" keyword, it is almost always a signal that code can and should be simplified.

    One of the most readable ways to structure code is to start out with errors & adjustments, then just end by returning the successful value.

    Just a stupid hypothetical example:
  • 3
    Was he paid by the line or...?
  • 0
    @HollowKitty Many outsourced companies are!!!11
  • 0
    @nate Really, even in this day? I've worked for some companies that hired some pretty shitty outsourcers and even then they were hired by the day or by the feature.

    Still I don't know how else code like this could come about. :/
  • 0
    @HollowKitty Yes. Overseas companies who pay a fraction of the minimum wage you are used to, who then apportion that by LOC.
  • 0
    @nate Yikes. The worst we've seen so far for outsourcing is czech republic, so maybe that explains it.
  • 1
    @bittersweet Just scrolled the comments section and hoped to find the __toString() explanation. Thanks! 👌
  • 2
    I know everyone is being "don't mock the code, everyone started here" but I didn't. I did start at the bottom, confused as hell, but this is lower. A confusing amount lower.

    I'm just curious if someone can explain to me:
    What does "if x is equal to value, set x to the same value, rinse repeat" possible achieve aside from wasting cycles?

    Also I find it highly improbable that they are aware that setters can have side effects, yet too blind to see how bad of a design that is, instead of just actually doing what you want explicitly.
  • 0
    well, at least it's not vulnerable to query param injection...
  • 0
    Now your employees will learn from his mistakes, i.e. not to use bright theme
  • 3
    Some of the comments here are way too preachy IMO.

    The code is shitty, it’s funny, and the rant makes absolutely no mention of junior developers (or if this person was even considered jr) and says nothing about the person being fired specifically for this code. I’m guessing this wasn’t the only bad code the person wrote to not be there anymore :) Some of the comments here make so many assumptions about the original post it’s not really fair, and borderline disrespectful IMO to the poster.
  • 2
    FYI the code isn't bad because a junior did it or because it's inefficient - it's bad because if you look closely, you will see it's doing absolutely nothing.
  • 1
    @dfox If you're the author of this code I can recommend you some remedial classes. :) Seriously though this code is inexcusable for anyone who thinks they're a professional. Only way I could see it being disrespectful would be if someone was assuming that this reflected on the rest of the programmers at the company, which I don't see here.
  • 2
    @HollowKitty I meant disrespectful to the original poster for making tons of assumptions without asking a question.

    Here’s the assumptions I saw made here, none of which were stated in the original rant:
    - the developer was a jr
    - the developer had no experience
    - the developer was fired for this one piece of bad code
    - the developer was fired (maybe they just left on their own seeing it wasn’t a fit)
    - the developer took kindly to constructive criticism/teaching and wanted to learn (I’ve met multiple junior devs who were combative when people tried to help them)

    All of those things could be true, but I feel like it would be respectful to the original poster to engage in conversation and ask them about that kind of stuff as opposed to just assuming the absolute worst.
  • 1
    @dfox But you made some of these assumptions yourself? "I’m guessing this wasn’t the only bad code the person wrote to not be there anymore".

    And honestly yes, if someone writes code like this they're a junior, regardless of what their job title might be, aside from a small chance that they happened to be horribly injured and were writing code while high on prescription medication. This isn't just sloppy code, it's completely worthless code.
  • 1
    @HollowKitty the word “guessing” states it’s an assumption that I don’t know for sure. I also wasn’t giving advice based on assumption. The other comments I’m referring to were not formatted as such, asked no questions, and just made assumptions and handed out advice. I’m a strong believer that if you’re giving advice then assumptions are bad and you should ask questions.

    The OP said the person had 3 years of experience with PHP. I wouldn’t expect to see that bad of code from someone with 3 years of experience, and 3 years isn’t really a jr either in many situations.
  • 0
    @dfox I wouldn't expect to see code this bad from someone with 3y experience either, but there are people who have 3 years of experience and then there are people who have the same year of experience 3 times in a row. In a sane world, "junior" isn't a measure of years spent with your butt in a seat, it's a measure of ability. Unless this person wrote the code on a super off day, this is a sign the person is a junior, and not a very good junior either.
  • 0
    @HollowKitty I get your point, but I’m sure there could be other reasons. I’m not really sure what you’re arguing exactly. My point stands - I don’t see anything controversial in this post and I did see a lot of assumptions in the comments (more important that jr., ones like they were fired for this and the person does want to get better).

    It’s devRant - people are going to rant and I think this is a great rant. I don’t want people to feel like they will be judged unfairly for posting rants. Some of the stuff in this thread are great examples of unfair judging, and I don’t want that to be a thing here. If you must point out the other side of a rant like this, at least ask a few questions to validate what you are trying to get at, otherwise it’s just unfair to the OP.
  • 0
    @dfox I guess I don't agree that bagging on the author of the code is bagging on the OP. The OP knows the code sucks and presumably the OP wasn't responsible for hiring them.
  • 0
    @HollowKitty I’m talking about the people specifically criticizing the OP either directly or indirectly.
  • 0
    @Bitwise no problem, I think your comment led to some other ones that were more critical of the OP, so I wasn’t really referring to yours specifically. I think there were some after it that were much more unfair.
  • 0
    @ArcaneEye I guess I can see that. Kinda. But really it's 2018. Unless you need to build embedded systems, who really uses strongly unsafe typed languages?

    If this code can be be considered a good idea, then it's probably best to look at the code which makes it justifiable. That's probably bad code.
  • 0
    What in the hell is the point of that?! I'm not even that verbose in my writing.
Add Comment