whaleross,
@whaleross@lemmy.world avatar

One, two and nine. Depending on the project, depending on the requirements.

drew_belloc,
@drew_belloc@programming.dev avatar

I’m the first and the last, it depends on my mood

auf,

Thief way is actually the best among all of these imo, in terms of readability and efficiency.

platypode,
@platypode@sh.itjust.works avatar

Not using thief is professional incompetence unless you’re doing something deeply cursed

GlitterInfection,

Like pair programming.

auf,

Fr. People like to reimplement wheels tho

Natanael,

Sometimes you need to minimize function calls in a tight loop, but otherwise yeah

xmunk,

Sometimes, but practically never. Just be a thief.

demonen,
@demonen@lemmy.ml avatar

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…

Aceticon,

I was under the impression that modern compilers just inline something like that, and even in older languages (like C) use 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.

el_abuelo,

Why would you be using JS in this scenario?

Natanael,

Node.js, electron 🤷‍♂️

MajorHavoc,

Good answer.

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

Edit: Not the concept of Electron, itself - but being asked to write highly performant code in Electron.

el_abuelo,

Something has gone horribly wrong if you’re trying to do such optimisations when you’ve already chosen JavaScript…let alone Electron.

Natanael,

And yet it happens, just look at the molasses that is Teams

el_abuelo,

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.

snowe,
@snowe@programming.dev avatar

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.

platypode,
@platypode@sh.itjust.works avatar

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

demonen,
@demonen@lemmy.ml avatar

Yeah, that’s my reading as well.

snowe,
@snowe@programming.dev avatar

well it’s called Thief. They’re stealing the function and making it look like they wrote it. hence max1.

Templa,

Sounds good to me

crandlecan,

I’m mostly lost and in over my head

SuperIce,

Why would you use anything other than Math.max?

SzethFriendOfNimi,

Some of us have trust issues. Or worked with Java.

Which, now that I think about it, comes to the same thing.

Zagorath,
@Zagorath@aussie.zone avatar

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.

demonen,
@demonen@lemmy.ml avatar

This is why I think school and interviews are like a whole different universe from the one where actual work gets done.

Zagorath,
@Zagorath@aussie.zone avatar

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.

Rodeo,

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?

Zagorath,
@Zagorath@aussie.zone avatar

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

hatchet,

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.

demonen,
@demonen@lemmy.ml avatar

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!

MajorHavoc,

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…

peyotecosmico,

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

PeriodicallyPedantic, (edited )

If thief is actually an option, then thief.

Otherwise probably procreator or engineer 😅😬

Edit: errrrr that was supposed to say “procrastinator” 😬dyac

TonyToniToneOfficial,
@TonyToniToneOfficial@lemmy.ml avatar

Last one should be // still a student

xmunk,

Every single entry other than thief is “still a student”

davel,
@davel@lemmy.ml avatar

Thief. Writing code is for chumps, and the more code you right, the more of a chump you are.

cheerjoy,
@cheerjoy@lemmy.world avatar

why say many word when few do trick

independantiste,
@independantiste@sh.itjust.works avatar

Why 🗣️📈 word when 😃👍

tiredofsametab,

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?

davel,
@davel@lemmy.ml avatar

It’s too late now to wright my wrongh ¯_(ツ)_/¯

kewko,

Mathematician 2 kinda blew my mind, kinda obvious, just can’t believe I was never taught or thought about it.

canihasaccount,

Yeah, that was my favorite one

mac,

Lost me when it used Math.abs after calling math.max a their

MBM,

Math.Sqrt((x-y) * (x-y)) (I’ve actually seen someone use this)

Artyom,

I’ve been staring at it for 10 minutes and I’m still not convinced it works.

uberrice,

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

maegul,
@maegul@lemmy.ml avatar

https://lemmy.ml/pictrs/image/ad47683b-e2d7-4607-97ec-7f83d468f11a.jpeg

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.

13,
@13@masto.bg avatar

@coja I am the engineer because I forget about Math.max existence

Tolookah,

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.

bstix, (edited )

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?

Natanael,

How easy will it be to explain what you’re invoicing them for?

By the hour I presume

bstix,

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.

kromem,

max6(1, 2, 3)

Man that’s going to cause some headaches…

neosheo,
@neosheo@discuss.tchncs.de avatar

Thief no doubt

BautAufWasEuchAufbaut,
@BautAufWasEuchAufbaut@lemmy.blahaj.zone avatar

Thief gang. Why stand on shoulders of giants if you’re not using it to your advantage?

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • uselessserver093
  • Food
  • aaaaaaacccccccce
  • [email protected]
  • test
  • CafeMeta
  • testmag
  • MUD
  • RhythmGameZone
  • RSS
  • dabs
  • Socialism
  • KbinCafe
  • TheResearchGuardian
  • Ask_kbincafe
  • oklahoma
  • feritale
  • SuperSentai
  • KamenRider
  • All magazines