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 - "ternary"
-
Yesterday: Senior dev messages out a screenshot of someone using an extension method I wrote (he didn’t know I wrote it)..
SeniorDev: “OMG…that has to be the stupidest thing I ever saw.”
Me: “Stupid? Why?”
SeniorDev: “Why are they having to check the value from the database to see if it’s DBNull and if it is, return null. The database value is already null. So stupid.”
Me: “DBNull is not null, it has a value. When you call the .ToString, it returns an empty string.”
SeniorDev: ”No it doesn’t, it returns null.”
<oh no he didn’t….the smack down begins>
Me: “Really? Are you sure?”
SeniorDev: “Yes! And if the developer bothered to write any unit tests, he would have known.”
Me: “Unit tests? Why do you assume there aren’t any unit tests? Did you look?”
<at this moment, couple other devs take off their head phones and turn around>
SeniorDev:”Well…uh…I just assumed there aren’t because this is an obvious use case. If there was a test, it would have failed.”
Me: “Well, let’s take a look..”
<open up the test project…navigate to the specific use case>
Me: “Yep, there it is. DBNull.Value.ToString does not return a Null value.”
SeniorDev: “Huh? Must be a new feature of C#. Anyway, if the developers wrote their code correctly, they wouldn’t have to use those extension methods. It’s a mess.”
<trying really hard not drop the F-Bomb or two>
Me: “Couple of years ago the DBAs changed the data access standard so any nullable values would always default to null. So no empty strings, zeros, negative values to indicate a non-value. Downside was now the developers couldn’t assume the value returned the expected data type. What they ended up writing was a lot of code to check the value if it was DBNull. Lots of variations of ‘if …’ , ternary operators, some creative lamda expressions, which led to unexpected behavior in the user interface. Developers blamed the DBAs, DBAs blamed the developers. Remember, Tom and DBA-Sam almost got into a fist fight over it.”
SeniorDev: “Oh…yea…but that’s a management problem, not a programming problem.”
Me: “Probably, but since the developers starting using the extension methods, bug tickets related to mis-matched data has nearly disappeared. When was the last time you saw DBA-Sam complain about the developers?”
SeniorDev: “I guess not for a while, but it’s still no excuse.”
Me: “Excuse? Excuse for what?”
<couple of awkward seconds of silence>
SeniorDev: “Hey, did you guys see the video of the guy punching the kangaroo? It’s hilarious…here, check this out.. ”
Pin shoulders the mat…1 2 3….I win.6 -
There are 10 types of people in this world.
Those who understand ternary , those who don't and those who thought this was going to be a binary joke.4 -
PineScript is absolute garbage.
It's TradingView's scripting language. It works, but it's worse than any language I have ever seen for shoddy parsing. Its naming conventions are pretty terrible, too:
transparency? no, "transp"
sum? no, cum. seriously. cum(array) is its "cumulative sum."
There are other terrible names, but the parser is what really pisses me off.
1) If you break up a long line for readability (e.g. a chained ternary), each fragment needs to be indented by more than its parent... but never by a multiple of 4 spaces because then it isn't a fragment anymore, but its own statement.
2) line fragments also cannot end in comments because comments are considered to be separate lines.
3) Lambdas can only be global. They're just fancy function declarations. Someone really liked the "blah(x,y,z) =>" syntax
4) blocks to `if`s must be on separate lines, meaning `if (x) y:=z` is illegal. And no, there are no curly braces, only whitespace.
There are plenty more, but the one that really got me furious is:
98) You cannot call `plot()`, `plotshape()`, etc. if they're indented! So if you're using non-trivial logic to optionally plot things like indicators, fuck you.
Whoever wrote this language and/or parser needs to commit seppuku.rant or python? pinescript or fucking euphoria? or ruby? why can't they just use lua? or javascript? tradingview17 -
Kotlin: I don't have ternary operator, it's bad for readability
Swift: I removed ++ and --, cause they are old fashioned
Dart: *screams*23 -
Why is the ternary operator such a hated thing? I constantly hear people saying it's less readable, confusing, etc.
I think it's a beautiful, useful, and important operator and I use it constantly wherever readability won't be much affected.
How can you justify a repetitive if/else structure over a ternary, given that you're sure you're not going to put anything else in the ifs?
Whatever happened to DRY?
Whatever happened to KISS?
If those guidelines are what you code by, what's the excuse not to use it?
Because you can't read it as well? Familiarity breeds comprehension and legibility, my dudes.15 -
YOU: if(exp){ statement 1;} else { statement 2;}
v/s
THE GUY: exp ? Statement1 : statement 2;
She says not to worry about!!9 -
Finally found a way to keep track of my ever expanding studies and how to prioritize them as relevant > how interested I'm > how urgent it is (as in it'd be a game changer if I had this skill right now).
It's called a ternary diagram (just in case you wondered)12 -
Saw a lot of posts on social media recently where people highlight a specific quote/sentence from a book/ebook and post it's picture online.
It only I could do the same with the killer ass functions I wrote, or the fifth degree nested ternary operator line of code I wrote that makes the whole component work and is the most beautiful thing I've ever seen. -
I have a junior who really drives me up a wall. He's been a junior for a couple of years now (since he started as an intern here).
He always looks for the quickest, cheapest, easiest solution he can possibly think of to all his tickets. Most of it pretty much just involves copy/pasting code that has similar functionality from elsewhere in the application, tweaking some variable names and calling it a day. And I mean, I'm not knocking copy/paste solutions at all, because that's a perfectly valid way of learning certain things, provided that one actually analyzes the code they are cloning, and actually modifies it in a way that solves the problem, and can potentially extend the ability to reuse the original code. This is rarely the case with this guy.
I've tried to gently encourage this person to take their time with things, and really put some thought into design with his solutions instead of rushing to finish; because ultimately all the time he spends on reworks could have been spent on doing it right the first time. Problem is, this guy is very stubborn, and gets very defensive when any sort of insinuation is made that he needs to improve on something. My advice to actually spend time analyzing how an interface was used, or how an extension method can be further extended before trying to brute-force your way through the problem seems to fall on deaf ears.
I always like to include my juniors on my pull requests; even though I pretty much have all final say in what gets merged, I like to encourage not only all devs be given thoughtful, constructive criticism, regardless of "rank" but also give them the opportunity to see how others write code and learn by asking questions, and analyzing why I approached the problem the way I did. It seems like this dev consistently uses this opportunity to get in as many public digs as he can on my work by going for the low-hanging fruit: "whitespace", "add comments, this code isn't self-documenting", and "an if/else here is more readable and consistent with this file than a ternary statement". Like dude, c'mon. Can you at least analyze the logic and see if it's sound? or perhaps offer a better way of doing something, or ask if the way I did something really makes sense?
Mid-Year reviews are due this week; I'm really struggling to find any way to document any sort of progress he's made. Once in a great while, he does surprise me and prove that he's capable of figuring out how something works and manage to use the mechanisms properly to solve a problem. At the very least he's productive (in terms of always working on assigned work). And because of this, he's likely safe from losing his job because the company considers him cheap labor. He is very underpaid, but also very under-qualified.
He's my most problematic junior; worst part is, he only has a job because of me: I wanted to give the benefit of the doubt when my boss asked me if we should extend an offer, as I thought it was only fair to give the opportunity to grow and prove himself like I was given. But I'm also starting to toe the line of being a good mentor by giving opportunities to learn, and falling behind on work because I could have just done it myself in a fraction of the time.
I hate managing people. I miss the days of code + spotify for 10 hours a day then going home.11 -
You wanna know what the fuck we did in our goddamn code.org class today, wait no, the last whole fucking week. YES OR NO QUESTIONS. I GET BINARY IS FUCKING 0'S AND 1'S. FOR GOD SAKES I KNOW BINARY. I EVEN KNOW FUCKING TERNARY. AND. YOU KNOW WHAT TEACHER ? EVERYONE ELSE COULD LEARN BINARY IN FIVE GODDAMN MINUTES. "Is code.org worthy of being kicked in the ass and tied up on a railroad when the trains coming?" Is a perfect binary question. This whole fucking class I feel like I'm in an english class for five year olds in spain. HEY TEACHER I DON'T CARE IF BILL GATES OR MARK SUCKERBURG OR BARAK OBAMA OR GODDAMN CHRIS BOSH SUPPORTS IT. ITS FOR THERE FUCKING REPUTATION. PEOPLE WITH HALF A BRAIN KNOW THESE PEOPLE DON'T GIVE A FUCK. THEY EACH HAVE HUNDREDS OF MILLIONS OR EVEN BILLIONS OF DOLLARS, BUT THEY ALL CHOSE TO USE A FIVE DOLLAR MIC JUST TO FUCK WITH US. EVERY TIME I WALK IN THAT CLASS I FEEL DEGRADED LIKE I'VE BEEN PUT BACK IN PRESCHOOL. THANK YOU TEACHER, I ALWAYS WANTED TO LEARN BINARY TO MAKE MY FUCKING SIMPLE JAVASCRIPT APP AS MY FINAL PROJECT FOR THE REST OF THE YEAR.4
-
I wrote a base converter in AssemblyScript that could take a numeric or string radix of 2-36. String options being binary, ternary, etc.
Then I couldn’t figure out how to color scheme it, so went about it the lazy way.
I present to you: Choose your own damned background and text colors.
https://baseconverterwebassembly.netlify.app/...6 -
Just because you can do things in one line and throw in ternary operators everywhere, doesn't mean you should.. other people will touch your code. Make it readable instead of making it harder to maintain8
-
Main language, do people have such a thing? Some quixotic shit about various languages I use:
C#: Microsoft
F#: never quite committing to 100% functional paradigms while still being one of the most enjoyable langs I use
Java: null handling via optional and maybes are ugly, but better than it was
C++: surprisingly functional in 2020
Haskell: no one else seems to ❤️ it, despite it being fucking beautiful
Kotlin: Ternary warfare, Czech sports opinions on how languages should work
Clojure: parenthetical scoping makes me far happier than it should
Typescript: makes ever more sense as it changes7 -
Came across a method in the code base that returns a boolean.
It uses a ternary operator which returns true if the result is true and false.. you guessed it... if the result is false.
WHY NOT JUST RETURN THE FUCKING RESULT!!!
What. The. F#%#....2 -
$a = 1;
$b = 2;
echo ($a < $b) ? ($a > $b) ? 'This is totally fine' : ($a < $b) ? 'This is not ok!' : 'Perfect' : 'No problem here';
Why do people do this?!
(And I mean nested ternary ifs, not coding in PHP :P)16 -
This is the ferrocube, a memory cell of the Setun' ([sew-toon]) — the only non-experimental, production ternary computer. It was developed in Soviet Union.
https://en.wikipedia.org/wiki/Setun
https://earltcampbell.com/2014/12/...
http://putcurlybrace.com/2020/01/...2 -
So I got to thinking about computer systems and how they are all based on binary. So the math we perform is obviously based upon a binary approach. Then I started wondering if there was value in exploring math using a different base. I know in math we can shift things to a different domain to do things more efficiently (like Laplace transforms to get to the frequency domain to do freq based calcs, or quaternions to do various orientation calcs). I thought maybe a base 3 logic might do some calcs better. I searched and found that indeed some ternary computing systems had been built. I then searched for libraries that might employ ternary math as an exploration exercise. I didn't find anything except academic articles (few at that).
This idea of changing the base in the math (and possibly the frame of reference) is interesting. It is like searching for treasure and not being sure it even exists.
https://en.wikipedia.org/wiki/...5 -
Not sure if it's the worst code review but it's a recent one.
We don't really do code reviews where I work unfortunately but my coworker used my framework for the first time (build some nice composer libraries for cmdline projects) and asked if I could make them do autoloading.
He never used namespaces before so I was glad to help him out.
What I saw was a dreadful mess. His project was called "scripts" so good luck picking a namespace...
Than it was all lose functions in the executable file. All those functions are however called by a class in another file (if they where not calling eachother as a cascading mess). That class was extending an abstract class from my library as instructed. However I never imagined my lib being raped like that.
The functions themselves are a horrible mess. Nothing uniform completely different style (our documentation states PSR's should be used).
Parameters counts higher than 5.
Variable names like Object and Dobject (in calling function Dobject is Object but it needs a fresh one.
If statements on parameters that need basically split it in two (should simply be to functions)
If else statement with return of same variable as a single line (sane people use ternary for that)
Note that I said functions. All of it should have been OO and methods. Would have saved at least some of the parameter hell.
I could go on and on. Do I think the programmer is bad yes (does not even grasp interfaces, dep injection, foreach loops). Is this his best work no. He said that for a one of script like this it just has to work. Not going to be used elsewhere. I disagree as it is a few thousand lines of code that others have to read too.2 -
I don't really get it why my co-male dev does not like ternary operator as a shorthand operator for if/else statements.15
-
There are 10 types of people in the world: those who understand ternary, those who don't and those who were expecting the binary joke ;)
-
Spent like 24h trying to figure out why the system does not work. It turns out I forgot to put ternary operator into parentheses. :///10
-
Trying to make everything a one-liner. In the process overusing ternary operators, comma operators, short circuiting and/or operators.
Until someone else needs to review or understand what I created, and I'm forced to change... 😥1 -
So my MCU teacher said I should use a long ass ternary to determine which pins should be set high for a given number on a seven segment display. Cause the display was on a single 8-bit port on the mcu I decided to generate a bitmask with a switch statement and set the port directly.3
-
Oh! no There is more than 10 level of nesting conditions in if else statements. I can not refactor it but It needs to add more nest there. I will only add switch statements or ternary operator for the deeper nesting conditions.4
-
My lovely team and I inherited a legacy app written in Angular 14.
We love it when we get fucked by Pajeets like this.
We love tons of `any`-s in the codebase.
We love unreadable code with 5 levels of nested ternary operators.
We love the lack of a README on how to actually build/start the app.
We love the outdated dependencies.
And we absolutely love it when you use a paid package that costs $1755.4 -
There are 10 types of people in tue world. those who think his is a ternary joke, those who can extrapolate from incomplete information...2
-
My biggest influence on coding style is working with other people's code. I know the temptation to write "clever" code and I've been (and probably still occasionally am) guilty of it myself, but it's not until you have to debug someones oneliner iterator which has !(i-j) as the stop condition that you start to appreciate dumb, boring, obvious code.
If having a series of if checks in a long list makes it readable, keep it that way. If it makes it more readable to rewrite it into a nested switchcase with a couple of ternary bits, go ahead. Just don't spend half a day wrapping it up into two layers of abstraction that will require an onboarding process for the rest of the team.2 -
According to people here, ternary operators. I don't care what I'm doing, if I can use a ternary operator instead of an if, get ready for it!
I guess implicit brackets on conditionals and for loops if it's a single line. Anything that saves me typing boilerplate, but it's still readable, I'm gonna do it.1 -
string action = day == "Monday" ? "Go to work" : "Friday" ? "Netflix & chill" : "Saturday" ? "Sleep all day" : "Sunday" ? "Get ready again for Monday" : "Code from 9-5";
I wrote nested ternary operators before and I swear I'd only use shorter conditions like the one below. 😳
string action = isTired == true ? "Get some sleep" : "Drink more coffee";5 -
Flask people
so I was given this old flask project, around 3k lines written in py2, the code is simply old and not refactored. So, it's pile of shit. Migrations completely botched as the original author created reference to live data in models.
Very strict line formatting resulting in backslashed ternary conditions.
Even saw manually formatted json responses... _line by line_.
My job is to clean this mess and eventually do as much as possible to freshen the whole project.
Currently just refucktoring the code as it's the only easy thing to do out of everything that could be done (it's still slow process).
Any tricks and tips? currently considering to try upgrading it to py3 but it feels like throwing gunpowder into already burning house.3 -
I'm developing a new (just for fun) programming language and I'm wondering what features I should add next? These features are already implemented:
- Printing text
- Variables
- user-input
- Datatype conversion (String, Int, Float, Bool, List, Dictionary)
- lists/arrays
- dictionaries
- Sorting
- Shuffling
- random numbers & choices
- Math stuff like: log, abs, floor, ceiling, sin, etc...
- Time & Date
- Working with files
- If-else statements
- Ternary operators
- Loops (for & while)
- Functions
- Classes
- Error handling
- Importing libraries & other scripts
- Arrow/callback functions
- Escaping (\)
is there anything you often use missing?11 -
I hate arrow functions in ES6! Whenever I see them, I get acute code dyslexia and can't read shit. What the fuck is wrong with writing function, why change it for some unreadable series of symbols?10
-
Yesterday, I was expecting my merge request to be closed.
I've done all the stuff my tech lead told me to do.
All tests passes, green light boyzzzzz.
Gitlab CI pipeline passes, greeeeeen light I said.
In Jenkins everything f*cked up...
Why ??
Well it was a conflict with 3 other MRs, missing rebase from other dudes.
And because they were remote working, got to clean up all this mess.
That's was a day off.
PS : well that's was not so off, I could fix a UB on a ternary and extend a test which was not covering some cases.
PS2 : learn git damn3 -
nested ternary operators
like/dislike?
I used to hate them cuz I would have to break them apart just to understand them, but now I use ternary operators so much, nesting at least one level is ok for me.
but i'm the only person that reads my code, what's the concensus.. nesting one level bad?
I wouldn't want someone reviewing my code if they couldn't wrap their head around a simple ternary, so if only myself or people more experienced than myself will ever read them, then fuck it, i'm using them10 -
Feeling good , finally got the time to start on my side-project that has mentally occupied my mind for a while. Let the code out 😊1
-
What's your opinion on functional shortcuts and 'hacks' in many languages, like map/reduce/filter, ternary operator, lambdas,inner/anonymous classes?
Imo they can make development faster and more efficent but they make the code very unreadable, especially if someone else has to read it, Therefore I try to use them only when it's appropriate. My dev friends use them too much and it makes reading their code a hellish experience, especially in Javascript with Rx.3 -
Today I've read this line of code:
$like === true ? $operator = "LIKE" : $operator = "=";
Should I be angry, sad or disappointed?
That was written by a person who I tought could code.6 -
Sometimes I just want to see the world burn.
Unfortunately I'm the one who'll be ranting once I get back to that in the future.4 -
The most excited I was about my code was when I shrunk a bunch of easy if-else statements to a couple of lines using ternary operator. It wasn't groud breaking but it was the first time I felt like a programmer writing nice code.
-
so
?. <- optional chaining
?? <- nullish coalescing
? <- conditional/ternary operator
dunno why, I can't seem to remember optional chaining off the top of my head.8 -
I believe ternary operators should be banned in python/ruby. They are confusing, irrelevant and people use them in bizzare places.4
-
Am I the only one who thinks to rewrite whole thing when the code have weird formatting and so complex to understand and annoying bunch of functions which can be just ternary or an if?
-
People hate on Python a lot. I just used the Python ternary operator for the first time. I found it easier to read than the C++ ternary operator:
0 if i==0 else 2 if i==segmentMax-1 else 1
vs
i==0 ? 0 : i==segmentMax-1 ? 2 : 1
I think Python did a good job in this case.18 -
Looking into some javascript. Which function should I use... guess I have to start the day refactoring. What the f*ck, is good naming so hard:
...
function removeColumn(column) {
selectedColumns.remove(column);
};
function columnRemove(column) {
appliedColumns.remove(column);
}; -
So I have this gulp task to minify javascript but it doesn't actually do that, It minifies in a single line which is actually correct, but it doesn't convert if/else into ternary and true/false to !0/!1?
> Gulp Task: https://pastebin.com/1d8k8juX -
i can never understand the theme behind kotlin.
THEY DON'T HAVE A FUCKING TERNARY OPERATOR!!![?:]
Like before realizing this, i thought yeah jetbrains has decided to make android development a privileged hobby and non beginner friendly , so its now creating an encoding like language, in the false theme of " reducing code size"
But now they remove WORLDWIDE KNOWN, OPTIMIZED , EASY TO READ AND USE AND UNDERSTAND FEATURE of ternary operator and replacing it with less powerful but same looking elvis operator.( and stating that using if else for that is a better option)
Like why? if your goal is to make a shitty encoding language that makes everything shorter and most of the things optional, why remove the already efficient if else encoder?
God knows when this stupid language is going to stop my brain from getting blasted11