A similar concept is making sure you understand a bug before fixing it. So often I see people implementing a “fix” that is actually fixing the symptom not the cause because they didn’t take the time to fully understand the cause before trying to fix it. The project ends up being layers of crap on top of crap u til you can’t work out what code actually needs to be there anymore.
Secretly, if, for, function calls and all control flow are jumps. I'm glad the jumps are structured into something comprehensible in higher level languages though. The main problem is dogmatism. Using loops and ifs get the job done 99% of the time and are the most readable option 90% of the time. But there are cases where direct jumps or other more unusual options are just as good or better than. Range based loops are neat when they work and they can be done without too much overhead, but making them the default or only option is just silly.
I literally just last week had a code review where I asked for a map() to be changed to a forEach() because they were just discarding the result. When asked why I said because it’s using additional memory unnecessarily and will cause slowdown as well as confusion as to why map is being used. The response I got was essentially “we are doing web development, memory management and performance doesn’t matter”. I am at a loss of how to deal with and change that mentality in the industry.
This mentality is extremely dangerous because it creates code that works at first but later creates strange behavior or performance issues that might be hard to track down.
Except it does matter. Not everyone has the latest super fast phone/computer/tablet etc. Some of those tablets (for a time anyway) were trying to get away with the lowest RAM to qualify as a device for "web surfing" but then add on whatever OS is on the device, chrome, apps you've installed, and on top of that your web app with several fat libraries and you can see why this becomes a potential problem.
This could be a valid take if both of these are true: 1. It actually doesn't matter in the given context, i.e. the additional memory is insignificant and does not leak. 2. It would be considerably more effort to do it the right way. So, if some values happen to be copied within a function, but the extra memory will be garbage collected, the function is called infrequently, and refactoring it to be more memory efficient would be extra effort... okay, it's probably fine the way it is. But using forEach instead of map _is not hard_ - so this fails #2. Basically, absolute rules don't work. We can't rule "never discard results" or "always use map" or anything, whether it's web or app or server development, because it's _always_ context specific.
"how much money are we losing because customers cant run our software, and how much money do you think we lose because a customer clicked off waiting for something to take 4 seconds to finish"
Dijkstra's basic point was about how hard it is to follow the state of a variable throughout an iterative process if you let the programmer decide the structure of the loop rather than having some standard iterative flows. Continue in this context would be just fine as it doesn't meaningfully impact that understanding.
Yeah, it just makes code harder to understand. I use goto very rarely, almost never... but there was one situation where it was more convenient than alternatives.
Also, Dijkstra was saying this in a time where people used line number based basic. As in: 10 PRINT "Hello world" - 20 GOTO 10. Before for loops, while loops etc even existed. That type of line number based programming is long gone (in part thanks to Dijkstra). Dijkstra was not wrong, he also wasn't talking about using continue in a loop. He was talking about having structured loops in the first place.
Not sure about that, early returns, breaks, and even continues interrupt control flow. If I'm looking for something specific in a codebase I won't read every function line by line top to bottom. But if I miss a return/break/continue, I can be sent on a wild goose chase. Contrast this with conditionals: A properly indented branch tells me at a glance that the part of code I'm looking at depends on some previous condition.
@@paxcoder In Fortran there was this syntax that you could only return once. Just to improve control flow and readability. I thought that achieved quite the opposite. And like you said indents really make life easy. And also gotos within a subroutine doesn’t make it hard to understand the code. People who find that disorganized probably never wrote assembly. As most of the Fortran devs when this idea of goto must go to came up.
@@paxcoderI'd rather have early returns and read the function from top to bottom than deal with the branching nature of nested if clauses in long functions. Especially when it's mutating state outside of them. Functions should be short anyway, not clean code short, but as short as it's reasonable given the situation and then it's most of the times only an early return for an assertion. Like: if(not validation.success) { return/throw whatever } ... happy path ... For my small team and I it's perfectly reasonable and if the situation arises that nested ifs are neccessary or easier to reason about we'd just use them. I haven't read a good arguement why you shouldn't use early returns, and at this point I think it's just preference. 🤷♂️ I've programmed profesionally for 5 years now and changed on many opinions and stances either through good arguments or experience. I am willing to change my mind.
1st of all goto isn't harmful. 2nd of all continue isn't a goto. I actually like how java deals with this: just label a block and then you can break out of it, and you can also break out of labelled blocks for iteration. It is exactly the same as goto but the fact that there are labelled brackets around the code that can be jumped out of or continued makes it clear what's happening and what the flow is.
Both instructions break what Dijkstra calls the "control flow" of the code. So you can't read it as a series of steps top-down anymore. That being said, break, continue have the same consequente as goto. But they're "formatted" control flow changes, as for and while loops. I don't agree with putting these instructions in the same category as goto, as harmful as goto. But it's important to understand the argument behind it
I get that people don't like goto because it can send you to basically anywhere in the code but a freaking continue is very staightforward and predictable
Personally, i think goto is fine. It's not my first choice most the time, but it's useful occasionally. And i can read code whether it has a goto or not. I don't think people need to be so scared of ... writing code. Every line has implications, whether you use goto or not.
"for loops are faster" in sane project management you would integrate speed/efficiency factors with feature implementation. However sane is not industry standard. Industry standard is to crank out the priority your project organizer breaths down your neck. In this case use map or foreach over for. Because once there is a bug it will never again be addressed, because of the next 10 feature that are breathed down your neck.
because a function returns to its next line. goto leads to a situation where variables in the current context/scope have unexpected values, potentially, if not accounted for. and accounting for it is a huge mental burden, lowering maintainability. also its more error prone.
@@astralfoxy1787 false. you have a frame pointer (ebp or rbp) and therefore, you have "functions". you should learn about the call stack (stdcall, for example). you have jumps for loops and if, but they dont count. those are well defined applications of jumps. anything outside of it qualifies as a "goto" which is clearly an anti pattern. stop trying to win a fight which has been long lost.
@@tanko.reactions176i use actual goto sometimes, and you know what? It works. I'm a programmer, and i can understand code. And i make mistakes, regardless what rules i follow, because I'm a human. And the fix is the same with goto or anything else that's broken: debug & write code.
not sure what he said, but was it something like "95% are overpaid idiots and the other 5% are the ones that do actual interesting stuffs or even just deliver" ? if so, yeah, it's not really a secret.
I said in 1996 already that web code was a cancer. If yiu understand http is a markup language means that it’s simply not designed to have interactive interaction. To get it to somewhere to that state was just bolting on crap like Java applets and later JavaScript
@@herrpez okay go ahead. But to me it’s terrible in every sense of the word. Security, speed, complexity, scalability. Oh man cgi-bin in the beginning, what a hell. Then Java applets, which was a great idea as running a cross platform vm with capabilities of a think client was okay of an idea, but it was so slow to download and run. Then JavaScript, suddenly you used 3 languages your backend language that you had to parse the request headers for post and get 😣JavaScript for frontend and sql for backend. You had to make some clever connection pools separately because it wouldn’t do that properly because a backend module request had to connect to the database and authenticate otherwise ever connection because http wasn’t stateful. Because it wasn’t tasteful you had to use cookies and separate state stores to store state. None of this you ever had to do with regular thick client programs. The web is just a heap of technology slapped together to address everyone of the shortcomings of a poor foundation.
I'd like to know how many of us have been there, and moved on. There definitely were times when I wrote contrived code which adhered to uninformed standards just to marvel at how complicated it was while still getting the job done. I think what's going on is that some programmers unconsciously treat programming like a game, instead of as an engineering discipline.
So, this is JavaScript of course. I have recently ran across a simple example in rust where an iterator was completely optimized away down to a hard coded constant but the semantically equivalent while loop was not. That clearly relies on the input being know at compile time of course which often is not the case, but I currently don’t fully understand what causes that difference. Sometimes rust hardcodes loop results as well so there is some extra difference messing it up.
Every time I see someone making an array out of a number and then looping over it with .map() to return another array of anything when simple for() loop would suffice I can't help but agree with people seeing JS devs as incompetent. You are using a bulldozer to remove a few bricks, what are you doing? Also: .filter() and .map() instead of .reduce(), because muh readability. Yet another reason to like Golang: one loop for everything, whether you like it or not. Refreshing.
in the end of the day assembly uses jumps to make flow of the code, we have an branch predict thingy in the CPU's nowdays. GOTO holds the mordern world
I searched the issue for a more resonable answer. Someone said that avoiding continue and break may enforce more immutable code and decrease function size. These are points I could understand, but it took some scrolling to get there.
Airbnb eslint rule is a plague after maintaining several codebases based on their rules. The people who copy/paste the eslint rule has literally 0 idea why they used it. "It was created by Airbnb, big tech company, must be good then". That's the 100% times I got the answer. All of their rules might work well for the airbnb codebase, but it's a premature optimization for 99% codebase outside of that, for me it's even an opinionated biased config.
Goto isn’t harmful either. It’s the most useless position to take! And people who defend it hard, don’t understand that gotos are the foundation of branching in any cpu. Every loop you program below is using a jump/branch and that’s a goto. But when you use goto just inside a single function, it’s not hard to trace. I agree it’s like break and continue and I have no problem with those either. You just don’t want to use goto over functions. This is what creates spaghetti code, because there’s no easy context. And that’s what happened mainly in basic when people didn’t use gosub. But frankly I can’t recall when I used goto in a higher level language. But in assembly jmp is my friend and I’m not getting lost in assembly either.
At work I also have devs who blindly follow absolutely everything they see in code style guides. Most annoying part is when they demand others to follow them too in code review.
Continue and break is not goto? I take offense. It is very determined and does the same thing everytime. Goto has to be maintained. I use continue and break all the time to optimize the median run time of my loops.
Imagine getting hired in a company where the "senior" devs won't approve your PRs because it has regular loops instead of these "functional" loops (and don't care about the reasons)...
No, break and continue are NOT goto! The reason that goto isn't needed is BECAUSE OF break and continue! The use of goto leaves the scope in an arbitrary way, which means defer (Go, Zig, D (called "scope exit")), and destructors (C++, Rust (called "Drop")) don't behave as expected.
forEach doesn't create another array, there's no memory allocation. You could even modify the elements of the same array you're iterating. Some devs are concerned with off by one errors and infinite loops, others are concerned with using JS for what it was not intended to (being fast), both are valid concerns.
that isnt the point. the point is that a forEach will iterate through the entire array, which binds the linear execution time to the current amount of elements in the array. Continue and break can implement early exits in iteration making the linear execution time bound to the matching case, regardless of the size of the array.
@@stayfree1776 for that you can use a for..of loop, which gets rid of the issues I pointed out like infinite loops and off by one errors. Yes, saying that break and continue are bad is dumb, I wasn't defending that idk why you got that idea from my comment.
1 Timothy 6:10 combined (misquoted by omitting "love of") with "money" replaced by "premature optimization" (Tony Hoare via Donald Knuth) but with the "about 97% of" part being omitted, so indirectly it's a misquote of a misquote of the bible.
so sick of advice just being like 'this thing is bad practice', "continues are bad practice", "goto is bad practice", "LOOPS are bad practice". Nobody actually knows why, they just parrot these things that they heard once and act like they're smarter. 'GOTO considered harmful' was written before we even had standard control flow like 'for', 'while', 'if else', so a loop would just be 'label: foo(); goto label;', and that this hard to understand when the entire code base is written like that. Djikstra was just advocating for standard control flow, and nowadays 'goto' (and continue/break) are harmful is used where standard control flow could be used instead (looking at all the juniors who write 'while (true) { ... break; }' instead of just putting the break condition as the while condition' loops being 'bad practice' in js is just the result of js andy's who don't actually know how to code going 'if you use iterator methods its only one line!! the fewer the lines better!!' and then teaching juniors 'loops are bad practice', and then those juniors taught other juniors and so on. 'premature optimization is the root of all evil' should be replaced with 'premature abstraction is the root of all evil'. if you can get something done with a boomer 'for (i' loop, do it that way. the end user doesn't see how many lines of code it is. they're not impressed by your 'array.map().reduce().suck().fuck().cum()'.
A few hours ago I just stumbled across an article about Chesterton fence, then the first youtube video I watched ThePrimeagen mentions it... It's been a recurring thing in my life. Maybe I should start a religion... Who's the revealed prophet, you asked me? ThePrimeagen is his name. I'm not working and studying too many hours until lack of skill syndrome becomes impostor syndrome. I'm completely sane, for now. That's what they are saying to me.
Just an fyi, it’s because the google algorithm knows what you’re searching and what you’re looking at in chrome. It then uses that info to feed you relevant content on other google entities like youtube. It isn’t a coincidence
It's not the loops, it's the mutation. Once you get used to using expressions and values, debugging imperative mutating code is vertigo inducing. I want to solve business problems, not play stupid pointer games.
If you look at how I'm using the continue statement, you will start to think they are harmfull xDDDDD while (i < argc) { if (strcmp(argv[i], "--json") == 0) { json_flag = 1; i++; continue; } if (strcmp(argv[i], "--debug") == 0) { debug_level++; i++; continue; } break; }
@@sub-harmonik I mean if i is initialized to 0 it definitely wouldn't hit continue. It would fall through and hit break since the name of the program isn't --json or --debug. But assuming i was correctly initialized to 1, then if you had any other flag before these two, it would fall through and break without going through the rest of the args.
Most people won't need to care about performance for the majority of the loops they would need to make. In this case, when you know what you doing and have a case for needing more performance... then go ~to~ for loops!
Prime got stuck on not using regular loops haha. Its common to consider not using break and continue or more than 1 return as good practice and instead the break conditions should be in the loop condition and if statements organized for operation control. The reasoning is to avoid hidden program flow, especially in a large chunk. It doesn't inherently discourage use of normal loops though. There can be a performance hit to not using continue, break, more than 1 return (but usually in C or other compiled languages this usually isn't the case because they can optimize it back to its continue/break equivalent, not sure about something like JS though)
The avoidance of break continue and multiple returns can not only hit performance but can also lead to unnecessary if statements which make the code much harder to read.
@@mudi2000a I've run into multiple times when working on a large loop that having early breakout really took a long time to track down, I even dislike throws for that reason (anything that is not default, well defined program flow), but its mostly personal preference. Both ways have their pros and cons.
If the break statement is something that happens only at the start or the end of the loop then it should probably be done as part of the loop conditions (even then it might sometimes be more readable as a separate statement - a loop like for(int i =0; i
Let me tell you why: 95% of us don't need to write code that iterates over millions of items. 99% of the collections my code has to iterate over contain 20 items at most.
@@ITRThe cognitive load of an iterator is smaller than a loop. That is why people recommend using them. Then use map/filter/reduce to transform your data, which makes the code much easier to reason about than a custom for loop with a bunch of temporary variables and if statement and what not.
A similar concept is making sure you understand a bug before fixing it.
So often I see people implementing a “fix” that is actually fixing the symptom not the cause because they didn’t take the time to fully understand the cause before trying to fix it.
The project ends up being layers of crap on top of crap u til you can’t work out what code actually needs to be there anymore.
Secretly, if, for, function calls and all control flow are jumps. I'm glad the jumps are structured into something comprehensible in higher level languages though. The main problem is dogmatism. Using loops and ifs get the job done 99% of the time and are the most readable option 90% of the time. But there are cases where direct jumps or other more unusual options are just as good or better than. Range based loops are neat when they work and they can be done without too much overhead, but making them the default or only option is just silly.
The "When used incorrectly" makes this even more funny. You could say the same about JS itself, is that a reason to ban JS? (It is)
I literally just last week had a code review where I asked for a map() to be changed to a forEach() because they were just discarding the result.
When asked why I said because it’s using additional memory unnecessarily and will cause slowdown as well as confusion as to why map is being used.
The response I got was essentially “we are doing web development, memory management and performance doesn’t matter”.
I am at a loss of how to deal with and change that mentality in the industry.
Ask this counter-question:
"Why should map be used instead of forEach?"
This mentality is extremely dangerous because it creates code that works at first but later creates strange behavior or performance issues that might be hard to track down.
Except it does matter. Not everyone has the latest super fast phone/computer/tablet etc. Some of those tablets (for a time anyway) were trying to get away with the lowest RAM to qualify as a device for "web surfing" but then add on whatever OS is on the device, chrome, apps you've installed, and on top of that your web app with several fat libraries and you can see why this becomes a potential problem.
This could be a valid take if both of these are true:
1. It actually doesn't matter in the given context, i.e. the additional memory is insignificant and does not leak.
2. It would be considerably more effort to do it the right way.
So, if some values happen to be copied within a function, but the extra memory will be garbage collected, the function is called infrequently, and refactoring it to be more memory efficient would be extra effort... okay, it's probably fine the way it is.
But using forEach instead of map _is not hard_ - so this fails #2.
Basically, absolute rules don't work. We can't rule "never discard results" or "always use map" or anything, whether it's web or app or server development, because it's _always_ context specific.
"how much money are we losing because customers cant run our software, and how much money do you think we lose because a customer clicked off waiting for something to take 4 seconds to finish"
Dijkstra's basic point was about how hard it is to follow the state of a variable throughout an iterative process if you let the programmer decide the structure of the loop rather than having some standard iterative flows. Continue in this context would be just fine as it doesn't meaningfully impact that understanding.
Yeah, it just makes code harder to understand. I use goto very rarely, almost never... but there was one situation where it was more convenient than alternatives.
Also, Dijkstra was saying this in a time where people used line number based basic. As in: 10 PRINT "Hello world" - 20 GOTO 10. Before for loops, while loops etc even existed. That type of line number based programming is long gone (in part thanks to Dijkstra). Dijkstra was not wrong, he also wasn't talking about using continue in a loop. He was talking about having structured loops in the first place.
Not sure about that, early returns, breaks, and even continues interrupt control flow.
If I'm looking for something specific in a codebase I won't read every function line by line top to bottom. But if I miss a return/break/continue, I can be sent on a wild goose chase.
Contrast this with conditionals: A properly indented branch tells me at a glance that the part of code I'm looking at depends on some previous condition.
@@paxcoder In Fortran there was this syntax that you could only return once. Just to improve control flow and readability. I thought that achieved quite the opposite.
And like you said indents really make life easy.
And also gotos within a subroutine doesn’t make it hard to understand the code. People who find that disorganized probably never wrote assembly. As most of the Fortran devs when this idea of goto must go to came up.
@@paxcoderI'd rather have early returns and read the function from top to bottom than deal with the branching nature of nested if clauses in long functions. Especially when it's mutating state outside of them.
Functions should be short anyway, not clean code short, but as short as it's reasonable given the situation and then it's most of the times only an early return for an assertion. Like:
if(not validation.success) {
return/throw whatever
}
... happy path ...
For my small team and I it's perfectly reasonable and if the situation arises that nested ifs are neccessary or easier to reason about we'd just use them. I haven't read a good arguement why you shouldn't use early returns, and at this point I think it's just preference. 🤷♂️
I've programmed profesionally for 5 years now and changed on many opinions and stances either through good arguments or experience. I am willing to change my mind.
1st of all goto isn't harmful.
2nd of all continue isn't a goto.
I actually like how java deals with this: just label a block and then you can break out of it, and you can also break out of labelled blocks for iteration. It is exactly the same as goto but the fact that there are labelled brackets around the code that can be jumped out of or continued makes it clear what's happening and what the flow is.
Both instructions break what Dijkstra calls the "control flow" of the code. So you can't read it as a series of steps top-down anymore.
That being said, break, continue have the same consequente as goto. But they're "formatted" control flow changes, as for and while loops.
I don't agree with putting these instructions in the same category as goto, as harmful as goto. But it's important to understand the argument behind it
BOOMER LOOPS!
Honestly expected boomer loops to be jumps. I must be old.
@@dmitriyrasskazov8858
Depends on which code level you contemplate. Jumps/ Gotos on the lower levels. For on the higher levels.
@@dmitriyrasskazov8858missionary loop!
"Missionary loops" had me rolling
The loops were unrolling
this comment is so underrated@@Haitaish
airbnb style guide is dumb, I am so happy to know that I am not the only one who thinks so
I get that people don't like goto because it can send you to basically anywhere in the code but a freaking continue is very staightforward and predictable
So isn't goto, until it isn't
Personally, i think goto is fine. It's not my first choice most the time, but it's useful occasionally. And i can read code whether it has a goto or not. I don't think people need to be so scared of ... writing code. Every line has implications, whether you use goto or not.
"for loops are faster" in sane project management you would integrate speed/efficiency factors with feature implementation. However sane is not industry standard. Industry standard is to crank out the priority your project organizer breaths down your neck. In this case use map or foreach over for. Because once there is a bug it will never again be addressed, because of the next 10 feature that are breathed down your neck.
So why we use "functions" if it's GOTO too.
If that "type" of guys decide what JS is - that's can explain A LOT. LMAO
because a function returns to its next line.
goto leads to a situation where variables in the current context/scope have unexpected values, potentially, if not accounted for. and accounting for it is a huge mental burden, lowering maintainability. also its more error prone.
@@tanko.reactions176 DUDE in assembly you HAVE NOT "SCOPES", its just a TEXT
@@astralfoxy1787 false.
you have a frame pointer (ebp or rbp) and therefore, you have "functions".
you should learn about the call stack (stdcall, for example). you have jumps for loops and if, but they dont count. those are well defined applications of jumps. anything outside of it qualifies as a "goto" which is clearly an anti pattern.
stop trying to win a fight which has been long lost.
@@tanko.reactions176i use actual goto sometimes, and you know what? It works. I'm a programmer, and i can understand code. And i make mistakes, regardless what rules i follow, because I'm a human. And the fix is the same with goto or anything else that's broken: debug & write code.
addicted to prime videos while taking a dump
you know..... Jonathan Blow might have been right about web jobs
not sure what he said, but was it something like "95% are overpaid idiots and the other 5% are the ones that do actual interesting stuffs or even just deliver" ? if so, yeah, it's not really a secret.
You can attribute most of that to JavaScript, to be really honest
I said in 1996 already that web code was a cancer. If yiu understand http is a markup language means that it’s simply not designed to have interactive interaction.
To get it to somewhere to that state was just bolting on crap like Java applets and later JavaScript
@@CallousCoderI've lived the web since the 90s, and I would love to tell you how utterly wrong you are. But you are right, so I won't. 😉
@@herrpez okay go ahead.
But to me it’s terrible in every sense of the word.
Security, speed, complexity, scalability. Oh man cgi-bin in the beginning, what a hell.
Then Java applets, which was a great idea as running a cross platform vm with capabilities of a think client was okay of an idea, but it was so slow to download and run.
Then JavaScript, suddenly you used 3 languages your backend language that you had to parse the request headers for post and get 😣JavaScript for frontend and sql for backend. You had to make some clever connection pools separately because it wouldn’t do that properly because a backend module request had to connect to the database and authenticate otherwise ever connection because http wasn’t stateful. Because it wasn’t tasteful you had to use cookies and separate state stores to store state. None of this you ever had to do with regular thick client programs.
The web is just a heap of technology slapped together to address everyone of the shortcomings of a poor foundation.
I'd like to know how many of us have been there, and moved on. There definitely were times when I wrote contrived code which adhered to uninformed standards just to marvel at how complicated it was while still getting the job done. I think what's going on is that some programmers unconsciously treat programming like a game, instead of as an engineering discipline.
I think part of the problem is many of the so-called clean coding gurus give bad advice that makes its way into coding standards documents.
Less a game, more a religion, I would argue. In many cases it's about dogmatic and unquestioning adherence to bad ideas.
So, this is JavaScript of course. I have recently ran across a simple example in rust where an iterator was completely optimized away down to a hard coded constant but the semantically equivalent while loop was not. That clearly relies on the input being know at compile time of course which often is not the case, but I currently don’t fully understand what causes that difference.
Sometimes rust hardcodes loop results as well so there is some extra difference messing it up.
Even goto have good uses in c#, for exiting nested loops.
Continue is based
Every time I see someone making an array out of a number and then looping over it with .map() to return another array of anything when simple for() loop would suffice I can't help but agree with people seeing JS devs as incompetent. You are using a bulldozer to remove a few bricks, what are you doing? Also: .filter() and .map() instead of .reduce(), because muh readability. Yet another reason to like Golang: one loop for everything, whether you like it or not. Refreshing.
Reduce sucks tbh, it’s much more convenient to just use a loop instead
So if I found some place to rest on Airbnb is it harmful to GOTO?
oh my god what did I just read... 😂😂😂
in the end of the day assembly uses jumps to make flow of the code, we have an branch predict thingy in the CPU's nowdays.
GOTO holds the mordern world
i use contues as gaurd clauses, especially when I'm searching for an item that needs to meet a certain criteria linearly.
I searched the issue for a more resonable answer. Someone said that avoiding continue and break may enforce more immutable code and decrease function size. These are points I could understand, but it took some scrolling to get there.
Airbnb eslint rule is a plague after maintaining several codebases based on their rules.
The people who copy/paste the eslint rule has literally 0 idea why they used it. "It was created by Airbnb, big tech company, must be good then". That's the 100% times I got the answer.
All of their rules might work well for the airbnb codebase, but it's a premature optimization for 99% codebase outside of that, for me it's even an opinionated biased config.
Disallowing continue is not a premature optimization, it's a premature pessimization
Goto isn’t harmful either. It’s the most useless position to take! And people who defend it hard, don’t understand that gotos are the foundation of branching in any cpu.
Every loop you program below is using a jump/branch and that’s a goto. But when you use goto just inside a single function, it’s not hard to trace. I agree it’s like break and continue and I have no problem with those either.
You just don’t want to use goto over functions. This is what creates spaghetti code, because there’s no easy context. And that’s what happened mainly in basic when people didn’t use gosub.
But frankly I can’t recall when I used goto in a higher level language. But in assembly jmp is my friend and I’m not getting lost in assembly either.
At work I also have devs who blindly follow absolutely everything they see in code style guides. Most annoying part is when they demand others to follow them too in code review.
We must make a copy of all things because functional and immutable are words I've heard.
once i had 2 nested for loops, and i was proud of using continue with label.
Continue and break is not goto? I take offense.
It is very determined and does the same thing everytime. Goto has to be maintained.
I use continue and break all the time to optimize the median run time of my loops.
If continue is bad because it’s “GOTO”, why do they like try catch?
I didn't even listen to what the linter try to warn me.
Imagine getting hired in a company where the "senior" devs won't approve your PRs because it has regular loops instead of these "functional" loops (and don't care about the reasons)...
Chesterton Fence Principle: Don’t Destroy What You Don’t Understand!
Yes always ask why, to devs to pms to everyone. If someone can’t tell you why they need to do more homework.
No, break and continue are NOT goto! The reason that goto isn't needed is BECAUSE OF break and continue! The use of goto leaves the scope in an arbitrary way, which means defer (Go, Zig, D (called "scope exit")), and destructors (C++, Rust (called "Drop")) don't behave as expected.
forEach doesn't create another array, there's no memory allocation. You could even modify the elements of the same array you're iterating. Some devs are concerned with off by one errors and infinite loops, others are concerned with using JS for what it was not intended to (being fast), both are valid concerns.
that isnt the point. the point is that a forEach will iterate through the entire array, which binds the linear execution time to the current amount of elements in the array. Continue and break can implement early exits in iteration making the linear execution time bound to the matching case, regardless of the size of the array.
@@stayfree1776 for that you can use a for..of loop, which gets rid of the issues I pointed out like infinite loops and off by one errors. Yes, saying that break and continue are bad is dumb, I wasn't defending that idk why you got that idea from my comment.
Yes it come from Dijkstra and was considered bad because goto made it difficult to prove the correctness of an algorithm
"Boomer loops" new term established.
"premature optimisation is the root of all evil" is a misquote from a biblical verse? What?
Can some give some more info on this ? :D
Thanks!
1 Timothy 6:10 combined (misquoted by omitting "love of") with "money" replaced by "premature optimization" (Tony Hoare via Donald Knuth) but with the "about 97% of" part being omitted, so indirectly it's a misquote of a misquote of the bible.
@@MNbenMN Thank you!
My girlfriend said premature optimisation happens to everyone.
If continue and break are GOTO then so is return and throw...
well, to be honest throw is almost as bad as GOTO
languages that don't have it are much nicer when it comes to error handling
Web code monkeys are hilarious, aren't they? It'll be a bit sad when they all are replaced with stochastic parrots, they were quite entertaining.
so sick of advice just being like 'this thing is bad practice', "continues are bad practice", "goto is bad practice", "LOOPS are bad practice". Nobody actually knows why, they just parrot these things that they heard once and act like they're smarter.
'GOTO considered harmful' was written before we even had standard control flow like 'for', 'while', 'if else', so a loop would just be 'label: foo(); goto label;', and that this hard to understand when the entire code base is written like that. Djikstra was just advocating for standard control flow, and nowadays 'goto' (and continue/break) are harmful is used where standard control flow could be used instead (looking at all the juniors who write 'while (true) { ... break; }' instead of just putting the break condition as the while condition'
loops being 'bad practice' in js is just the result of js andy's who don't actually know how to code going 'if you use iterator methods its only one line!! the fewer the lines better!!' and then teaching juniors 'loops are bad practice', and then those juniors taught other juniors and so on.
'premature optimization is the root of all evil' should be replaced with 'premature abstraction is the root of all evil'. if you can get something done with a boomer 'for (i' loop, do it that way. the end user doesn't see how many lines of code it is. they're not impressed by your 'array.map().reduce().suck().fuck().cum()'.
A few hours ago I just stumbled across an article about Chesterton fence, then the first youtube video I watched ThePrimeagen mentions it...
It's been a recurring thing in my life.
Maybe I should start a religion... Who's the revealed prophet, you asked me? ThePrimeagen is his name.
I'm not working and studying too many hours until lack of skill syndrome becomes impostor syndrome.
I'm completely sane, for now.
That's what they are saying to me.
Just an fyi, it’s because the google algorithm knows what you’re searching and what you’re looking at in chrome. It then uses that info to feed you relevant content on other google entities like youtube.
It isn’t a coincidence
If only he was part of TC69, he'd be taken more seriously.
Love me some boomer speedup loops
It's not the loops, it's the mutation. Once you get used to using expressions and values, debugging imperative mutating code is vertigo inducing. I want to solve business problems, not play stupid pointer games.
People has been fooling people in tech for long long time
The only programming advice you should listen to is what Joe Biden says. He is the master of programming.
He says to Use Rust !
im all in on boomer loops
missionary Loop; lessgo
First they came for the goto..
Poor guy never got an answer.
If you look at how I'm using the continue statement, you will start to think they are harmfull xDDDDD
while (i < argc) {
if (strcmp(argv[i], "--json") == 0) {
json_flag = 1;
i++;
continue;
}
if (strcmp(argv[i], "--debug") == 0) {
debug_level++;
i++;
continue;
}
break;
}
Wtf, continue is the least of the problems with this. No one would ever write it. I mean it most likely never even hits a continue or does anything.
@@InfiniteQuest86 why would it not hit a continue? (assuming i is initialized to 0)
@@InfiniteQuest86 Bullshit. Its EXACTLY this kind of code that makes me avoid loops.
@@sub-harmonik I mean if i is initialized to 0 it definitely wouldn't hit continue. It would fall through and hit break since the name of the program isn't --json or --debug. But assuming i was correctly initialized to 1, then if you had any other flag before these two, it would fall through and break without going through the rest of the args.
@@adambickford8720 Wtf how do you avoid loops? I probably wrote 100 loops yesterday alone.
Most people won't need to care about performance for the majority of the loops they would need to make.
In this case, when you know what you doing and have a case for needing more performance... then go ~to~ for loops!
missionary loops ;-)
Prime got stuck on not using regular loops haha. Its common to consider not using break and continue or more than 1 return as good practice and instead the break conditions should be in the loop condition and if statements organized for operation control. The reasoning is to avoid hidden program flow, especially in a large chunk. It doesn't inherently discourage use of normal loops though. There can be a performance hit to not using continue, break, more than 1 return (but usually in C or other compiled languages this usually isn't the case because they can optimize it back to its continue/break equivalent, not sure about something like JS though)
The avoidance of break continue and multiple returns can not only hit performance but can also lead to unnecessary if statements which make the code much harder to read.
@@mudi2000a I've run into multiple times when working on a large loop that having early breakout really took a long time to track down, I even dislike throws for that reason (anything that is not default, well defined program flow), but its mostly personal preference. Both ways have their pros and cons.
If the break statement is something that happens only at the start or the end of the loop then it should probably be done as part of the loop conditions (even then it might sometimes be more readable as a separate statement - a loop like for(int i =0; i
careful about about any internet advice.
Ban javascript. Websites only need html and css.
Agen
JavaScript 💀
boomer loops
Let me tell you why: 95% of us don't need to write code that iterates over millions of items. 99% of the collections my code has to iterate over contain 20 items at most.
And for that reason, developer time is more important than computer time.
In what scenario does continue slow down your developer time?
depends what context you are iterating in
And typing 1 second longer for the for loop is just not worth it :/
@@ITRThe cognitive load of an iterator is smaller than a loop. That is why people recommend using them. Then use map/filter/reduce to transform your data, which makes the code much easier to reason about than a custom for loop with a bunch of temporary variables and if statement and what not.
first