Why Some Programmers Code Like Yoda

Why Some Programmers Code Like Yoda

Low Level

2 года назад

1,807,739 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@leaden6563
@leaden6563 - 27.02.2023 02:54

I have no idea what is goin on 💀

Ответить
@WendigoJunior
@WendigoJunior - 09.06.2025 06:27

it's like using a cane because someday you'll be old

Ответить
@ThisShitWontWor
@ThisShitWontWor - 08.06.2025 17:20

i vomited

3 times

Ответить
@stephenking2499
@stephenking2499 - 08.06.2025 00:15

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.

Ответить
@amraswoke6762
@amraswoke6762 - 07.06.2025 11:27

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.

Ответить
@gabe8168
@gabe8168 - 07.06.2025 09:21

a problem only a vim user could possibly care about

Ответить
@hebozhe
@hebozhe - 07.06.2025 01:28

Yoda notation is banned in Go.

Ответить
@TodayTestfbsfbsfbs
@TodayTestfbsfbsfbs - 06.06.2025 18:38

Please don’t do this, it makes code hard to read and especially don’t do this when you’re working in teams.

Ответить
@omarfedawy7979
@omarfedawy7979 - 06.06.2025 16:48

But if you put a single equal in an if statment it results in an error? Or am i an idiot someone help plss.

Ответить
@shalevforfor5550
@shalevforfor5550 - 06.06.2025 13:51

i think that its happens only in c.

Ответить
@Nostradevus1
@Nostradevus1 - 04.06.2025 20:06

Luminous beings are we…not these junior level typos.

Ответить
@krisztianfekete3277
@krisztianfekete3277 - 04.06.2025 19:06

Say what you want about python, but there it’s a syntax error 😂

Ответить
@theosexpertdaymon2774
@theosexpertdaymon2774 - 04.06.2025 00:12

That gives FORTH vibes.
42 myVar @ = if ."something" then

Ответить
@james.lambert
@james.lambert - 02.06.2025 21:43

Junior developer? Ive been coding for decades and I will still do this on occasion.

Ответить
@sollybunn
@sollybunn - 02.06.2025 20:52

"Code like this is what Yoda makes"*

Ответить
@kalyanoliveira3224
@kalyanoliveira3224 - 02.06.2025 06:32

or just dont have skill issues

- do, or do not. there is no try

Ответить
@bened22
@bened22 - 01.06.2025 23:15

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.

Ответить
@venicer
@venicer - 01.06.2025 23:13

Yoda like this would code: 42 val =

Ответить
@Kimdimasan
@Kimdimasan - 01.06.2025 21:30

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 😊

Ответить
@Kalendarren
@Kalendarren - 31.05.2025 10:45

That is the jedi way

Ответить
@aniksamiurrahman6365
@aniksamiurrahman6365 - 31.05.2025 10:01

Wow! This is neat.

Ответить
@HDConcussionz
@HDConcussionz - 31.05.2025 07:06

If you make that mistake, it's a right of passage that you spend an hour or two debugging it.

Ответить
@scbtripwire
@scbtripwire - 31.05.2025 03:30

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.

Ответить
@machoman1214
@machoman1214 - 30.05.2025 19:53

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

Ответить
@justinian.erdmier
@justinian.erdmier - 29.05.2025 20:10

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.

Ответить
@rafazieba9982
@rafazieba9982 - 29.05.2025 15:54

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.

Ответить
@gotaproblemwithmyname9331
@gotaproblemwithmyname9331 - 29.05.2025 13:36

The double equal sign bug took me a week to debug once. I use that experience to explain my trust issues to this day.

Ответить
@Ch0rr1s
@Ch0rr1s - 28.05.2025 22:37

Make your codebase unreadable to avoid a typo literally every IDE is screaming in your face anyway.

Smort

Ответить
@Kramer-tt32
@Kramer-tt32 - 28.05.2025 04:55

Would it not go in the if statement if you entered 0?

Ответить
@meat-rack
@meat-rack - 27.05.2025 22:40

i code yoda style because i HATE two equals signs.
all my homies hate ==

Ответить
@MrGeometres
@MrGeometres - 26.05.2025 15:59

Maybe your programming language shouldn't allow this nonsense in the first place.

Ответить
@lucifer-yb1xk
@lucifer-yb1xk - 25.05.2025 15:05

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

Ответить
@TagetesAlkesta
@TagetesAlkesta - 24.05.2025 16:45

I don’t think the juice is worth the squeeze on this one.

Ответить
@freedmen123
@freedmen123 - 24.05.2025 00:49

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)

Ответить
@RomanianProductions
@RomanianProductions - 20.05.2025 20:10

Skill issue?

Ответить
@dimasbka
@dimasbka - 17.05.2025 17:56

And then we got a linter warning about Yoda Notation. 😂

Ответить
@pfever
@pfever - 16.05.2025 15:48

Not all languages are C 😅

Ответить
@florianvo7616
@florianvo7616 - 16.05.2025 14:31

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.

Ответить
@FOSS-For-All
@FOSS-For-All - 15.05.2025 21:45

How do you forget to do “==”, even on my first days of programming that was not a problem?

Ответить
@codejedi-123
@codejedi-123 - 14.05.2025 21:29

No it just wouldn’t run

Ответить
@linker-arm
@linker-arm - 13.05.2025 18:05

42 БРАТУХА!!1! КЕМЕРОВСКАЯ ОБЛАСТЬ!!! WW

Ответить
@correabuscar
@correabuscar - 12.05.2025 00:43

didn't know it was called this, it's just common sense, ok for me, to do it because safety first :)

Ответить
@chunfung8934
@chunfung8934 - 11.05.2025 13:25

We were told this was wrong / not to do this while we learning how to program when we’re young…😅

Ответить
@johnpekkala6941
@johnpekkala6941 - 11.05.2025 01:41

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.

Ответить
@theoh.5734
@theoh.5734 - 07.05.2025 22:05

Expérienced programmer will make the maximum amount of variables constants and use a linter to avoid this kind of errors

Ответить
@TheOGDominic
@TheOGDominic - 07.05.2025 04:59

So instead of just remembering to put `==`, you instead remember to yoda-notate so that you are reminded to put `==` when you accidentally put `=`.

Ответить
@ashupednekardev-y2j
@ashupednekardev-y2j - 05.05.2025 06:09

The braces 😢

Ответить
@olasoderlind5685
@olasoderlind5685 - 04.05.2025 10:20

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) ??

Ответить
@Dd-do-and-dont
@Dd-do-and-dont - 01.05.2025 14:48

I use constan to var comp. in Java, just for simplicity (avoiding null check).
Works especially well with const.equals(arg)

Ответить
@hurle0409
@hurle0409 - 29.04.2025 05:24

This is why type safe languages are introduced. Modern developers don't realize how important is type safety.

Ответить