Circle slash circle 2 is unreadable code. Clearly this needs a dedicated function with if/else blocks of common outputs of the previous calculation, and just add blocks as you find more cases.
They both will likely optimize to same code underneath the hood anyways (don't know about this case). Such micro-optimizations are pointless anyways with todays hardware.
That might work in languages where booleans are just numeric types (e.g. C where true ^ false == 1 and true == 1), easily promote to numeric types and back (e.g. JS where true ^ false === 1 and 1 == true) or where xor is defined as a boolean xor for the boolean type (e.g. Python where True ^ False == True).
In any of these languages (and I've worked with each of them full time professionally) this would surprise me, though I'd probably accept it for Python. It's better to be obvious than to be clever.
In C and JavaScript this would be dangerous because this is always a bitwise operator, and at the same time they have the concept of truthiness, where values can be truthy and evaluate as true in any context where a boolean would be accepted, without having the same value as true. For example, 2 and 1 are both truthy, but so is 2 ^ 1 (3).
Happy to hear further insight as to why beginners program in a "spoken language" sort of way, it has always fascinated me. Yes, my friend is a beginner.
I basically came across this myself in our code base the other way around; When you have huge subroutines, where the "if" is several screen heights away, then reading "else" is not very helpful.
It made me think about how to express such code more naturally, but the disadvantages of "if/then/elif/then" over "if/then/else" are just too big. (Also, solving the problem from the wrong side...)
This entire subreddit is people circle-jerking each other by thinking they are smart by being pedantic in pointless code snippets.
"omg, you wrote 10 else if statements? disgusting, you are stupid. I, however, am super smart and would use switch case, which is way better and fixes everything"
"pff, meaningless if else condition, i could save 2 lines by negating the bool value, saving the entire world from this monstrosity of a code"
Probably beginner programmers wanting to feel good and validated by looking at bad code and finding mistakes with it.
In programming there is a concept called "maintainability". If EVERY developer pushed code like this to the repo, no one would want to maintain this bs
Oops, sorry if it came out in a bad way. I totally get your point, I myself code on Roblox every once in a while because it's way faster than having to deal with sockets, networking, backend, servers, etc. Nice platform to program semi-peacefully in :)
I love how for some people this seems like the worst thing they can think of. This easily happens even to experienced and skilled programmers when refactoring. It's still readable and it can easily be cleaned up, so I'd put it around the bottom of the list of things about a code base that frustrate me. On the top of that list are things that actually matter, e.g. "half of the code solves the wrong problem and shouldn't exist because the problem is Theseus' ship", "the solution fundamentally doesn't scale to the number of users we have"
If you find this so horrifying as to exclaim expletives at it, just wait until you see a real, non-trivial production code base.
I love the speed at which I can write code in dynamically typed languages (say, Python, Javascript, ...) but one of the things I hate is how issues like
def doit(flag):
if flag:
doit1()
else:
doit2()
doit("False")
are shifted to the runtime, while hardening the code with static analysis and type hints removes many of the advantages the languages had in the first place.
Mind you, the net outcome is still positive for the most part.
My friend who sometimes stalks me on Reddit and gives random anonymous awards did this mistake one and I corrected him. If you're reading this, you know who you are, ily homie
Well, there's nothing wrong with doing it this way in languages where an ifs condition must be a boolean, like Java or C#. This seems to be Lua, where all values other than false and nil are truthy. Explicitly checking cond == true restricts what conditions will be accepted in a way that's inconsistent with the rest of the language, so I'd say it is a bit wrong... really not wrong enough to make a big deal out of, but not quite right either.
Yet again, an instance of people (since I shouldn't say just beginners) not being aware that conditions and booleans are the exact same thing!
Edit:... Kinda. Partially. Now that I say it I don't know if simplifying the expression to inventory.Visible = not inventory.Visible is particularly indicative of that.
Well, the screenshot is obviously a beginners take at flipping a Boolean. OP thinks it is bad code since this can be done in a fucking one-liner.
Now, it is true that you shouldnât use elsifs without an else. How often do you see a beginner doing something like that:
If (userinput == âhalfâ)
a = 2
Elseif (userinput == âthirdâ)
a = 3
Endif
b = something / a;
the above is just a dumb example, but most programmers just forget about the fucking else, especially if the blocks are large and the âelseâ case is very rare. There is also a group of beginners who struggle with conditions at the beginning of their careers. So basically what I tell every programmer: use the else. If you just âdonât wantâ or âdonât needâ to do anything there, place a comment there, like âdonât bother with all other casesâ. If the else never happens, then convert last elseif into an else (like in the OPs post), if you think it shouldnât happen in praxis, but may happen in theory, place an else and throw an exception with âshouldnât happenâ as text
Now the joke is to complain at something that was obviously not the intent of OP, but still a valid point of improvement.
if inventory.visible == false then
inventory.visible = true
Elseif inventory.visible == true then
inventory.visible = false
Endif
should be
if inventory.visible == false then
inventory.visible = true
Else
inventory.visible = false
Endif
Well tbf I used the else always when I was a beginner since I wanted to be clear what's going on. But later on I had seen more code from others and then I used their way where when you just want to do sth IF a condition is met then you won't use an ELSE
236
u/[deleted] Dec 27 '21
bruh all he needed to do to shorten it was to replace it with inventory.Visible = not inventory.Visible
104
u/halfanothersdozen Dec 27 '21
I mean it's not wrong
25
u/Arcoda2 Dec 27 '21
I can recognize the roblox coding font&colors here
5
u/redfoggg Dec 27 '21
I really don't understand what's is the goal here.
13
u/eyisus Dec 27 '21
Ahh yes a perfectly balanced finite state machine
2
u/xdjiijii Dec 27 '21
how about inventory.Visible = !inventory.Visible
am I missing something?
8
u/Reaper_Houstan Dec 27 '21 edited Dec 27 '21
Image Transcription: Code
I'm a human volunteer content transcriber and you could be too! If you'd like more information on what we do and why we do it, click here!
24
u/Da-Blue-Guy Dec 27 '21
if boolean == true
what the fuck
1
u/[deleted] Dec 29 '21
You have to hand it to them, it is... excessively clear what this does. :P
3
u/NullPro Dec 27 '21
Replace the if and elseif with while and youâve got the perfect program
7
u/torftorf Dec 27 '21
I mean is It really bad code if it works? XD
2
u/niks510 Dec 27 '21
I would never write this code but I do love its readability.
2
u/jadenash Dec 27 '21
i used to do this :')
1
u/Novinity1 shameless Dec 27 '21
yes.
1
u/[deleted] Dec 27 '21
me a year ago:
1
u/Speykious Dec 27 '21
Yet again, an instance of people (since I shouldn't say just beginners) not being aware that conditions and booleans are the exact same thing!
Edit:... Kinda. Partially. Now that I say it I don't know if simplifying the expression to
inventory.Visible = not inventory.Visibleis particularly indicative of that.1
u/TigreDeLosLlanos Dec 27 '21
There is no a single sane paradigm for GUI proggramming. You just have to prey your pasta is at least readable.
1
u/kemot10 Dec 27 '21
Wait... There is a better way to do it?
1
u/AlexLovesBeans Dec 28 '21
can you really expect any better from a roblox game dev
1
u/TrashfaceMcGee Dec 30 '21
What about this:
inventory.Visible = (inventory.Visible + 1) % 2Works especially well in strongly typed languages
1
u/bettercalldelta Jan 27 '22
inventory.Visible = not inventory.Visible
0
u/DeveloperMikey Dec 27 '21
Roblox developers be like
-1
u/bistr-o-math Dec 27 '21
NEVER EVER use an If-elseif WITHOUT a final âelseâ
0
u/[deleted] Dec 27 '21
[deleted] â view deleted comment