Find yourself
Find yourself
Find yourself
Why would you use anything other than Math.max?
Some of us have trust issues. Or worked with Java.
Which, now that I think about it, comes to the same thing.
Well, the question sort of implies that you're needing to implementing Math.max
yourself, for whatever reason. Probably as an exercise. It doesn't make sense to reuse a library that implements the feature if you're explicitly being asked how you would implement it yourself.
Why would you use anything other than Math.max?
I mean, I might be being paid by the hour or my performance measured by lines of code...
TDD
undefined
const max12 = (x, y) => { if (x === 1 && y === 2) { return 2; } else if (x === 7 && y === 4) { return 7; } else { return x; } };
Thief. Writing code is for chumps, and the more code you right, the more of a chump you are.
why say many word when few do trick
Why 🗣️📈 word when 😃👍
Writing code is for chumps, and the more code you right, the more of a chump you are.
So you're the one in there wronging up my code?
It’s too late now to wright my wrongh ¯\_(ツ)_/¯
Where's the Julia programmer that hits every one of these with @benchmark and then works for six hours to shave three nanoseconds off of the fastest one?
(Example: https://discourse.julialang.org/t/faster-bernoulli-sampling/35209)
404 or walled
works here
Mathematician 2 kinda blew my mind, kinda obvious, just can't believe I was never taught or thought about it.
Lost me when it used Math.abs after calling math.max a their
Math.Sqrt((x-y) * (x-y))
(I've actually seen someone use this)
Yeah, that was my favorite one
I've been staring at it for 10 minutes and I'm still not convinced it works.
Simple, really. Abs(x-y) is the difference between the two numbers, absolute, so positive value. So, adding abs(x-y) to the smaller of the two numbers turns it into the bigger number. Plus the bigger number, now you have 2 times the bigger number
Thief no doubt
Thief gang. Why stand on shoulders of giants if you're not using it to your advantage?
Procrastinator + troll.
return x
Bit hacker 2 is really fascinating. It uses a bit mask of all 1s (-1) or all 0s (0) and takes advantage of the fact that y ^ (x ^ y) = x and y ^ 0 = y
undefined
#define max(x,y) ( { __auto_type __x = (x); __auto_type __y = (y); __x > __y ? __x : __y; })
GNU C. Also works with Clang. Avoids evaluating the arguments multiple times. The optimizer will convert the branch into a conditional move, if it doesn't I'd replace the ternary with the "bit hacker 2" version.
wtf kind of cursed programming language is this? JS? it's so ugly, in no universe should a function look like that
but obviously as a rust enjoyer i have to do it like
undefined
fn max ⟨T: PartialOrd + Copy⟩(nums: ⁊[T]) -> Option⟨T⟩ { let mut greatest: ⁊T = ⁊nums[0]; match nums.len() { 0 => None, 1 => Some(*greatest), _ => { for num in nums { if num > greatest { greatest = num; } } Some(*greatest) } } }
edit: lemmy formatting REALLY hates references and generics it seems... time to go back to medieval times
Ah yes, rust. The language that somehow manages to manages to as verbose as possible, with as much jargonized shorthand that a computer could handle.
Exactly, I don't understand why languages have decided that every keyword needs to be as randomly minified as possible.
fn
, def
, rune
(ok that's not minified, just a dumb name), fmt
, std
. Many of these things aren't new, but programmers recognize descriptive variable names are important, the same should be true for keywords.
Wow that's a very exhausting language. I dropped your code into an online rust to asm converter and it actually wasn't more! I did try to post it for fun but lemmy kept messing up the code block. Oh well, wasn't that amusing anyway!
Isn't it php?
Mathematician 3
Max(x, y) = floor(ln(ex + ey))
so 0.3 ~= 1-ln(2)=max(1-ln(2),1-ln(2)) = floor(ln(2*e^(1-ln(2)))) = floor(ln(2)+(1-ln(2))) = 1 ?
That would bee engeneer 2, not Mathematician3 xD.
Just out of curiostity, what was you Idea behind that?
Guess only work with integers, specially for the floor function that is going to give you an integer at the end everytime.
Not my idea, learned it somewhere while doing college in an statistics class. The idea is that the exponential function grow really fast, so small difference on variables become extreme difference on the exponential, then the log function reverse the exponential, but because it grew more for the biggest variable it reverts to the max variable making the other variables the decimal part (this is why you need the floor function). I think is cool because works for any number of variables, unlike mathematician 2 who only work for 2 variables (maybe it can be generalized for more variables but I don't think can be done).
For a min fuction it can be use ceiling(-ln(e-x + e-y))
Procrastinator.
Okay, but seriously: "Thief". Why reimplement it if it’s already available in the language?
Thief
And not feeling one byte bad about it :p
Master Thief const { Max: max } = Math;
Engineer I guess... Thief is the objectively better enterprise programmer option but I don't know why I always forget about it and just write a ternary ¯_(ツ)_/¯
JS instills distrust. Rely on built-in sort? It's alphanumeric. Rely on built-in reverse? It modifies your array. Copy an array? No you didn't.
Yeah no kidding we bang out a kata in a dozen characters. I don't even believe in order of operations at this point. I've been routinely betrayed.
One, two and nine. Depending on the project, depending on the requirements.
Reminded of how truly little I know about programming despite the time have spent doing it
Ugh. I'll never be any good.
Listen, in industry programming (and for personal projects if you want to get them done), the thief is the way to go. By all means, challenge yourself to understand each of these functions, but 99% of day to day development will not look like this.
How much time have you spent doing it? What part didn't you understand? If it's the bit shifting stuff, don't worry about it - hardly anyone actually knows how that works unless they look it up.
About a year with varying levels of commitment and intensity.
I kind of just threw myself into the deep end. Which was a rewarding but frustrating experience. My first project was one hot encoding 400gb of reddit porn to try and teach stylegan3 how to make porn. And then turning the function on in stylegan3. And then there was validating the images and ditching the ones that erroted. Resizing the whole datasets. Using ffmpeg to extract stills from the gifs and mp3s
I found stable diffusion existed like 5 days into actually training it which was bitter sweet. I mean. No way it would have produced actual porn but I was really looking forward to the horror.
I taught myself as I went along which is a great way to learn but it's super disheartening when I see the math that's second nature to anyone whose studied this stuff academically.. I don't like math. In fact I hate it, and no matter how skilled (or not) a coder I become I'll never learn calculus sometimes makes it all feel like a fools errand.
And then your customer changes their mind. Instead of two numbers, they will now input three numbers. How easy will it be for you to change your code?
And then the customer changes their mind. Instead of three numbers, they will now input any series of numbers. How easy will it be for you to change your code? And why didn't you already do this is the previous step?
And then the customer changes their mind. Instead of any set of numbers, they will now input numbers and text. How easy will it be to change your code?
And then the customer changes their mind. They now have no idea of what they're sending you or if they're even sending you anything. Nevermind the code now, you already did that in the previous step, right? How easy will it be to explain what you're invoicing them for?
How easy will it be to explain what you're invoicing them for?
By the hour I presume
If only you'd done the most bloated and well documented function first, you could have saved yourself the time and your client for the money.
I mean this is the kind of shit my boss would argue about. Why pay for the first attempts that didn't work.. blabla bla. He always ends up paying but it's always such a hassle.
Either engineer or bit hacker, depending on whether or not I'm trying to avoid branching.
If thief is actually an option, then thief.
Otherwise probably procreator or engineer 😅😬
Edit: errrrr that was supposed to say "procrastinator" 😬dyac
Otherwise, realistically, I’m prob the worst of all worlds … the procrastinator waiting/hoping to be the pair programmer that has hopefully remembered to just be the thief.
I'm the first and the last, it depends on my mood
max6(1, 2, 3)
Man that's going to cause some headaches...
I’m number 11.
I'm in this post and I'm offended.
Max11 is all my code. Why doesn't it work????🤔
Thief, or Procrastinator.
Last one should be // still a student
Every single entry other than thief is "still a student"
I use 8, but only when I'm operating on unsigned longs.
Yoink.
Actually I've probably been all of these at various times in my career.
@coja I am the engineer because I forget about Math.max existence
Engineer likely ends up with the smallest code. Though the hit to execution time for a branch sucks. (Pipelines and such)
Bit hacker will take the least execution time because of pipelines, but it needs more comments. Maybe something like // trust me, this works.
Why use
const max = (x, y) => x > y ? x : y
instead of
function max(x, y) { return x > y ? x : y }
?
I'm mostly lost and in over my head
here’s another mathematical approach (that has the added benefit of only working when x and y are both positive).
let f denote the linear functional on ℝ2 defined by f(1,0) = x and f(0,1) = y (and extend by linearity). then the operator norm || f || is equal to max(x,y).
2, but I'm incredibly embarrassed to say that I've had to do 9 before
9 is objectively better if you have untrusted inputs and need a stable failure mode.
That was precisely the reason. I prefer strongly typed languages languages, so it just felt gross to write that
my $max = $x > $y ? $x : $y;