Find yourself - Lemmy

One, two and nine. Depending on the project, depending on the requirements.
I’m the first and the last, it depends on my mood
Thief way is actually the best among all of these imo, in terms of readability and efficiency.
Not using thief is professional incompetence unless you’re doing something deeply cursed
Like pair programming.
Fr. People like to reimplement wheels tho
Sometimes you need to minimize function calls in a tight loop, but otherwise yeah
Sometimes, but practically never. Just be a thief.

If you’re optimizing that hard you should probably sort the data first anyway, but yeah, sometimes it’s absolutely called for. Not that I’ve actually needed that in my professional career, but then again I’ve never worked close enough to metal for it to actually matter.

That said, all of these are implemented as functions, so they’re already costing the function call anyway…

I was under the impression that modern compilers just inline something like that, and even in older languages (like C) trickeries are used to inline it (typically MAX is a macro rather than a real function, so its always inlined)

Ultimatelly it depends not just on what you’re doing but also the language and compiler you’re using.

Why would you be using JS in this scenario?
Node.js 🤷‍♂️

Good answer.

Even if it made me throw up in my mouth a little. /s

Something has gone horribly wrong if you’re trying to do such optimisations when you’ve already chosen JavaScript…let alone Electron.
And yet it happens, just look at the molasses that is Teams

Thankfully the only interaction I have with teams is when a supplier arranges the call. Once every two weeks. It grosses me out every time…and that’s the Web app.

Do you really think they have done such optimisation efforts as minimising function calls? I can’t imagine it’s required for what is actually a fairly simple frontend app. The complexity is the enabling stack on the backend.

They’re setting a variable to a function. Just use the original function. All thief does is obfuscate for literally no gain except character count.
I presumed it to be a standin for just directly using Math.max, since there’s no nice way to show that in a valid code snippet
Yeah, that’s my reading as well.
well it’s called Thief. They’re stealing the function and making it look like they wrote it. hence max1.
I’m mostly lost and in over my head
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.
This is why I think school and interviews are like a whole different universe from the one where actual work gets done.

In some ways they can be wholly different, but I don’t think this is a good example of it.

Any programmer who cannot implement “take two numbers, return the larger one” is clearly not very competent. Even though you’re never going to literally need to implement Math.max yourself at work, you are going to need basically the same types of skills. Probably 95% of the work I do day-to-day is stuff you’d learn in your first year at uni, and this just shows that you’ve got that ability.

In practice, the best interviews I’ve had usually set a slightly more complicated task as a do-in-your-own-time problem and then go through what you did in the actual interview. Problems like “read a list of names in the form , each name on a separate line, from a text file. Sort the names by last name, then by other names. Output to another text file. Include unit tests.” They wouldn’t then expect you to re-implement the sorting algorithm itself, but more want to look at the quality of code, extensibility, etc.

More basic questions like the one in the OP, or fizzbuzz, are decent as well, and a big step up from lame questions like “what does SOLID stand for? What does the Liskov substitution principle mean to you?” Even if they’re not quite as valuable as a miniature project.

In practice, the best interviews I’ve had usually set a slightly more complicated task as a do-in-your-own-time problem and then go through what you did in the actual interview.

The best interviews you’ve had are the ones where you’re doing free work on your own time?

“Work” is a debatable term. It’s not work that provides any direct value to the company, if that’s what you mean. But yes, it involves more effort on my part.

But yes. Not only does this method let me show that I’m good at what I do (far better than nonsense theory questions do), I have also found that companies that use this approach tend to come across as a better fit in other ways during the interview process.

I think you can probably make the question a lot more interesting by asking them to implement max without using any branching syntax. I’m not saying that is necessarily a good interview question, but it is certainly more interesting. That might also be where some of the more esoteric answers are coming from.
For me, a good interview is a dialogue where the company representative shows me as much about the company as I do about me as a candidate. Take-home tasks are okay, I guess, but I suspect they might balk at me requesting they handle a mock HR issue, or whatever, for me!

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…

I’m in this post and I’m offended.

If thief is actually an option, then thief.

Otherwise probably procreator or engineer 😅😬

Last one should be // still a student
Every single entry other than thief is “still a student”
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 not to wright my whrong ¯\_(ツ)_/¯
Mathematician 2 kinda blew my mind, kinda obvious, just can’t believe I was never taught or thought about it.
Yeah, that was my favorite one
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)
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

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.

@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.

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.

max6(1, 2, 3)

Man that’s going to cause some headaches…

Thief no doubt
Thief gang. Why stand on shoulders of giants if you’re not using it to your advantage?
#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.

kinda strange solution in that you are replacing one library function with another…
__auto_type is a compiler builtin, not a library function. It’s not a function at all, the parentheses are for precedence & grouping.
Max11 is all my code. Why doesn’t it work???🤔