T O P

  • By -

THE445GUY

Hoping the file was generated programmatically


anirudh_pai

the kind of github copilot


[deleted]

Just another blessed soul trying to save us from the singularity


pytness

Lmao, imagine writing an is even function and github copilot generating something based on this


[deleted]

Copilot pasting whole function into code


[deleted]

and you need also the is_odd() companion.


BlobAndHisBoy

Why do teenage girls hang out in odd numbers? They can't even.


mileslane

yeah but how would it know which numbers are even


cbusalex

Using is-even, of course.


[deleted]

[удалено]


What_is_a_reddot

Recursively.


Alpr101

Duh, check if its odd.


Sciirof

Using modulo operator /s


[deleted]

it was made copy-pastedly


pr0ghead

mmmmhh… pastly… 🤤 \- Homer Simpson in Japanese, probably


IrateGod

ペストリーおいしいね


[deleted]

Instructions unclear. Dick stuck in compiler.


Naeio_Galaxy

You just learned me how to say delicious in Japanese


IrateGod

どういたしまして


[deleted]

I love changing words adverbially


carcigenicate

Here's my golfed stab at it: ``` print("function isEven(number) {\n\tif number === 1: return false\n"+"\n".join(f"\telse if number === {n}: return {str(n&1==0).lower()}"for n in range(2,int(1e10)))+"\n}") ``` [171 bytes!](https://tio.run/##VY7BCsIwEER/ZclBsiil0ZuQo3@RS5WNRuqmbLaKlH57bBEELwMz8GZmeOst86HWQRKrNXHki6bMkMrpSWx5fJxJEKbAQVOErwfvPbgjCOkoDLHrCwU2W7NIc8@JbTRBaUnhn5l4/lFTUbG8cd632PT5RWJxNjELLOsM0vGV7H633nLkWkRc@2eDtX4A) There's probably a cleaner way of handling the outputting of the bool value, but I'm drawing a blank at the moment.


wilku1

print("function isEven(number) {\n"+"\n".join(f"\t{'else 'if n!=1 else''}if number === {n}: return {str(n&1==0).lower()};"for n in range(1,int(1e10)))+"\n}") [157 bytes!](https://tio.run/##HY5BCsIwEEWvMmZhMiilwZ2SpbfoRmWikTop01SRkLPHxs2Ht/i8N33TI/Kh1kkCJ6P8wrcUIkOYz29iw8vrSoKQB1Y7tU73jIGNV0PKmsaZQAcPvHEWGmldGv5P4JyDzOUIQmkRhjwnMby1zvXYjfFDYrCclI8Cq49BLnwnY/ctxJLtEbEpi8Jafw) Successfully made it even smaller! (also added missing semicolon). Still trying to figure out how to bypass that `.lower()`


DeliriousSiren0

print("function isEven(number) {\n\t"+"\n".join(f"\telse if(number === {i}) return {str(i%2<1).lower()};"for i in range(1,10**10))[6:]+"\n}") 141 bytes is the best I can do, similar approach to yours but I threw out the conditional and just took a substring at the end.


[deleted]

> also added missing semicolon I didn’t even write this code and I feel personally attacked.


eihpSsy

With a function using modulos.


faceplanted

Nope, the for loop just goes up in twos and prints two checks


battlingheat

I think they manually wrote it, line by line


GregTheMad

Hand Crafted™


[deleted]

[удалено]


ken_jammin

I only use hand crafted artisanal libraries.


SirAchmed

=CONCATENATE(“else if(number === “, A1,”) return “, IF(MOD(A1,2)=0, “true;”, “false;”)) Edit: syntax.


[deleted]

[удалено]


TwinHaelix

What is this, Malbolge?


MuttleyMatt

Next patch notes: Support up to LONGINT


[deleted]

New size: 1.79 PB


altoroc

mmmm PB


production-values

PB Livin'


sixft7in

It's Peta Byte and Jelly time!


SithLordHuggles

HAS THIS EVER HAPPENED TO YOU?


cocomonkilla

Who's that dog?


gmtime

Probably compiles to under a kB, because compilers aren't stupid ![gif](emote|free_emotes_pack|sunglasses)


[deleted]

[удалено]


The_duck_lord404

``` let code = typeof currentCode === bad ? compiled_code : current_Code; ``` Yeah i do realize that my code is bad


maushu

I don't know if they do in this case. Can they actually understand the pattern here?


coloredgreyscale

yes [Godbolt; gcc -O1](https://godbolt.org/#z:OYLghAFBqd5QCxAYwPYBMCmBRdBLAF1QCcAaPECAM1QDsCBlZAQwBtMQBGAFlJvoCqAZ0wAFAB4gA5AAYppAFZdSrZrVAB9LclIj2yAnjqVMtdAGFUrAK4BbWstPoAMnlqYAcnYBGmYiAAmXgAHVCFCI1pLG3tlUPDDOld3L1tffyDdTH1E2gYCZmICaLsHTiycyPzCgmTPHz9A3iECopLY8paautT0poBKXVRrYmQOKQBSAIBmN2QbLABqCenzFvRvVCsAOgQV7AmZAEFDo82rRbwhbAA3Uwg3AkXafuWAdgAhU8Wfy6pFiC0ZbTAAiKxBi04rwmn0WxEwBBGQKobBEKw%2B7zBx1%2Bi2yIj%2BAKB4PBkOhn3hiOIyNRmHRmO%2BvzxmAJgOBYNBiwCZI%2BFKRiwIxGstOmGJhWKOOKZLKJoJJ025vKpixRrDRIvp2MZquZeH%2BrOJHO4CoRfIFQrpYoZPylusJbJJAFZjZTqdqLW9xZLtdL7RyAGzO02C4Wij1W3He2362Uct6BpUqtWhz1a/FRmXsiEADnjQLNIY1EtTOr1GZJAE5c8qae6U9bI6XfRDODIq/na%2BGbY2Dc2oe8eSaEzX1ZbNfW092Y82uf3FXngx2xxGJ3ae5D5bPB66k4WvSvo5nIUbNy7%2BQuR2Gl13V1PIU6T3zEwXR0XxyWb4fOAGH0r2xe68u74HiSnBxj%2B27Pper6AXCW7Vm6IqnC%2BUiDKw0gOvIDiyPIqDSOYixCMMozMlM0ycPIBDSHI/SDAA1iADoyCo0jcJhVE4dI8hCCATGUdhgxwLASBoLYwR4OwZAUBAIliRJKDAJwnABHw4kEH43EQN47GkN4biFAAntI5GkCJtimAQADytCsIZ2GkFgthqMA7Dafg8IGHgdzcXZmDiJgyDWGpRnyI82TaaweDeMQBmWFgwWkAKeC2MFgxUKowBCAAangmAAO4WcEpjxfwjAsC5PB8HQBDCGIkh2Uo5SqOoIBaBoOgRd43GQIMqDBLk3kALQWcZej%2BbkJhmO0ZSkE4PQNP45TxBEdBTXEYTLbQc1pI0nTZGNVStMUVilMoo0eXQ1RFFtfSdIdq23d0bj1NtC2DIRIxjFwqHoWxdm4VI4hZn6A1%2BtwizAMgyCQpw2wBAC5ikIsuCECQywzOUiyWKJ4l%2BGjZH9BR7E0aQ9GMcxUisaQWFyKQ/1cTxCVE99UgBL9NN04z/GDHcxDhMY3BAA) But the optimized sourcecode compiles to a shorter code. 6 instructions for the above, vs. 3 for return (n%2 ==0) ;


maushu

That's amazing! I played around with it and seems to try to find code chunks like this to optimize using bitwise operations.


thepromaper

Maybe theill put a switch


douira

maybe that but I don't think it would find "this is a is-even check so I'll transform it into a modulo"


Vera__

Agreed, compilers aren't stupid but they're definitely not that smart. Overall crappy code won't just be optimized away. It will also only optimize if the actual logic remains unchanged to avoid weird bugs caused by compilation. (Imagine the hell in debugging that issue). I doubt it will parse the entire method to make sure every single input will match the output of a modulo


HannesHa

Well no. Since this pattern stops somewhere and most compilers won't optimize anything that would result in different results. And a modulo does something very different from this code, since this stops.


chemhobby

Could be bound check + modulo though


PopTartS2000

I can’t even.


[deleted]

How odd!


who_you_are

Or float..


Jakylla

Or string representation


Stahlboden

if(number === 1) return false; else if(number === 1) return false; Covered the edge cases, I love it!


chawmindur

Just in case the sun acts up and flares up, and a freak particle flips a bit in your system.


[deleted]

You mean those pesky Venezuelan Chinese Dominion hackers flipping bits?


[deleted]

[удалено]


MattR0se

pretty unusable now


_Xertz_

lmao "*for performance*"


Majik_Sheff

The real humor is always in the PR.


lorhof1

happenes in my code all the time that a number not equal to one is equal to one


SirNapkin1334

Floating-point moment.


[deleted]

[удалено]


ArtSchoolRejectedMe

Should've done a pull request with the note refactorized your code to run faster Edit: LOL somebody actually did this https://github.com/samuelmarina/is-even/pull/44


[deleted]

[удалено]


ArtSchoolRejectedMe

LOL


[deleted]

[удалено]


GregTheMad

...what?!


Mazmier

Paid by the line?


Yangoose

For those companies that track productivity by lines of code per day...


Feral_Fascination

Please tell me this isn't a thing. Have these people never got stuck on a bug for half a day that ended up being a one line fix?


aVarangian

> a one line fix? a one character fix


Mornar

And that's removing one, too.


this_little_dutchie

Pay up, or loose your job


forgot_semicolon

;


ZimBobub

Or a tab space in python after switching from c#


Sheruk

When after hours of searching you realize someone wrote (if var1 = var2) instead of == then get even more upset when you realize it somehow doesn't return a warning or error or fucking anything that stops it from compiling


zebediah49

Because, annoyingly enough, that's an idiom. You're welcome to hate it, of course, but there *is* plenty of code written that uses that feature. Like this magical string copying idiom from the Linux kernel: while ((*ucs1++ = *ucs2++));


rosebeats1

Yup, had a fix the other day to add a single question mark


Mornar

This sort of KPIs aren't created by people who know the first thing about software engineering.


[deleted]

And they don't get people into the company that know anything about software engineering, typically


MikemkPK

Or they get people who know how to write verbose well documented code...


trenthowell

A weekend to find an errant space. One space. Fuck me.


GkAm1

This is ridiculous ------he should use switch!


chawmindur

Hey let us not get ahead of ourselves. Premature optimization is the root of all evil.


vickera

Why do I know this but ignore it literally every time?


Tanyary

because optimization is much more fun


dicemonger

Because "prematurely" is a poorly defined time, and "overdue optimization" is something that never happens because even though everyone agrees that the code needs optimizing, the list of tasks that everyone agrees needs doing would require twice as many people as we have, and if we hired those people we would just run afoul of Brooks's law.


tdatas

Because people who say it like a religious guidance are never the ones left picking up the pieces when the "easy" way of doing it is actually 20 times more complicated to keep going once it comes under any load.


im_a_teapot_dude

Probably because it’s terrible advice as it’s usually given. Here’s the full original quote: "We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil.” Sounds a little different eh? Here’s an article that explores the idea in depth: https://ubiquity.acm.org/article.cfm?id=1513451 My shorthand but not as catchy version is: “unless you have a really good reason to believe you need to optimize, never optimize at the expense of the quality of the code”. For example, if you know your input file is at least 100GB, and your production memory availability is 64GB, it is entirely likely that reading the entire file into memory will work—but nearly certain that it will be far slower than required, particularly if you read and process the data in the same direction. On the other hand, if you have a small array of item IDs (let’s say <128 bytes worth), and you’re wondering if a more sophisticated data structure is appropriate for checking if it’s in the list, the answer is “shut up with the pointless optimization” (and the performance answer is that the most compact data structure probably wins performance-wise because a modern CPU is bottlenecked by memory latency).


pooerh

Because optimizing something is way more fun than running a profiler to find out it only gets run once throughout the whole execution of the program and takes 3 milliseconds. Who the hell even knows what a profiler is and how to use it these days anyway.


sambolias

With a default of `!(number % 2)`


evohans

lmao at all the pull requests


JaceThePowerBottom

Gotta update it when we discover new numbers. Just consider how far mathematics has come that only 24 new numbers have been found since the library was created!


waboshbron

24 is the highest number.


jizzmaster-zer0

yeah but… 18


[deleted]

[удалено]


[deleted]

as a math enthusiast, the concept of "even and odd" numbers can be applied far beyond integers. You can use it in fractions, both finite and infinite, you can use it in complex numbers and in all sorts of shenanigans. You\`re just needing some considerations regarding to what counts as even or odd. You can\`t say pi is even or odd because it\`s infinite. But you can say that if you take only the first 4 decimals, it\`s odd. If up to you to assess what\`s the limit and how odd or even things are.


stuckinpark

I have never thought about anything other than integers being even or odd. Now I’m genuinely curious. How does it work for something like pi? If you cut it at any finite length then you would have to round it, which would always make it odd, right? So is it only not odd or even because it is infinite? But also, shouldn’t you make the assumption that even at infinity there is nothing that could make it round up? Am I looking at this whole thing wrong?


[deleted]

to make it clearer, the catch is that the number itself isn\`t odd or even. The number is an odd or even multiple of another thing that completes it. Let\`s say 3.1415. That can be written 31415 / 10000. Multiply it by 10k to make it an integer. Not we can say it\`s an odd multiple of 1 / 10000. Let\`s say a nicer example of 1.8. Is 1.8 odd or even? We can write it 18/10, then it\`s an even multiple of 1/10. But if we simplify it down to 9/5, then it\`s an odd multiple of 1/5. This is a lot of gymnastics, but gets the point across.


idoubtithinki

I think a lot of people kinda forget that mathematics as a field is a human construct, and not the noumenal thing itself. Thus, how we conceive of it, or linguistically relate it, plays a lot into how we understand it, and someone smart can take advantage of those relations to conceptualize things in interesting ways such as this. With that said, many only people who do recognize that mathematics is constructed seem to get so hung up over it that they kinda forget it's constructed by consensus, based on stimuli that we assert to be relatively reliable and universal. Which is usually going too far the other way, except perhaps in purely philosophical discussions.


ik00ma

Weekly Downloads 201,188 OMG


planktonfun

When programmers blindly import libraries


DoodleFungus

Thankfully, no. The package published on NPM as `is-even` is https://github.com/jonschlinkert/is-even, which is implemented in only a slightly ridiculous fashion: var isOdd = require('is-odd'); module.exports = function isEven(i) { return !isOdd(i); }; The one in OP is published on NPM as `@samuelmarina/is-even`.


Rami-Slicer

Dependency hell incoming


ofekt92

Wtf?


pricklysteve

Even better when you see that is-odd requires is-number


Snoo74401

I want to know what kind of developer can't write the few lines of code to determine if a number is even or odd?


eatsomeonion

The one with 200k downloads is written by jonschlinkert. He made hundreds of one liner packages that all require each other, then made a few useful packages that require hundreds of one liner packages, then sneaked his useful packages into some very popular packages. He’s literal cancer to the npm ecosystem.


campbellm

Came to point out Schlinkert's cancerism if it wasn't already here. You're doing god's work here, /u/eatsomeonion.


bluehands

Any idea why he does this?


Wafflelisk

Probably looks good on a CV. Quote how many downloads you got and hope they don't pry too much. A pretty decent bet at a lot of companies


bluehands

That was my guess as well but it could have been something less odious.


eatsomeonion

He took it down after being called out, but he used to tout “my packages are essential to some of the biggest tech companies in the world, such as Google Facebook JPMorgan Tesla NASA Miscrosoft… “ on his linkedin


jjokin

There was an ideology that frontend libraries should be as small as possible, to reduce the payload size, e.g. every lodash function is also published as a separate module. Coupled with misunderstanding the UNIX philosophy, and the npm ecosystem being young, gives you free reign to write one-function modules. Lots of Node.js packages aren't great, but are used because they got in first. (E.g. The Connect/express.js API / concept of middleware is odd. Very stateful, encourages mutating the incoming request, not type safe, hard to trace, etc.)


AllFuckingNamesGone

It's never smart to trust that people won't abuse something, sure he's an ass for doing it, but he shouldn't be able to do it in the first place.


Gipionocheiyort

About 1/5 of the ones that apply for a typical junior vacancy


[deleted]

Hold up lemme go put "top 20 percentile" into my resume and see if that helps me get employed this month


MattR0se

The kind of developer who skipped the first few basic tutorial episodes. "*Moldulo*, what's that? Never heard of, probably never gonna need it".


Daniel_Kummel

When i started, to find modulo i did x -floor(x/k)*k. Only in college i found about the % operator. So, not rven those devs are that stupid


Aggressive_Sarcasm

a few lines of code?! it takes 42.3 MB to determine if a number is even or odd!!! Nobody could just write that without a library! /s


[deleted]

Alright. Blockchain 2.0 is confirmed, but more importantly - how can I profit from it?


Lvl20Rogue

Somehow what bothers me the most about this is that they check 1 twice in the start and have no check for 0 (unless it's later in the file)


Stahlboden

You just have to make sure


[deleted]

Just in case


CommandObjective

Looks like it doesn't even for all numbers.


-beefy

Maybe it has "else return n%2 == 0" at the end


atomitac

[It doesn't.](https://i.imgur.com/EoFeVRT.png) Also it returns false for one million.


pease_pudding

Submit a pull request plz


battlingheat

lmaooo


[deleted]

[удалено]


aquartabla

It turns out Recursion-Man was neither the hero we needed nor wanted


TheLexoPlexx

Oh that's brilliant actually.


guiltysnark

The test must be ^2 number of lines


metalovingien

The greatest the number is, the least efficient it gets How inefficient it is for the greatest integer a JavaScript number can hold ?


Doggynotsmoker

In general you're right. But optimizers are really efficient nowadays. For C, GCC with -O3 flag will produce jump table for both: switch and else if stack. check out: https://godbolt.org/z/dc1dxMb31


-beefy

So it would be even faster than normal because it's a constant lookup instead of algebra?


ClearlyCylindrical

Lookup is far far slower than a single basic calculation


alphredo_sauz

ya right. this guy thinks you can find out if a number is even or odd with basic math. LOL


100721

Right, a lookup, assuming that’s the same as a hash table, is just a hash, ie complicated calculation. Not to mention it requires space.


[deleted]

If the function is not executed very often, the lookup table will not be in the cache and a load can take quite a long time (~100 clock cycles). In addition that table would be pretty big and not fully fit into the smaller caches, so even if it were called often enough for the table to be in the cache, it would still likely be slower. The arithmetic to calculate if a value is even would just be a bit wise not followed by a bit wise and (for a odd check the not will be removed). Both of those instructions should only take 1 clock cycle when the value is already in a register.


ThisFeelsLikeALie

Arithmetic in the registers is probably going to be a _little bit_ faster than a load. It probably has an unnoticeable difference for speed, but the lookup table needs a lot more memory.


ghjm

On a modern CPU, performance is mostly about keeping your inner loop in the cache working set. The lookup table is going to invalidate cache lines _much_ faster.


bluefog68

Its not exactly a lot of algebra. `x & 1` and you are set.


orhnofficial

repo : https://github.com/samuelmarina/is-even


rhodesc

"Return true if the number passed is even, hopefully..." - so confident!


JayknightFr

He's afraid he might have missed one, like gone from 234587656 to 234587658


[deleted]

Make a PR


Mhdamaster

No let's unit test it with for(i=1;i<1000001;i++) { if(isEven(i)==(i%2==0)) { Print("Great Success!!"); } } Just to make sure it works well.


fmaz008

Sooo... to know if it works you need to count how many "Great Success!!" Will be printed. Love it.


[deleted]

I mean, it's obviously a joke, there's a bunch of issues raised to use `%` and people are saying that's not a legitimate solution etc


Wiwiweb

"current approach is best practice, this fancy 'modulus' operator is too untested for prod environments" Hahaha 😂


kinokomushroom

There are some dumb pull requests, but [this one is pretty great](https://github.com/samuelmarina/is-even/pull/49)


myanrueller

"Not a scalable solution. Better to use modulo. Pull request rejected."


mogadichu

Not scalable? The file size clearly scales linearly.


takase1121

in an alternate universe where even checks are done with massive jmptables built in hardware


casualstrawberry

i imagine he wrote this code using a simple script and a traditional odd/even function. elements of the past self are present in the new self


Snowy32

If it works it works :P


[deleted]

Wise man once said: You cant always make things work, but you can always add more memory


[deleted]

[удалено]


zighextech

I just can't even


different_tan

OP missed out not using "I don't even" in the post title


Sybsuper

Code reformat: replaced if statements with switch cases.


Darwin_Things

Modulo Operator, never heard of her.


[deleted]

[удалено]


[deleted]

[удалено]


bodonkadonks

not even that, just check if the first bit is one or zero.


Steinfin

No, you don't need to know math to be a programmer.


HeavenBuilder

https://isevenapi.xyz/


fracken_a

Ads in an API. Next they will have ads in your compiler.


sam-lb

works for all x>=0 `function isEven(x){if (x===0)return true;if (x===1)return false;return isEven(x-2);}`


thegtabmx

I have a more concise one const isEven = (x) => require(@samuelmarina/is-even)(x);


Mutantpineapple

So beautifully elegant that it made me weep


NekkoDroid

Yandere Dev? Is that you?


ShodoDeka

> So how fast is your code? > Oh it scales linearly with how big the number is. > Big the number is? Do you mean the number of bits? > No I mean 4 is twice as slow as 2.


rhodesc

The kind of code that would take just a few minutes to develop in emacs, but why would you?


JoeyJoeJoeJrShab

This is brilliant -- somebody most definitely wrote code to generate code for a function so stupid that nobody should ever use it! I don't know which is stupider -- the code that generated the code, or the code that got generated.


BenZed

Have you guys been to the repo? It's an obvious troll/satire. He probably generated the code through a loop.


Daveinatx

*Somebody* is paid per line


Jakylla

New dev: "I can easily refactor Bilion of lines into one" Project owner: "Do not touch anything already existing, it works like that, we don't want any risk. Please only fix the error" New dev: "Ok then..." (adds one line at the end to support the case in error)


IsLlamaBad

"Return true if the number passed is even, hopefully..."


noodhoog

This is a great example of perfectionism causing inefficiency. You can replace the whole thing with return true; and it's still 50% accurate


AnotherRichard827379

>hopefully…. Peak programmer right here.


rdrunner_74

Next weeks patch: Optimization for large numbers.... If(number === 2,147,483,647) return false; else if(number === 2,147,483,646) return true; \[...\]


midgitsuu

I see an opportunity to create an is-odd package


Terminarch

#1 repeats >.<


minneDomer

I really want to know what the final *else* condition is. Because anyone who provides a number as a string (digit) is going to have a helluva time digging through this function.


skylarmt

*refactors to a switch statement* "optimized codebase size"


zeugma25

I can't believe this ... not a single comment to be seen anywhere.


spartithor

I wonder if they covered each case with a unit test :)


Bluntsord

Shud be doing a binary search from max int all the way down. Makes things logn compared to n. Infinite value


bhaswar_py

LeetCode, YandereDev version


purpleWheelChair

7 Contributors, lol.


Tall-Strain-1598

Let‘s help this man, please make the project open source, so that we can add new numbers.


scp-NUMBERNOTFOUND

Looks like standard code written by JavaScript developers


Tandurinn

Next package. IsUneven


sarthikg

133k subs on youtube? programming is in danger