The absolute state of "the greatest Ruby programmer of all time"
>half of Jow Forums won't find the huge flaw in this program
The absolute state of "the greatest Ruby programmer of all time"
>half of Jow Forums won't find the huge flaw in this program
Other urls found in this thread:
programiz.com
en.wikipedia.org
twitter.com
>return num3
Should be who the fuck uses Ruby.
kek >=
closing bracket?
me c programer me dont understand
me think is correct
>the greatest Ruby programmer of all time
What does your pic have to do with that?
>10+ minutes and nobody has spotted the flaw yet
make that 90% of Jow Forums
what's the error
Is it about nan or inf? Or about repeated tests ?
Look at the logic, not at the syntax, brainlets
the problem here is clear; the programmer believes coloring is going to make them program any better
what's wrong with the logic sir?
please enlighten us sir.
num2 >= num1 is unnecessary?
what's won't with the logic? In which case does it return a false result?
>THREE 3 (three) numbers
>FOUR four (4) comparisons (does ruby even have short circuiting?)
>!!ELSIF!! not elif or else if
>def like python but also end !!!!! AFTER RETURN
>FUCKING WITH BRANCH PREDICTION TOO
KEK IM DONE
yes, Jow Forums is really brainlet board
Missing 'end' for the 'if' block
if not (a >= b) then b= num1 is not necessary how are you this much of a brainlet
if it compiles i smiles :)
OP is fucking coward for not telling what he thinks is wrong.
He didn't call you a brainlet. You got it right. He called out everyone else who didn't get it. Then again, you are not a brainlet, but you do lack emotional intelligence.
do you know how to read, I confirmed post where user said that num2 >= num1 us not necesarry
See:
is this correct guisee?
def max(a, b, c):
ret = a
if (b > ret):
ret = b
if (c > ret):
ret = c
return ret
so this is the
>huge flaw
Return statements are unnecessary, the 'if' block will return the value of its chosen branch
This is how software gets bloated. It starts with things like this.
fair enough although I think a compiler could optimize this out
Literally the only person to get it right ITT
Poor phrasing. You should explain the "and". Let me try it. If the test for (num1 >= num2 && num1 >= num3) fails, then it stands that (num1 < num2 || num1 < num3). In either case num1 can't be the maximum, so we can ignore it from now on.
def max(num1, num2, num3)
if num1 >= num2 and num1 >= num3
num1
elsif num2 >= num3
num2
else
num3
end
end
No. Software gets bloated through unnecessary features and integrations, not trivial redundant code.
Ruby is dynamic enough that you can't do it.
Check out Example #3 in this
programiz.com
You are retarded.
Redundancy can be used as a tool to help trainees understand logic better.
From what I gather in your picture, it is from a "course" video, so not only is it a justified use of redundancy, but it might be a deliberate one, too.
>huge flaw
My ass.
If I made a "course" recording, I'd plant redundancies like this everywhere purposefully. Even "advanced level" courses wouldn't be spared.
Good luck with your slippery slope though. Lovely thread.
>70074707
>LOLALOOL
A I R S P A C E
t. pajeet
>Huge flaw
ok
It was clearly a troll thread from the start.
>the greatest Ruby programmer of all time
>huge flaw
>trivial code
These are dead giveaways.
25% loss of efficiency is a huge flaw
You are getting entertaining, OP.
def max (num1, num2, num3)
return Java.import.max(num1, num2, num3)
end
ez
Not OP, just saying. There's no justification to be a shitty programmer.
Protip: If you do this in a job interview, you don't get the job.
>JRuby
a lot comfyer than OP solution
>redundancy is a flaw
Lel thanks Jow Forums, I'm no longer going to keep backups xDDD
Assignments are worse than comparisons. Each assignment is 5, each comparison is 2
Shut up pajeet, your program is bloated and slow.
nothing personal ruby
max:
cmp esi, edx
mov eax, edi
cmovl esi, edx
cmp esi, edi
cmovge eax, esi
ret
The reason why no one sees anything wrong with the code is because there really is nothing logically wrong with the code. That doesn't mean it's bad code. Like many have stated:
num2 >= num1
is meaningless, there's also a missing "end" statement, and it's written in Ruby. But other than that there is no logical error. This function will suffice for most "introductory" courses as an explanation. I've taken the bait, but literally "half of Jow Forums won't find the huge flaw in this program" sounds like a porn clickbait. So yeah this is bait.
>slow
'Cause it's in Ruby.
Reminder that American universities stopped teaching micro-optimization because millennials found it too complicated.
Here in France, you'll fail the exam if your code has redundant waste of processing power. I guess that's why French companies are now leading software development.
>that's why French companies are now leading software development
Prove it, frogger.
I laughed hard
French are only good at surrendering
Have an examples?
With one exception.
>assignments are worse
Dassault Systemes is the new industry standard
Yes, writing is a lot worse than reading.
???
Haven't seen any piece of French software in my entire life. Actually scratch that, OFF was made by a French guy.
Im sorry can you repeat that statement?
see
>Haven't seen any piece of French software in my entire life
perhaps because you're a clueless zoomer
btfo or am i missing something here
>Reusing a variable like that
cringe
OP here, my first reply and the official mistake reveal
I meant that he forgot an "end" statement
Carry on
fucking shreked
that one compiles to the bottom one here
btw
What are you even doing?
Just do the following:
x= 1
y= 2
x > y
and then
x = 1
y = 2
x = y
and compare
None of that looks like any code posted here
isn't this a clear example of a recursive function enabling you to compare a much bigger amount of numbers?
???
Try both:
int max (int x, int y, int z) {
if (x > y && x > z)
{
return x;
}
if (y > z)
{
return y;
}
return z;
}
and
int max (int x, int y, int z) {
if (x > y && x > z)
{
return x;
}
else if (y > z)
{
return y;
}
else return z;
}
why would you do that? spreading such awful lies?
Ah, he was a troll.
I had no doubt that writing does take more CPU cycles than reading. It literally says it in the instructions of any microprocessor.
But I thought it might be the compiler being retarded at handling else's or brackets.
>turning off optimizations
>l-look at m-me mom
why are you even writing in C, you should be writing in hand-made assembly then
>still not showing your compiler options
usually writing is faster because it can be done asynchronously, wbereas reads must block until the data is fetched. do the timings in your processor documentation account for dram stalls?
It was literally at -O3 for both you autist retard
you shave off 2 cycles going from -O1 to -O2,
if you are that retarded about saving cycles you would have optimizations on like -Ofast, which changes absolutely nothing going from -O3 in the assignment case.
should've include this in your screencap
but you're right
I would rather have redundant checks than too few checks.
based tertiary operator poster
btw what program is that?
le basade et rougepilled
int max(int num1, int num2, int num3)
{
return Math.Max( Math.Max(num1,num2), num3);
}
That "award" looks really disgusting. I wouldn't touch that desu.
def max(*args); args.max; end
btfo
>>def like python but also end !!!!! AFTER RETURN
fun/endfun is the patrician block style you uncultured shitter
indentation is fine too
braces is dogshit tier (especially because of retards who think the opening brace is a part of the if-statement (and also think that that if-statements with "one line" are a special case), so they put it to the right of the if as if it was a fucking python colon).
>huge flaw in this program
No comments
}
I don't know ruby so...
def mymax(first, *rest):
ret = first
for arg in rest:
if arg > ret:
ret = arg
return ret
print mymax(3,9,5,7,2,6)
>elsif
That's just wrong whatever the compiler says...
ITT Jow Forums tries really hard to nitpick a beginner ruby tutorial screenshot, and it doesn't go well.
>promoting use of redundancy code
Just fucking explain it to them how hard could the concept be?
>Grenoble
Basé
based
FUNC MAX(a,b,c)
asshole = []
asshole.push(a)
asshole.push(b)
asshole.push(c)
sort asshole
return asshole[length asshole -1]