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
Search - "scripting python the right way"
-
This code review gave me eye cancer.
So, first of all, let me apologize to anyone impacted by eye cancer, if that really is a thing... because that sounds absolutely horrible. But, believe me, this code was absolutely horrible, too.
I was asked to code review another team's script. I don't like reviewing code from other teams, as I'm pretty "intense" and a nit-picker -- my own team knows and expects this, but I tend to really piss off other people who don't expect my level of input on "what I really think" about their code...
So, I get this script to review. It's over 200 lines of bash (so right away, it's fair game for a boilerplate "this should be re-written in python" or similar reply)... but I dive in to see what they sent.
My eyes.
My eyes.
MY EYES.
So, I certainly cannot violate IP rules and post any of the actual code here (be thankful - be very thankful), but let me just say, I think it may be the worst code I've ever seen. And I've been coding and code-reviewing for upwards of 30 years now. And I've seen a LOT of bad code...
I imagine the author of this script was a rebellious teenager who found the google shell scripting style guide and screamed "YOU'RE NOT MY REAL DAD!" at it and then set out to flagrantly violate every single rule and suggestion in the most dramatic ways possible.
Then they found every other style guide they could, and violated all THOSE rules, too. Just because they were there.
Within the same script... within the SAME CODE BLOCK... 2-space indentation... 4-space indentation... 8-space indentation... TAB indentation... and (just to be complete) NO indentation (entire blocks of code within another function of conditional block, all left-justified, no indentation at all).
lowercase variable/function names, UPPERCASE names, underscore_separated_names, CamelCase names, and every permutation of those as well.
Comments? Not a single one to be found, aside from a 4-line stanza at the top, containing a brief description of that the script did and (to their shame), the name of the author. There were, however, ENTIRE BLOCKS of code commented out.
[ In the examples below, I've replaced indentation spacing with '-', as I couldn't get devrant to format the indentation in a way to suitably share my pain otherwise... ]
Within just a few lines of one another, functions defined as...
function somefunction {
----stuff
}
Another_Function() {
------------stuff
}
There were conditionals blocks in various forms, indentation be damned...
if [ ... ]; then
--stuff
fi
if [ ... ]
--then
----some_stuff
fi
if [ ... ]
then
----something
something_else
--another_thing
fi
And brilliantly un-reachable code blocks, like:
if [ -z "$SOME_VAR" ]; then
--SOME_VAR="blah"
fi
if [ -z "$SOME_VAR" ]
----then
----SOME_VAR="foo"
fi
if [ -z "$SOME_VAR" ]
--then
--echo "SOME_VAR must be set"
fi
Do you remember the classic "demo" programs people used to distribute (like back in the 90s) -- where the program had no real purpose other than to demonstrate various graphics, just for the sake of demonstrating graphics techniques? Or some of those really bad photo slideshows, were the person making the slideshow used EVERY transition possible (slide, wipe, cross-fade, shapes, spins, on and on)? All just for the sake of "showing off" what they could do with the software? I honestly felt like I was looking at some kind of perverse shell-script demo, where the author was trying to use every possible style or obscure syntax possible, just to do it.
But this was PRODUCTION CODE.
There was absolutely no consistency, even within 1-2 adjacent lines. There is no way to maintain this. It's nearly impossible even understand what it's trying to do. It was just pure insanity. Lines and lines of insanity.
I picture the author of this code as some sort of hybrid hipster-artist-goth-mental-patient, chain-smoking clove cigarettes in their office, flinging their own poo at their monitor, frothing at the mouth and screaming "I CODE MY TRUTH! THIS CODE IS MY ART! IT WILL NOT CONFORM TO YOUR WORLDLY STANDARDS!"
I gave up after the first 100 lines.
Gave up.
I washed my eyes out with bleach.
Then I contacted my HR hotline to see if our medical insurance covers eye cancer.32 -
Man, I think we've all gotten way too many of these.
Normally most interactions that I have are through email. Eventually some would try to contact me via phone. These are some:
"Hey! We are calling you from <whatever company name> solutions! (most of them always seem to end on solutions or some shit like that) concerning the Ruby on Rails senior dev opportunity we were talking about via email"
<niceties, how are you doing, similar shit goes here...eventually>
So tell us! how good/comfortable would you say you are with C++?"
Me: I have never done anything serious with c++ and did just use it at school, but because I am not a professional in it I did not list it in my CV, what does it have to do with Rails?
Them: "Oh the applications of this position must be ready to take in additional duties which sometimes happen to be C or C++"
Me: Well that was not anywhere in the offer you sent, it specifically requested a full stack Rails developer that could work with 3 different frontend stacks already and like 4 different databases plus bla bla bla, I did not see c++ anywhere in it. Matter of fact I find it funny, one of the things that I was curious about was the salary, for what you are asking and specifically in the city in which you are asking it for 75k is way too low, you are seriously expecting a senior level rails dev to do all that AND take additional duties with c++? cpp could mean a billion different things"
Them: "well this is a big opportunity that will increase your level to senior position"
Me: the add ALREADY asks for a senior position, why are you making it sound that I will get build towards that level if you are already off the bat asking for seniors only to begin with?
Them: You are not getting it, it is an opportunity to grow into a senior, applicants right now are junior to mid-level
ME: You are all not making any sense, please don't contact me again.
=======
Them: We are looking for someone with 15 years experience with Swift development for mobile and web
Me: What is up with your people not making these requirements in paper? if I knew from the beginning that you people think that Swift is 15 years old I would have never agreed to this "interview"
Them: If you are not interested in that then might we offer this one for someone with 10 years experience as a full stack TypeScript developer.
Me: No, again, check your dates, this is insulting.
===
* For another Rails position
Them: How good are you with Ruby on Rails in terms of Python?
Me: excuse me? Python has nothing to do with Ruby on Rails.
Her (recruiter was a woman) * with a tone of superiority: I have it here that Python is the primary technology that accompanies Rails development.
Me (thinking this was a joke) : What do you think the RUBY part of Ruby on Rails is for? and what does "accompanies Rails development" even means?
Her: Well if you are not interested in using Rails with Python then maybe you can tell us about your experience in using Javascript as the main scripting platform for Rails.
Me: This is a joke, goodbye.
====
To be fair this was years ago when I still didn't know better and test the recruiters during the email part of being contacted. Now a days I feel sorry for everyone since I just say no without even bothering. This is a meme all on itself which no one has ever bothered to review and correct in years for now. I don't know why recruiters don't google themselves to see what people think of their "profession" in order to become better.
I've even had the Java/Javascript stupidity thrown at me by a local company. For that one it was someone from their very same HR department doing the rectuiter, their shop foreman was a friend of the family, did him the service of calling him to let him know that his HR was never going to land the kind of developer they were looking for with the retarded questions they had and sent him a detailed email concerning the correct information they needed for their JAVAscript job which they kept confusing with Java (for some reason in the context of Spring, they literally wanted nothing with Spring, they wanted some junior to do animations and shit like that on their company's website, which was in php, Java was nowhere in this equation)
I think people in web development get the short end of the stick when it comes to retarded recruiters more than anywhere else.3 -
Guys, a company's HR mailed me for a position that requires strong experience of ">3 years in Python with C or C++".
Does it mean Python and C/C++?
Or do they need someone who is using C/C++ to write Python?
I have some experience with adding Python support to C++ code. Does it count? 😁8 -
Today's rant: JavaScript's type system.
I realized halfway through that I can't happily call JavaScript a "programming language" so just assume
alias programming="scripting"
I'm sure it's not actually as frustrating as it seems to me. Thing is, I'm used to either statically-typed languages or dynamically-typed languages that actually make sense. If I were to try to add an integer to something I'd forgotten was a string in Python, it'd immediately tell me "look, buddy, do you want me to treat this as a concatenation or an addition? I have no idea the way you've got this written." I've found that mistakes are a common thing with dynamic typing. Maybe I'm just not experienced enough yet, maybe it's really as stupid as it looks. JavaScript just goes "hey look I'm gonna tack all of these guys together and make a weird franken-string like '$NaN34.$&' because that's absolutely what we want here!" Then I run my webpage and instead of a nice numeric total like I wanted, good old JavaScript just went "Yep, I have no idea what I'm doing here I'm just gonna drop this here and pretend it's right." Now absolutely I do not expect my programming language to make correct assumptions and read my mind, otherwise JavaScript would be programming me and not the other way around. But it could at least let me know that I had incompatible types going on rather than just shamelessly going along with what it's doing. Good GRIEF, man, some of the idiosyncrasies of the EMCAScript language definition itself just make me want to punch a horse.6 -
If you've ever tried using Go plugins raise your hand.
If you've ever tried doing plugins in Go, raise your hand.
If you think that the following rant will be interesting, raise your hand.
If you raised your hand, press [Read More]:
This is a tale of pain and sorrow, the sorrow of discovering that what could be a wonderful feature is woefully incomplete, and won't be for a very long time...
Go plugins are a cool feature: dynamically load pre-compiled code, and interact with it in a useful and relatively performant way (e.g. for dynamically extending the capabilities of your program). So far it sounds great, I know right?
Now let me list off some issues (in order of me remembering them):
1. You can't unload them (due to some bs about dlopen), so you need to restart the application...
2. They bundle the stdlib like a regular Go binary, despite the fact that they're meant to be dynamic!
3. #2 wouldn't be so bad if they didn't also require identical versions of all dependencies in both binaries (meaning you'd need to vendor the dependencies, and also hope you are using the right Go version).
4. You need to use -trimpath or everything dies...
All in all, they are broken and no one is rushing to fix it (literally, the Go team said they aren't really supporting it currently...).
So what other options are there for making plugins in Go?
There's the Hashicorp method of using RPC, where you have two separate applications one the plugin, one the plugin server, and they communicate over RPC. I don't like it. Why? Because it feels like a hack, it's not really efficient and it carries a fear of a limitation that I don't like...
Then we come to a somewhat more clever approach: using Lua (or any other scripting language), it's well known, it's what everyone uses (at least in games...). But, it simply is too hard to use, all the Go Lua VMs I could find were simply too hard to set up...
Now we come to the most creative option I've seen yet: WASM. Now you ask "WASM!? But that's a web thing, how are you gonna make that work?" Indeed, my son, it is a web thing, but that doesn't mean I can't use it! Someone made a WASM VM for Go, and the pros are that you can use any WASM supporting language (i.e. any/all of them). Problem inefficient, PITA to use, and also suffers from the same issues that were preventing me from using Lua.
Enter Yaegi, a Go interpreter created by the same guys who made (and named) Traefik. Yes, you heard me right, an INTERPRETER (i.e. like python) so while it's not super performant (and possibly suffering from large inefficiency issues), it's very easy to set up, and it means that my plugins can still be written in Go (yay)! However, don't think this method doesn't have its own issues, there's still the problem of effectively abstracting different types of plugins without requiring too much boilerplate (a hard problem that I'm actively working on, commits coming soon). However, this still feels to be the best option.
As you can see, doing plugins in Go is a very hard problem. In the coming weeks (hopefully), I'm going to (attempt to at least) benchmark all the different options, as well as publish a library that should help make using Yaegi based plugins easier. All of this stuff will go (see what I did there 😉) in a nice blog post that better explains the issues and solutions. But until then I have some coding to do...
Have a good night(/day)!13