Yep, he sure did. On the process of achieving this feat, he forgot that response.json is a function and you have to call it to successfully return the dictionary. π
Are you talking about type hinting as in providing type hints in function signature itself, for parameters and return types? If so, we already follow this practice.
First the response.json will be a function call, as in, response.json(). Then, you should use .get() to access keys instead of []. Then for sake of sanity, you can have a check if token, which will detect if the token is empty or not, then you can return the appropriate value.
That didn't even need unit tests to catch it, it would have simply never worked and would be obvious the first time you try to run it. This person...gets paid...to code?
Market's hot rn. I just took a new job w a 50% pay bump. If these are your superiors then you're in danger of being the smartest person in the room, which is a bad thing. Maybe have a look around. If you're interested in remote you can start making NY/LA salaries and spending them in Peoria.
Requiring the tests to pass won't do much if you don't enforce a coverage requirement, and do it in such a way that any scheme to game it will at least be obvious to the human code reviewer.
My current project was such a fucking nightmare when I first took it over that me and my supervisor basically decided that it would be better to set up a remote server and check in code then test if it worked.
To give you a sense of how fucked up it was, it took me 4 hours to get it back into development mode after spending a month of it in production mode. Because that's how fucking messed up the ONE file that the project needed for it to launch in development mode. Of course it took me longer since I had to learn the framework the previous developer picked which didn't have the world's best documentation so reverse engineering it wasn't always the easiest item, especially when you mess with the config files it needs to launch in development mode.
That's different though. I'm assuming (maybe a big assumption) that you set up a new branch specifically for deploying to that new server. That, in my mind, is still considered running the code before checking it in to master. Not all development supports a local functioning build. But before that gets into a PR to master for a review, it should be run in some way, shape, or form.
well, I'm the only developer so just about everything gets checked onto Master (although yes, I use separate branches for development though and don't check in right on Master).
It sucks it had to be this way since it's not really efficient by all means. But to describe this project in a few words it would be "Code Vomit" and yes, 90% of what was there originally has been rewritten already.
There were 800+ line functions, 400-450 of which were used to draw instructions on an HTML canvas (the core of the project is a series of HTML canvas "games" for a research study). I rewrote the same instructions and opted for a bootstrap modal instead, I used 30 lines. The only difference was their version showed images while mine is just text for now. Had they gone with a modal instead to handle the resizing of stuff easily all they would have needed to do is inject the images into the modal markup. They basically over did shit by a factor of 10 basically. And that was only one part of the site...
I once had to spend 2 weeks untangling a while loop of over 4000 lines.
It updated a database with values from itself, and it would do so by looping over its own rows using nested for loops inside. It was incredible. Updating a few thousand lines could take days. The company has been buying bigger and bigger machines to run the damn thing... I did not last long there.
Once I was done with it, the entire operation took less than an hour, typically around 10 minutes.
Sounds about right, I once had to write an Excel Macro to process a bunch of data that took maybe 3-4 hours for new people and 30 minutes to an hour for people familiar with how it works run in under 3 minutes. This data would then be fed into another stats software. What the macro did was basically take the raw data that was recorded and since the entire set didn't need to be used chop off the excess and then calculate aggregate values. If you want to imagine how the data was setup imagine a relational database model that has 3 tables, and Table A has X rows that point to a specific row in Table B which has multiple rows that point to a row in Table C. (Probably the worst way to visualize it but there was hierarchy to the data).
They were glad I was able to do that since it just meant that much quicker turn around time
In my small team of 3 we set up a Jenkins emailer to send an email whenever the testing suite fails one or more tests. We call it the "Shame Alarm" - shame on you for not running the tests before committing!
It works well, mostly because we've all triggered it once or twice so there's no shame in doing it anymore, just commiseration and feigned frustration.
We have that where I work, but we can override it for any non-empty stated reason, and doing so doesn't send notifications -- at least, not ones that anyone actually lets through the filters and reads.
It's not an excuse, but as this is Python won't it run correctly unless that specific branch is executed? i.e. the interpreter will see a syntactically correct file, and be fine until it tries to execute that specific piece of code.
I know that was a huge shock for me working in a Python environment and coming from a compiled languages background. I'd make a change to a small edge-case, run the test suite which looked to test that functionality, make a PR and inevitably get little surprises picked out... if I was lucky. Otherwise it would pass CI/CD hit production and bang.
This kind of problem happens in all languages. Compiled or not. There is no shortcut for testing your own changes.
Just because it is syntactically correct, says nothing about the logic or behavior. Just because you have a test suite, doesn't mean that everything is tested or even should be tested.
The backstory is I had literally added the first line a week prior. something was the result of a regular expression that logically could not have included either of the two things they tried replacing.
I asked them wtf this was and if there was some bug with the original.
They said no, they just put those in to "make sure". I explained what the regex did and showed them how to test the expression themselves: they had never even run the expression to see what output would come of it.
I mean honestly I don't blame them; people (speaking from experience) write some really dumb shit when they don't know that regex exists
I wrote a ~2000 line parser for the output of a cli dictionary that probably could have been done in 400 with regex and groups. Except I didn't know groups existed.
Iβve been struggling lately with a dev on my team who always wants to do a null check βjust in caseβ even when itβs right after another check and the code clearly will not be reached if the value is nullish.
My team does pair programming, so when I pair with him itβs sort of a feature, in that it reminds me to consider for each usage whether it should be checked, since he includes it and then I have to tell him to remove it and justify it. But when he pairs with another less-experienced dev, they end up writing very inefficient code.
Iβm really curious in his previous team, which did not use a recent language version, if he did this many null checks, or if the ES2020 optional chaining operator convinced him to do it, since it makes it look like the check is free, since itβs just 1-2 additional characters.
That's when I typically see stuff like this, flailing because something didn't make sense and once it was fixed they lacked the discipline (or confidence) to go back and undo all their crazy additions.
Iβm with you there, but humans make mistakes. He probably did not notice the missing parenthesis. I am guessing he did not write unit test at all. Because this couldβve caught also by the unit test.
Can someone explain the "if" part to me. Aren't those non-boolean variables, so what is the "and" comparing? I'm confusion. Or are the token variables simply Boolean values?
Cant you just simply check if token_variable.strip() exists instead of checking if token, token_variable and token_variable.strip() exists? because if tolken_variable.strip() exists then token exists too
In Python objects can have boolean values, so an int with value 0 evaluates to False while any other value (including negatives) evaluates to True, as for container and sequence objects, like set/dict or list/str, they evaluate to True when not empty.
Yeah what's up with people submitting PRs without even testing their code. After I submit a PR I even go to gitlab / GitHub to check if everything looks right because I don't want to submit some trash PRs.
I read somewhere that coding style reflects your mind. I really hope my colleague is doing fine with his life. It will be difficult to find a psychiatrist appointment during the pandemic situation.
592
u/[deleted] Jul 23 '21
He / she just wanted to make sure the token is really stripped out.
135
u/DrMaxwellEdison Jul 23 '21
I once came back from a day off to a new code review in my inbox. They had changed a line from:
To:
The backstory is I had literally added the first line a week prior.
somethingwas the result of a regular expression that logically could not have included either of the two things they tried replacing.I asked them wtf this was and if there was some bug with the original.
They said no, they just put those in to "make sure". I explained what the regex did and showed them how to test the expression themselves: they had never even run the expression to see what output would come of it.
PR declined with prejudice
29
u/mr_flameyflame Jul 23 '21
You just gotta be sure.
19
u/[deleted] Jul 23 '21
I thought this was an ad.
36
u/[deleted] Jul 23 '21
I just can not see why ... Why?
6
u/deniercounter Jul 24 '21
Obvious error in last line. Must be:
return token.strip()
9
u/shizzy0 Jul 23 '21
Strip poker. Strip coding.
4
u/SquidgyTheWhale Jul 24 '21
Review feedback: take a two week break, then give up coding altogether.
4
u/RepulsiveSheep Jul 24 '21
How do you make these screenshot worthy code snippets with the macos terminal thingy in the background?
3
u/[deleted] Jul 24 '21
This code is kinda STRIPtease
2
u/ta69ta69 Jul 24 '21
What is this "strip()" function in JS? Can't find any documentation. I'm guessing it's from your project?
2
u/kewlness Jul 24 '21
That token must be naked by now...
2
u/vawael Jul 24 '21
They forgot to write token.strip() in the return statement.
2
u/Nick433333 Jul 24 '21
Iβm seriously tempted to believe that this is intentionally bad code, because I refuse to believe someone wrote this with a serious face.
2
u/[deleted] Jul 30 '21
This couldβve been avoided if he used an editor with a decent linter. That will be bright red.
54
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Jul 23 '21
Image Transcription: Code
I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!
3
u/OrganicToes Jul 23 '21
Can someone explain the "if" part to me. Aren't those non-boolean variables, so what is the "and" comparing? I'm confusion. Or are the token variables simply Boolean values?
16
u/squishles Jul 24 '21
I can just see this guy yelling at his laptop
"STRIP YOU FUCKER STRIP!!!!!"
12
u/mosskin-woast Jul 24 '21
This reminds me of things I did as a baby coder because I thought it was somehow more secure
5
u/witty_salmon Jul 24 '21
Yeah what's up with people submitting PRs without even testing their code. After I submit a PR I even go to gitlab / GitHub to check if everything looks right because I don't want to submit some trash PRs.
4
u/[deleted] Jul 24 '21
Take it off baby!
1
u/DatAndre evil Jul 24 '21
Offtopic: where do you guys creates this type of graphics?
3
u/[deleted] Jul 24 '21
You colleague really wants to be a stripper.
3
u/uhimc00l Jul 24 '21
can never be too sure
3
u/abhi307 Jul 24 '21
The stripper..
5
u/QueenVogonBee Jul 24 '21
Clearly he/she loves stripping π
4
u/[deleted] Jul 24 '21
Damn, I was wondering why my job was paying me in singles.
2
u/middproxxy Jul 24 '21
Plot twist: the token spins around i/o pipes.
2
u/midgetlotterywinner Jul 24 '21
I'm mad at token.
2
u/Oveno Jul 24 '21
Nice striptease
2
u/il-est-la Jul 24 '21
Don't believe it...
2
u/Quanalack Jul 24 '21
This makes me feel better about my shitty code, thanks
2
u/crispy_cheez Jul 24 '21
better be tipping those variables
2
u/monkeywench Jul 24 '21
This seems like it was written with ML lol
2
u/pencilsdontshave Jul 24 '21
I feel like little caesars cause all that stripping got me hot n ready
2
u/thedevguy-ch Jul 24 '21
Take your clothes off already variable... - code author
2
u/therc7 Jul 24 '21
STRIP THE TOKENNNNN!
2
u/Konkichi21 Jul 24 '21
Talk about strip searching!
2
u/call-me-td Jul 24 '21
This person has serious trust issues
2
u/[deleted] Jul 27 '21
Canβt have more than enough strippers.
2
u/Timeler1 Jul 28 '21
This is so lost even i understand it lol
3
u/Slavichh Jul 24 '21
This makes me feel better about myself
3
u/kreetikal Jul 24 '21
Slaps response This baby can fit so much stripping
3
u/GiantsFan2645 Jul 24 '21
So much stripping in this code there should be a pole
1
u/dumblechode Jul 24 '21
tease.strip()
0
u/[deleted] Jul 23 '21
[deleted] β view deleted comment
0
u/[deleted] Jul 24 '21
[deleted] β view deleted comment
4
u/[deleted] Jul 23 '21
[removed] β view removed comment