Комментарии:
I have no idea what is goin on 💀
Ответитьit's like using a cane because someday you'll be old
Ответитьi vomited
3 times
Yoda notation is horrible because it decreases readability and unnecessarily increases the mental load on future developers who need to read your code. Don't do it.
Instead, use the tools you have at hand. gcc has -Wparenthesis to spit out a warning if you inadvertently put an assignment in a conditional. You can suppress the warning if you actually want to perform an assignment by, you guessed it, wrapping the assignment in parenthesis.
Fortunately in the modern day we have linters that will give you a warning before even going to compile it so that you don't have to code like Yoda anymore.
Ответитьa problem only a vim user could possibly care about
ОтветитьYoda notation is banned in Go.
ОтветитьPlease don’t do this, it makes code hard to read and especially don’t do this when you’re working in teams.
ОтветитьBut if you put a single equal in an if statment it results in an error? Or am i an idiot someone help plss.
Ответитьi think that its happens only in c.
ОтветитьLuminous beings are we…not these junior level typos.
ОтветитьSay what you want about python, but there it’s a syntax error 😂
ОтветитьThat gives FORTH vibes.
42 myVar @ = if ."something" then
Junior developer? Ive been coding for decades and I will still do this on occasion.
Ответить"Code like this is what Yoda makes"*
Ответитьor just dont have skill issues
- do, or do not. there is no try
If you make those kinds of errors you should either use a statically typed language (Error: expected bool but got int) or you should write (more) unit tests.
ОтветитьYoda like this would code: 42 val =
ОтветитьMany tools was used like naming conventions including types but with current ide highlighting mistakes its not that useful anymore. Still when looking into diffs in browser some things are still usefull lile explicit types insetad if auto or var 😊
ОтветитьThat is the jedi way
ОтветитьWow! This is neat.
ОтветитьIf you make that mistake, it's a right of passage that you spend an hour or two debugging it.
ОтветитьThat kind of bug (assignment instead lf equals) bugs me. I don't understand how someone could make or not ever even spot it. I can say with 100% confidence I have never made this mistake in my career, but I guess I'm just anal like that.
ОтветитьTbh it’s a common mistake to not put 2 ==‘s but like, idk Val == 42 seems better then putting the value first then the int name,
In summary in my opinion Val == 123 is better than 123 == Val
If you have to use some funky ass pattern to avoid unintentional side-effects due to the language, then you need to switch to a different language. This wouldn't happen in C# and it's insane that C is allowing you to do that. An `if` condition is just that, a condition. It's not the place for assignments.
Ответить1) It not only thinks that "ret" is 42 it sets ret to 42.
2) All good compilers give warnings if you do an assignment in an if condition. If you don't have 1200 warnings you are ignoring all the time you'll catch the mistake.
The double equal sign bug took me a week to debug once. I use that experience to explain my trust issues to this day.
ОтветитьMake your codebase unreadable to avoid a typo literally every IDE is screaming in your face anyway.
Smort
Would it not go in the if statement if you entered 0?
Ответитьi code yoda style because i HATE two equals signs.
all my homies hate ==
Maybe your programming language shouldn't allow this nonsense in the first place.
ОтветитьIts not that the val will always be 42 when using '='
But when using '=42' val is assigned 32 value which is a non zero value this considered as true in c
If you were to do "val = 0" that if loop won't execute
I don’t think the juice is worth the squeeze on this one.
ОтветитьUsing a symbol that is most commonly understood as an equivalence relation for variable binding has and always will be a leaky abstraction.
(def val 42) IS NOT (= val 42.0) IS NOT (== val 42.0)
Skill issue?
ОтветитьAnd then we got a linter warning about Yoda Notation. 😂
ОтветитьNot all languages are C 😅
Ответитьthere error shouldn't be because of assigning a value to a "constant literal", it is a variable that it is assigned to. Instead there should be an error because an if statement should take a boolean expression and not allow an assignment.
ОтветитьHow do you forget to do “==”, even on my first days of programming that was not a problem?
ОтветитьNo it just wouldn’t run
Ответить42 БРАТУХА!!1! КЕМЕРОВСКАЯ ОБЛАСТЬ!!! WW
Ответитьdidn't know it was called this, it's just common sense, ok for me, to do it because safety first :)
ОтветитьWe were told this was wrong / not to do this while we learning how to program when we’re young…😅
ОтветитьI didnt thought this was possible with any programming language to use a single = inside an if expression without the editor/compiler throwing errors/warnings and failing to compile. Then C is also a very old language so i guess Yoda notation is specific to that and I have never really worked with bare C. Any other programming language I know of and have used however throws an error with or without this Yoda notation if you use = instead of == within an if expression.
ОтветитьExpérienced programmer will make the maximum amount of variables constants and use a linter to avoid this kind of errors
ОтветитьSo instead of just remembering to put `==`, you instead remember to yoda-notate so that you are reminded to put `==` when you accidentally put `=`.
ОтветитьThe braces 😢
Ответитьyes so i think if( 42=val) .. but ... if i thnk of fliping them i can just think about the diffrent of aisgning or copmering and just put == where it shuld be if(val==42) question
what happen if you asigne a fals walue in a statiment
thisIsFalse=false;
if(valu=thisIsFalse) ??
I use constan to var comp. in Java, just for simplicity (avoiding null check).
Works especially well with const.equals(arg)
This is why type safe languages are introduced. Modern developers don't realize how important is type safety.
Ответить