Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
C0D4681456yThis is pretty good compared to the legacy shit I have to deal with at times.
As @bitwise said, we all started somewhere pretty similar. -
@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." -
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 -
@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.. -
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. -
Geoxion9036yDoes 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 😅 -
@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. 😝 -
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. -
I have done worst than this 🤣🤣 i remember i have written if($myboolean == true ) $anotherbool == true 🤣🤣 that's embarrassing
-
@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. -
Kaji22626y@bittersweet So in short, code shouldn't have logical branches? I think you've lost me here...
-
Cvrsor2666y@Bitwise I really like your approach in your first comment. Need to get someone in there to teach better habits.
-
@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: -
@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. :/ -
nate15136y@HollowKitty Yes. Overseas companies who pay a fraction of the minimum wage you are used to, who then apportion that by LOC.
-
@nate Yikes. The worst we've seen so far for outsourcing is czech republic, so maybe that explains it.
-
@bittersweet Just scrolled the comments section and hoped to find the __toString() explanation. Thanks! 👌
-
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. -
dfox428276ySome 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. -
mase26yFYI 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.
-
@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.
-
dfox428276y@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. -
@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. -
dfox428276y@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. -
@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.
-
dfox428276y@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. -
@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.
-
dfox428276y@HollowKitty I’m talking about the people specifically criticizing the OP either directly or indirectly.
-
dfox428276y@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.
-
@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. -
What in the hell is the point of that?! I'm not even that verbose in my writing.
Related Rants
Actual code by my (former) coworker. No wonder he's not here anymore
rant
php
code
wtf