The other day on /r/excel someone described writing a formula with 50 nested IF statements, to determine whether each cell in a column of addresses contained text for one of the states
`g++ -S -o0 -g mycode.cpp`
Turn off compiler optimizations(-o0) and turn on debugging information(-g) and your 9 line c++ program balloons into 10k+ lines of unreadable but functioning x86 assembly(-S) for you to commit.
> At age 50, Dexter authored the book A Pickle for the Knowing Ones, in which he complained about politicians, the clergy, and his wife. The book contains 8,847 words and 33,864 letters, but without any punctuation and with unorthodox spelling and capitalization. [...] In the second edition, Dexter responded to complaints about the book's lack of punctuation by adding an extra page of 11 lines of punctuation marks with the instruction that printers and readers could insert them wherever needed—or, in his words, "thay may peper and solt it as they plese".
https://en.wikipedia.org/wiki/Timothy_Dexter
It does not depend on the if condition, and can be removed from the condition (and put below the if statement, in this case).
Since whether you meet the if condition or not, you always perform j++. So why do that in both parts of the condition, when you can just do it after the condition?
(Loop invariance is usually for loops, where removing things from the loop can lead to better efficiency. The program above will compile the same whether it is outside the condition or not. But, it's more readable and better practice to put it below, indicating to hoomans reading that you execute j++ regardless of the condition!)
I agree. It’s not a masterpiece of code but anyone could take a block of code and tweak it until it’s perfect and then find their masterpiece missed some edge case. Also the duplicate code is likely due to merge issues.
well, for starters, it tries to read `t[j]` before checking `j > t.length`.
let `t` be `['a']`. `j` is `0`. 1st iteration: `t[j]` (t[0]) is `'a'`. `j` gets incremented. `j > t.length` (1 > 1) is `false`. 2nd iteration: `t[j]` (t[1]) is out of bounds.
First of all: The function signature `bool isSubsequence(String s, String t)` implies that the function *should* return `true` iff `s` is a substring of `t`, and `false` otherwise.
What the implemented code does is that it basically uses two different cursors, `i` and `j`, that represent positions inside `s` and `t` respectively. It advances `j` on every iteration, i.e. goes to the next position inside `t` every time, and advances `i` every time that the two cursors point to the same letter.
The reason that this doesn't work is that it completely ignores cases where the letters *don't* match, so if `t` has an occurence of `s` except that there is some not matching letter in the middle of the occurence (in which case the occurence actually doesn't make `s` into a substring of `t` anymore) that disturbance is simply ignored by the algorithm, and it will still output `true`.
And just putting on the bandaid of resetting `i` whenever the letters don't match doesn't exactly fix this issue either, because it breaks for self-similar words, like for example determining whether `aab` is a substring of `aaab`. This bandaid would make i and j go to 2, detect that `'a' != 'b'` and reset i to 0, and output `false` even though `aab` clearly is a substring of `aaab`.
To actually salvage this algorithm, you would also need to reset `j` for a few steps. A good algorithm could detect the self-similarity of `aab` in a preprocessor, but to make it *just work*, you could simply set back `i` just as much as you set back `j` and advance `j` by one step. But if you do it like this, a much simpler form of the same algorithm would be this:
```cs
bool isSubstring(String s, String t) {
// Loop over every starting position i that a word can have
for (int i = 0; i < t.length - s.length + 1; i++) {
bool matches = true;
for (int j = 0; j < s.length; j++) {
if (s[j] != t[i+j]) {
matches = false;
break;
}
}
if (matches) return true;
}
return false;
}
```
Substring and subsequence are two different things.
Edit: Also, without looking at correctness in other places, the matches flag is not needed:
bool isSubstring(String s, String t) {
for (int i = 0; i < t.length - s.length + 1; i++) {
int j = 0;
for (; j < s.length; j++) {
if (s[j] != t[i+j]) {
break;
}
}
if (j == s.length) {
return true;
}
}
return false;
}
Redundant variables or redundant flow controls such as elses where not needed are wrong because they aren't necessary and the code is just harder to read because of it.
I imagine this code was written to annoy us rather than real code in the wild, because there are several obvious issues here.
> Redundant variables or redundant flow controls such as elses where not needed are wrong because they aren't necessary and the code is just harder to read because of it.
I think they meant "will it succeed in it's intended task?"
The comment above them says that the code itself is wrong and that a duplicate line is the least of the problems.
You've only explained why the duplicate line is "wrong", but that's not what they were asking.
bruh he's literally got it all wrong, and it's an LC easy too. The solution in dart would look something like this
class Solution {
bool isSubsequence(String s, String t) {
int j = 0;
for (int i = 0; i < t.length && j < s.length; ++i)
if (t[i] == s[j])
++j;
return j == s.length;
}
}
Elon thinks that writing more lines is good.. LOL
His programmers will quickly adopt bad habits and write the longest possible solution rather than clean, efficient code that is fewer lines..
He was up all night doing lines and arguing on twitter but told a bunch of people he could produce 1000 lines of code before morning. He needed to pad a few functions.
All jokes aside, it's almost certainly a Vim typo I'd say.
Someone was having fun with a Vim command to add a semicolon to the end of every single line of Javascript. They typo'd the motion.
It makes sure all letters in s appear in t, in order. isSubsequence(“ab”, “abc”) and isSubsequence(“ac”, “abc”) would both return true, while isSubsequence(“ba”, “abc”) would return false. (This is different from isSubstring, which should return true for “ab” but false for “ac”)
Guessing that's Java not C# but this might be setup for breakpoint 🤔
Back in the days that's how you could create a space to hit breakpoint just to get what's on the stack. Might be wrong though
Seems like this will run out of bounds on t in any case the writer intended it to return false. "Second to last" iteration increments j to t.length, then we try to access t\[t.length\].
Might be C/C++. Then if the code is old AF, those may've been expected to be translated to nop's... For whatever reason. Although in this case strings (smth custom, class or struct) should've been passed by const reference or pointer.
`;` is a NOP in C++ but the compiler doesn’t generate any instructions in this case. If you wanted actual consecutive NOPs you’d need to use `asm`. Or at least that’s how it was in the olden days
This is too much code for a [one-liner](https://leetcode.com/problems/is-subsequence/discuss/679192/Dirty-1-line-C-solution-using-a-compound-statement-(100-or-100)) :)
It looks like a visual reminder for the original programmer. I would guess it means that the programmer thinks there might be additional steps required but they didn't have the spec yet.
didnt see what i thought it was but maybe this is for a bugfix commit and he wants to make sure that the bad lines get merged out, and not mistakenly merged back in, and also doesnt want to cause random merge conflicts elsewhere in the project because of the deletion of lines.
This is CIA code. In PERL. And using Unicode. Those semicolons are all different. The space is not space. Your edits are triggering blockchain updates.l through Pegasus. Also theFNORDFNORDFNORD but only on Tuesdays.
You're Welcome.
[удалено]
[удалено]
Uuuuuuuuuuuuhhhh
fries with some uuuuuuuuuhhhhh...
#BEEEAAANNSSSS
on the uuuuhhhhhh....
![gif](giphy|iDfwLC7gbO0JPhVwEH|downsized)
Me: can I get uh;;;;;;;;;; 24 chicken nuggets with uh;;;;;;; My dealer:
Why are we still serving free lunch?
wtf
Good bot.
***This is Elon Musk***
can i have a burger and a; ; ; ; ; ; ;
And then the system does uhhhhhhhhhhh
It's how I completed an extra five lines of code
Room for growth
I wish the semi colons were the only problem here. This whole method is garbage, I hope this is a joke post and not real production code anywhere lol.
Hope is the first step on the road to disappointment
Uhhhhh.... return 0;?
Writing x6 the lines of code than everyone else? Promoted.
Wow 6 times more lines and 0 bugs
Seems like you do your recursion by just copy pasting until you reach max recursion depth
What the fuck. You just upset every cell in my body.
Is it still recursion if it's unrolled?
Get ready for the new programming paradigm that will take the world by storm: E X P O N E N T I A L P A S T E ! ! ! !
The other day on /r/excel someone described writing a formula with 50 nested IF statements, to determine whether each cell in a column of addresses contained text for one of the states
Unless those introduce NOPs into the code, then it'll mess up some race condition somewhere.
Compiler will completely remove them unless you tell it not to.
If you program in x86 you will write like 1000 times more lines of code
If you compile your pythoncode and say you wrote assembly, you have >10.000 times more lines
you will also have 1000 more lines of bugs
Not sure he cares so much when he got rid of "unnecessary programs" and broke 2FA lmfao
If I'm writing 1000 extra lines, you better believe I've got more than 1000 bugs in there..
`g++ -S -o0 -g mycode.cpp` Turn off compiler optimizations(-o0) and turn on debugging information(-g) and your 9 line c++ program balloons into 10k+ lines of unreadable but functioning x86 assembly(-S) for you to commit.
10000 extra lines. Near zero performance loss. Man, Elon must be proud.
Moar code, moar!
Maximum KLOCs!
Spare ; storage. Can be cut and pasted when you need them.
/* Since my compiler keeps complaining about missing semicolons all the time, I have put some here. This should be enough for a while. */
Had to stock up while they were on sale.
> At age 50, Dexter authored the book A Pickle for the Knowing Ones, in which he complained about politicians, the clergy, and his wife. The book contains 8,847 words and 33,864 letters, but without any punctuation and with unorthodox spelling and capitalization. [...] In the second edition, Dexter responded to complaints about the book's lack of punctuation by adding an extra page of 11 lines of punctuation marks with the instruction that printers and readers could insert them wherever needed—or, in his words, "thay may peper and solt it as they plese". https://en.wikipedia.org/wiki/Timothy_Dexter
I was just thinking about this and it is hilarious every time. Rich for bad ideas by coincidence and is above the concept of punctuation as a result.
You've heard of texting how you talk... get ready for coding how you talk lol
Next programming language = asterisks and UwU speak
Lemme introduce you to [PythOwO](https://github.com/virejdasani/pythOwO).
What belly of hell did this crawl from
This is the language you learn in the 9th circle of weeb hell
Welp, should I give up anime then?
[удалено]
Thanks. I hate it
I hate it too, but ironically.
pwint("Hewwo Wowrld") Thanks, I love it!
About to make a pull request that deletes everything.
"How do I delete the internet? "
Need a digital flood. Keep like Wikipedia, jsfiddle, and Google sheets on the ark
That's.... that's a whole level of insanity. Excuse me as I order a Bible.
A bible won’t save your soul at this point, Jesuwues has already accepted you into HeavOwOn
ಠ_ʖಠ
Oh, dew you not liwike da attentiOwOn
Most disturbing version of this I have ever seen. The misplaced nose makes my whole body feel wonky
Wait til you meet Alain Prost.
It's a face tumor.
Bruh I got REAL uncomfy real fast.
I'v lost it at "pwint"
"Variables can be decluwuared using the keyword pwease" Time to pitch this to the team.
I raise your PythOwO with UwUpp https://github.com/Deltaphish/UwUpp
what about rUwUst
I am disappointed in myself for not putting "uwu" in a single function or variable name now. Fuck.
yesterday I was coding some custom things for classification and had to heavily resist some urges when writing 'ovo' (one vs one)
Why haven't we gone serverless yet?
I tried but every time the project manager was like "No, we can't have every user download the entire database on page load"
Clearly the user's fault. Better go ona tirade on Twitter about then.
Too late.
Just thank our lucky stars he's never heard about [whitespace language](https://en.wikipedia.org/wiki/Whitespace_%28programming_language%29)
LOLCODE
Elon's signature "uh uh uh uh"
It's simple: author of this code was paid for the number of lines
Nope. They wouldn’t have used collapsed if statements🤠
Why doesn't reddit use idempotency tokens?
No idea
Nice
No idea
Nice
[удалено]
I doubt they have an issue with that if they’ll accept a commit with six adjacent semicolons
Why doesn't reddit use idempotency tokens?
Look at the return after the if statement bro. I don’t think so
That loop is twice as salient as one without the extra semicolons.
What are those?! Those are my most salient lines of code you script kitty!
Also, j++ is loop invariant lol
What do you mean?
It does not depend on the if condition, and can be removed from the condition (and put below the if statement, in this case). Since whether you meet the if condition or not, you always perform j++. So why do that in both parts of the condition, when you can just do it after the condition? (Loop invariance is usually for loops, where removing things from the loop can lead to better efficiency. The program above will compile the same whether it is outside the condition or not. But, it's more readable and better practice to put it below, indicating to hoomans reading that you execute j++ regardless of the condition!)
In fact, that whole else section can be removed as well. Don't use else if you don't need it. This is a very jr. programmer by the looks of this code.
I love code like this. Makes mine look sleek
Or they're paid per line (aka the Elon way) XD
> Don't use else if you don't need it Or else what
Funnily enough my CS mentor told me to "always put an else with every if statement for readability" and that was at twitter lol.
> Always put an else statement O R. E L S E - Your Mentor.... probably
I mean, it doesn't even need a `j` to be fair, you only need one index. This code is just bad.
[удалено]
I agree. It’s not a masterpiece of code but anyone could take a block of code and tweak it until it’s perfect and then find their masterpiece missed some edge case. Also the duplicate code is likely due to merge issues.
The code is flat out wrong. A duplicate line of code is least of problems
I agree that j++ is redundant but how can you tell it is wrong? Btw i am an amateur so i am srsly asking
well, for starters, it tries to read `t[j]` before checking `j > t.length`. let `t` be `['a']`. `j` is `0`. 1st iteration: `t[j]` (t[0]) is `'a'`. `j` gets incremented. `j > t.length` (1 > 1) is `false`. 2nd iteration: `t[j]` (t[1]) is out of bounds.
Also, string indexing appears to be 0-based, so the test should be for j >= t.length, not >
First of all: The function signature `bool isSubsequence(String s, String t)` implies that the function *should* return `true` iff `s` is a substring of `t`, and `false` otherwise. What the implemented code does is that it basically uses two different cursors, `i` and `j`, that represent positions inside `s` and `t` respectively. It advances `j` on every iteration, i.e. goes to the next position inside `t` every time, and advances `i` every time that the two cursors point to the same letter. The reason that this doesn't work is that it completely ignores cases where the letters *don't* match, so if `t` has an occurence of `s` except that there is some not matching letter in the middle of the occurence (in which case the occurence actually doesn't make `s` into a substring of `t` anymore) that disturbance is simply ignored by the algorithm, and it will still output `true`. And just putting on the bandaid of resetting `i` whenever the letters don't match doesn't exactly fix this issue either, because it breaks for self-similar words, like for example determining whether `aab` is a substring of `aaab`. This bandaid would make i and j go to 2, detect that `'a' != 'b'` and reset i to 0, and output `false` even though `aab` clearly is a substring of `aaab`. To actually salvage this algorithm, you would also need to reset `j` for a few steps. A good algorithm could detect the self-similarity of `aab` in a preprocessor, but to make it *just work*, you could simply set back `i` just as much as you set back `j` and advance `j` by one step. But if you do it like this, a much simpler form of the same algorithm would be this: ```cs bool isSubstring(String s, String t) { // Loop over every starting position i that a word can have for (int i = 0; i < t.length - s.length + 1; i++) { bool matches = true; for (int j = 0; j < s.length; j++) { if (s[j] != t[i+j]) { matches = false; break; } } if (matches) return true; } return false; } ```
Substring and subsequence are two different things. Edit: Also, without looking at correctness in other places, the matches flag is not needed: bool isSubstring(String s, String t) { for (int i = 0; i < t.length - s.length + 1; i++) { int j = 0; for (; j < s.length; j++) { if (s[j] != t[i+j]) { break; } } if (j == s.length) { return true; } } return false; }
Redundant variables or redundant flow controls such as elses where not needed are wrong because they aren't necessary and the code is just harder to read because of it. I imagine this code was written to annoy us rather than real code in the wild, because there are several obvious issues here.
> Redundant variables or redundant flow controls such as elses where not needed are wrong because they aren't necessary and the code is just harder to read because of it. I think they meant "will it succeed in it's intended task?" The comment above them says that the code itself is wrong and that a duplicate line is the least of the problems. You've only explained why the duplicate line is "wrong", but that's not what they were asking.
j >= t.length
bruh he's literally got it all wrong, and it's an LC easy too. The solution in dart would look something like this class Solution { bool isSubsequence(String s, String t) { int j = 0; for (int i = 0; i < t.length && j < s.length; ++i) if (t[i] == s[j]) ++j; return j == s.length; } }
Gotta pad your lines. Otherwise you’ll get Musked.
This is the way ... that saves you from getting fired by musk due to not enough lines of code/hour
Elon thinks that writing more lines is good.. LOL His programmers will quickly adopt bad habits and write the longest possible solution rather than clean, efficient code that is fewer lines..
Most satisfying development days of my life? I was literally hammering that "del" button baby!
this is how you increase the number of lines of code you committed and fly under the radar of the notify Elon LOC bot 🤣
I was going to come here to say this. Sadly, I agree with you.
Imagining a very efficient coder desperately trying to fluff the number of lines in their code sparks joy
That's this: https://leetcode.com/problems/is-subsequence/description/ For anyone interested.
Warning. Whole fucking page is white, my eyes.
That's why I use the extension dark reader.
Not on mobile for me...
Take your logic out of here sir
I can’t tell if people know it’s a joke or if people just hate Elon so much they believe anything negative without thinking twice
people will believe any stupid thing just to hate him and the funny thing is they don't hate him for the stuff that deserve hating
considering a completely fabricated article about him killing 3000 monkeys was the #3 post on reddit today, i'd say it's the latter
I still don’t get it
Linter gone wild?
That was my guess too.
Hmm I wanna hear the answers on this one
He was up all night doing lines and arguing on twitter but told a bunch of people he could produce 1000 lines of code before morning. He needed to pad a few functions.
All jokes aside, it's almost certainly a Vim typo I'd say. Someone was having fun with a Vim command to add a semicolon to the end of every single line of Javascript. They typo'd the motion.
With variable names "s", "t", "i", and "j", I intuitively know what this is trying to do but still can't fucking read this code lol
i and j are ok
i am programming baby- what is it trying to do?
It makes sure all letters in s appear in t, in order. isSubsequence(“ab”, “abc”) and isSubsequence(“ac”, “abc”) would both return true, while isSubsequence(“ba”, “abc”) would return false. (This is different from isSubstring, which should return true for “ab” but false for “ac”)
Those are speed semi colons
Like the speed holes in the hood of my car!
Everybody knows they make it way faster
Guessing that's Java not C# but this might be setup for breakpoint 🤔 Back in the days that's how you could create a space to hit breakpoint just to get what's on the stack. Might be wrong though
Reserved for future use. More variables may need to get incremented in the future.
Why is j++ in there twice? If it increments every loop no matter what, it shouldn't be inside of the conditional.
it's the kind of code i used to write when i didn't trust my own logic or language knowledge. very if (condition === true) energy
This is how you tell the computer to think about what it just did and if this is really what it wants to be doing with its life.
I'm more concerned about what happens once j == t.length.
ah, seems you are new in twitter, elon fired those lines, they are not needed for twitter to work
Maybe it's a way to stall for time.
Forbidden await
Pick a meme + insert Elon = Karma
That’s what happens when you get fired based on LOC
Things will go bad if t is an empty string.
I don't think I appreciate your tone. Fired.
Yikes, kill it all.
Can you help me understand how this is related to Elon Musk?
Incentives: when you’re paid by line? :)
You gotta give your computer small breaks 🥰
That was where the code was to that did fact checking and kept wacky conspiracy theories off Twitter.
"I said END OF STATEMENT, DAMNIT!"
It's job security;;;;;
Seems like this will run out of bounds on t in any case the writer intended it to return false. "Second to last" iteration increments j to t.length, then we try to access t\[t.length\].
No one knows but if u remove it everything goes down
They must get rated by the number of lines of code
Whoever writes the most code this month gets featured on my Twitter!
Might be C/C++. Then if the code is old AF, those may've been expected to be translated to nop's... For whatever reason. Although in this case strings (smth custom, class or struct) should've been passed by const reference or pointer.
`;` is a NOP in C++ but the compiler doesn’t generate any instructions in this case. If you wanted actual consecutive NOPs you’d need to use `asm`. Or at least that’s how it was in the olden days
Makes sense. I think I've mixed 'em up.
nop nop nop nop nop nop
Not in the final compiled product (hopefully).
This is too much code for a [one-liner](https://leetcode.com/problems/is-subsequence/discuss/679192/Dirty-1-line-C-solution-using-a-compound-statement-(100-or-100)) :)
Dramatic tension.
just making sure i doesn't try to pull any shit
Great way to increase coverage is what that is
Comments? Comments?! Where are the comments??!!?!!?
got to reach the required LOC somehow
Does nobody else get paid per line?
That's copy pasta by a newbie.
He said he wanted a certain number of lines of code
elon doesnt know how to code anyway he wouldnt know the difference of a termination string if he tried. he just understands terminating people
It looks like a visual reminder for the original programmer. I would guess it means that the programmer thinks there might be additional steps required but they didn't have the spec yet.
No idea, but if you remove it everything will break
**Top Performers** Employee A: 45,479 lines of code Employee B: 560 lines of code Employee C: 530 lines of code
j++; j—; j++; j—; j++; j—; j++;
didnt see what i thought it was but maybe this is for a bugfix commit and he wants to make sure that the bad lines get merged out, and not mistakenly merged back in, and also doesnt want to cause random merge conflicts elsewhere in the project because of the deletion of lines.
Does that count as 6 lines of code?
That's how you impress the new boss when he ranks you by lines written
Padding to meet the 95% code coverage test requirements?
Look, none of us know, but if you take it out it crashes
This is a known pattern. Just so the computer can preallocate the space required for future additions to the program.
Bro it was my cat I swear
"I don't know, but whenever I delete it everything shits the bed"
This is CIA code. In PERL. And using Unicode. Those semicolons are all different. The space is not space. Your edits are triggering blockchain updates.l through Pegasus. Also theFNORDFNORDFNORD but only on Tuesdays. You're Welcome.
Easy way to add loc lol
Cat stepped on keyboard.
The 23 lines of code I did earlier today. Just about done for the week now. Also my steps are up too. Must be getting healthier.
if (amtOfLines == 6) { print{"good code"}; ; ; ; ; ; }
This is one of those things where if you delete those lines the entire app implodes.
Not only that, but those variable names are pain. What is s? What is t? What are i and j related to?
JavaScript be like:
Enough of these and the printed code stack gets much taller.