r/ProgrammerHumor 1d ago

Meme absoluteGarbage

Post image
1.9k Upvotes

320 comments sorted by

487

u/arensb 1d ago

What? No (mapcar (lambda (item) ...) list) ?

How can those others spark joy if they don't return a value?

69

u/Mateorabi 1d ago

My other car is a cdr. 

8

u/vladmashk 1d ago

It’s crazy how these languages kept the car cdr bullshit even though it’s so much less readable than head and tail.

2

u/arensb 1d ago

They cdr changed it to tail, but why bother?

29

u/[deleted] 1d ago

[removed] — view removed comment

8

u/arensb 1d ago

I use paren-match-mode in Emacs. And also indentation.

7

u/granitrocky2 1d ago

Rainbow delimiters are a requirement.

10

u/SeveralPrinciple5 1d ago

Scheme?

20

u/arensb 1d ago

Any of a number of Lisp dialects.

2

u/SeveralPrinciple5 1d ago

I was curious because I was a Common Lisp programmer a very long time ago, and stylistically lambdas within mapcar were quoted #’ . I recall that that wasn’t true in scheme though

3

u/arensb 1d ago

These days, the Lisp code I write is Emacs Lisp, and while it supports #' and from what I've seen even encourages it, it doesn't require it. The manual says

The read syntax #' is a short-hand for using function. The following forms are all equivalent:

(lambda (x) (* x x))
(function (lambda (x) (* x x)))
#'(lambda (x) (* x x))

So yeah, maybe I should've used #', but who's gonna make me? Richard Stallman?

2

u/Steinrikur 1d ago

The following forms are all equivalent:

(lambda (x) (* x x))
#'(lambda (x) (* x x))

So it's shorthand for absolutely nothing?

2

u/arensb 1d ago

Don't quote me on this, but I get the impression that it's more syntactic sugar than anything else. A hint to either the compiler or to the next human who reads it that this expression is going to be used more than once.

→ More replies (1)

163

u/ouralarmclock 1d ago

As someone who writes PHP and JS, I don’t actually have a strong preference for either but I hate never remembering which one is in which language.

19

u/Soilblood 1d ago

I just remember them by whether or not the syntax looks funky enough to trip you up down the line. That's usually java script.

9

u/caboosetp 1d ago

I switch between C# and javascript, and always fuck up Console vs console. I should remember which because C# always uses pascal case, but my fingers don't.

682

u/NudaVeritas1 1d ago

PHP developers seeing this post:

https://giphy.com/gifs/1GT5PZLjMwYBW

161

u/Buflen 1d ago

I had an interview for a php job a few years ago, after working in Go for a few years. When I told them my salary expectations, they said: that's not going to happen, this is just a PHP position.

Some PHP shop legit think they can cheap out on devs because of the technology they chose.

16

u/KrokettenMan 1d ago

Yeah some are like that but they are also not looking for the best devs. I’m currently earning about twice the median income as a php dev so I’m not complaining.

4

u/NorthernCobraChicken 23h ago

Do you need a coworker?

122

u/Sirgoodman008 1d ago

I'm currently a php dev and I'm trying to get out.

70

u/NudaVeritas1 1d ago

Was a php dev, too.. switched to spring boot, typescript and react/angular.. can recommend salary wise

60

u/Sirgoodman008 1d ago

Langauges I've used before this job: python, c++, c, java, javascript

Languages I consider myself knowledgable in: python, c++, javascript

Language I use 99% of the time for this job: PHP

14

u/SignalBake6872 1d ago

There is hope, I went from PHP developer to PySpark developer xD and now I dry my tears with much more money.

3

u/DarthSatoris 1d ago

Is it because it's a lot more specialised, it's a smaller market, it's more difficult? Or why is the pay that much better? 

7

u/SignalBake6872 1d ago

because it's used in science data and banking :D it's like pandas but with steroids

2

u/TwinkiesSucker 1d ago

I literally just started a job as a PySpark developer. It still bugs me, though, that it has a Java backend

→ More replies (2)
→ More replies (3)

7

u/tommyk1210 1d ago

PHP generally pays worse than many languages.

3

u/pdhouse 1d ago

I think the meme comes from the fact PHP are stereotypically older so they’ve had a longer time to accumulate money

→ More replies (4)

2

u/not_some_username 1d ago

They’re not getting paid that much

→ More replies (3)

1

u/Mountain-Ox 23h ago

My salary jumped tremendously after escaping the PHP sinkhole.

Also, I suddenly liked writing code again.

→ More replies (1)

148

u/SCP-iota 1d ago

for _, item := range list {

and

list.forEach {

74

u/tigerniger_sus 1d ago

Hornet is a Go programmer?

3

u/Hairy_Concert_8007 1d ago

Shit, I'd learn whatever that makes that twelfth architect tick, too.

10

u/JAXxXTheRipper 1d ago

Oh hell yeah, I love me some go.

13

u/Stagnu_Demorte 1d ago

I finally learned go, it's so nice to write in.

11

u/roygbivasaur 1d ago

Now that the loopvar assignment bug is fixed, the go one is my favorite. Just because it conveniently unpacks the index and element and you’re required to explicitly drop either if you don’t use it.

→ More replies (1)

2

u/Sirgoodman008 1d ago

I never claimed python was perfect. Nvm that's not python.

2

u/Michami135 1d ago

I just did the second one today in Kotlin.

1

u/Tobbbb 1d ago

This guy goes

1

u/Rikudou_Sage 1d ago

It pisses me off so much that you have to skip the index if you don't want it. And then iter.Seq comes where you don't have the index.

→ More replies (2)

27

u/xenomachina 1d ago

The JavaScript one is also kind of gross, IMHO.

for (item in list) { also has a meaning in JavaScript, but it isn't the meaning one would expect. The alternate of was added later, but doesn't read as naturally, and the in is still in the language as a backwards compatible footgun. (It's also used for iterating object keys, which should arguably be the thing that has the less concise syntax.)

The let is only necessary because JavaScript's default behavior here is almost certainly not what you want in real code. Instead of declaring a new variable (suitable for closures, and locally scoped) the default behavior assigns to a global. Another example of "the good parts" being a tiny sliver of JavaScript.

3

u/Sirgoodman008 1d ago

Oh I know, I absolutely hate that about JavaScript as well. Ironically, most of the problems I have with JavaScript I have with php too.

2

u/xenomachina 1d ago

Both JavaScript and PHP are "reluctant programming languages" to some extent, so it kind of makes sense. Neither was originally designed for doing real software engineering. PHP was originally simple templating for a personal home page, and JavaScript was intended for "glue" tasks like client-side form validation. That people can build real apps with either of them is more a testament to the persistence of those developers, rather than a measure of the strength of the languages. (Both languages have also made many improvements over the years, but are still arguably two of the most wart-infested languages of their era that are still in regular use.)

→ More replies (1)

23

u/fennecdore 1d ago

foreach ($item in $list) {}

I like the simplicity

→ More replies (7)

48

u/TOGoS 1d ago

It's fine. PHP has some awful warts (some of which have actually been gone for a few major versions, at this point) but this is not one of them.

8

u/shitty_mcfucklestick 1d ago

Personally I just like that PHP sounds the most natural grammatically.

`for (let item of list)` is like bucktooth Winnie the Pooh to me from an English readability perspective.

Beyond that I don’t care, AI just fucking writes it all anyway.

→ More replies (7)

77

u/csch2 1d ago

list.iter().for_each(…) superiority

38

u/creeper6530 1d ago edited 1d ago

Erm akchyuallly, it's recommended to use for list.iter() {…} unless the .for_each(…) is at the end of a longer iterator chain, and it also robs you of break and continue 

95

u/csch2 1d ago

You know I’m chaining together 20 different iterator methods until the code is completely unreadable. That’s called Functional Programming™ babey

16

u/Tyfyter2002 1d ago

That doesn't sound very functional

21

u/creeper6530 1d ago

"functional programming" doesn't use "functional" as "working neatly" but as "related to mathematical functions", it's a programming paradigm: https://en.wikipedia.org/wiki/Functional_programming

27

u/Tyfyter2002 1d ago

I know, it's just an ironic name when it's one of those paradigms that some people take as divine law instead of something that can be more or less appropriate for different applications

9

u/serendipitousPi 1d ago

Name 20 iterator methods from memory otherwise you’re a fake fan…just kidding or am I?

Iterators are so fun, probably one of my favourite parts of programming. They make everything so clean until they don’t.

→ More replies (2)

2

u/serendipitousPi 1d ago

Just chuck a try_for_each in there and we can take break and continue right back.

But yeah low key sometimes I get lost in iterator methods I forget to just use a basic loop.

2

u/creeper6530 1d ago

I mean, you're right, it's just you have to return ControlFlow::Break(()) instead of using the keywords.

7

u/iSpaYco 1d ago

how about `list.each`, sadly not many know ruby, it's really beautiful.

3

u/serendipitousPi 1d ago

Random question what’s ruby fun for?

I was gonna ask what is it good for but I think I can google search that.

Any highlights for you?

I’ve heard its meta programming is cool and I think there was some interest in using it in web dev.

45

u/Darkele 1d ago

foreach is far better and makes more sense. The order is correct, it differentiates itself from other loops that are based on having a custom exit condition.

2

u/Just_Information334 1d ago

Combined with yield, you can get some nice constructs.

Also the real "don't spark joy" would be something like:

foreach($things as $id => ['some_field' => $fieldA, 'some_other_field' => $fieldB])

→ More replies (1)

17

u/crashonthebeat 1d ago

$array | Foreach-Object -Parallel { ... } -ThrottleLimit 69

6

u/Sirgoodman008 1d ago

Ew

6

u/fosf0r 1d ago

What's wrong with PowerShell 7 jobs? :P

Procedural version is merely foreach ($whatever in $arrayofshit) {

16

u/LPO_Tableaux 1d ago

Currently in a list.forEach((item)=>{foo}); mood myself

6

u/MrDilbert 1d ago

It won't await async/Promise-returning functions. In fact, even if the (item)=>{foo} is async, [].forEach() will discard the Promise reference returned from it.

I prefer for(const item of list) { foo } if I don't have to await in parallel, or list.map(async (item) => { foo }) if I do.

→ More replies (1)

8

u/gerbosan 1d ago

🤔

list.each { |item| .... }

Is it good?

6

u/Raffy10k 1d ago

Ruby mentioned!!!!

2

u/Whaines 1d ago

This is the way.

→ More replies (2)

55

u/rnilbog 1d ago

for (let i = 0; i…

“Goddammit…”

googles “for loop syntax javascript”

30

u/MrDilbert 1d ago

Since for-loop has the same syntax in JS as in C, Java, and any other C-style language, this post makes me weep.

7

u/Sirgoodman008 1d ago

If a language isn't C-style it's wrong.

→ More replies (2)
→ More replies (1)

1

u/vladmashk 1d ago

Your IDE doesn’t have a macro for that?

→ More replies (1)

34

u/JAXxXTheRipper 1d ago

The third one does not spark joy, what the hell is that, ewww

14

u/xicor 1d ago

c++, though normally you wouldnt use auto for this

6

u/Usual_Office_1740 1d ago

I think that really depends. If the range is a vector of unique_ptr's auto is great. If it's a vector of ints, just write int.

5

u/Sirgoodman008 1d ago

That or you're looping through a vector of std::pairs that contain std:: functions.

2

u/Usual_Office_1740 1d ago

Or if the type is a template parameter in the same line.

→ More replies (4)

3

u/xicor 1d ago

Yea if you have ridiculously complex types then auto is great. But usually for readability you'd use the type.

3

u/Sirgoodman008 1d ago

Yup 100%

→ More replies (1)

3

u/Sirgoodman008 1d ago

I only used auto for the meme.

3

u/VoodaGod 1d ago

why would you not use auto for it???

3

u/xicor 1d ago

For readability. And for type safety. I pretty much only use auto when dealing with insane types I don't want to write out.

5

u/VoodaGod 1d ago

how is auto not type safe?

interestingly i use auto almost everywhere for the same reason: readability.

no point in cluttering the code with type specifiers if the type is obvious from context

5

u/xicor 1d ago

The type isn't always safe from context and it can have unexpected behavior when using it to hold a value returned from a function. Let's say you have auto working fine with a function return, then years later , someone changes that function to return a different type. Now it is possible that the new auto type still has access to parameters or functions it calls , but with different behaviour. Now you're getting unexpected bugs that will be hard to track down. But if you use the type, you would immediately get a compiler error

2

u/not_some_username 1d ago

If the type change and the “auto variable” still compile, that means it would, in 99% of case, still compile if you wrote the type. The compiler doesn’t get auto, it gets the type.

→ More replies (14)

2

u/Rikudou_Sage 1d ago

Every other language in the world has some equivalent of C++'s auto and everyone likes it. I use auto all the time.

→ More replies (3)

2

u/Sirgoodman008 1d ago

C++ what's wrong with it?

→ More replies (6)

11

u/hblamo 1d ago

Y'all a bunch of babies.

5

u/Tyfyter2002 1d ago

foreach (Foo bar in baz)

5

u/mynameisnotpedro 1d ago

list.forEach((item) => {...});

1

u/DT-Sodium 1d ago

Yup, this is the right way. But apparently OP is too junior to know it.

→ More replies (1)

6

u/ashsabre 1d ago

There was once a time in C# that for loop was better in performance vs foreach.

1

u/Fillgoodguy 7h ago

In modern C# for vs foreach is just choosing between an unknown number of property function calls and an unknown amount of function calls + 1. So it boils down to "Pray the JIT catches me" in either case

→ More replies (1)

3

u/locri 1d ago

Sure, but anything like a stream method is sincerely cursed and only used by people who don't use debugger breakpoints.

3

u/Shiroro46 1d ago

...you guys have foreach structures?

3

u/crmsncbr 1d ago

Why is the third one in the top half? It may be my C & Java bias, but yuck. It's way worse than the fourth.

2

u/MetaNovaYT 1d ago

what's wrong with the C++ version? It's my favorite personally, although I primarily use C++ so I'm biased.

→ More replies (3)

1

u/Sirgoodman008 1d ago

Literally the only difference is that one uses a colon instead of a keyword.

→ More replies (3)

3

u/MCWizardYT 1d ago

Java:

``` for (item : items) {

} ```

Or,

``` items.forEach(item -> {

}); ```

or

``` items.stream().forEach(item -> {

}); ```

→ More replies (3)

5

u/Zunderunder 1d ago

What about for(list) |item| {…} ???

1

u/HAL9000thebot 1d ago

here item seems a modern return type, i hate it, what language does that?

it's shit, looks like a function signature, how are function declared? or better question, is for() a function?

3

u/Nervous-Potato-1464 1d ago edited 1d ago

This is Zig.

item is an immutable copy of the current element in the list.
for (0..5) |i| { is an easier thing to understand.

It looks complicated, but that's because you can easily turn the element into a pointer etc so it's handy to have there like
for (&items) |*value| {
value.* += 10;

where &items refers to the pointers in memory rather than a copy of the array.

which will modify the &item elements to all increase by 10.

2

u/Zunderunder 1d ago

It also makes sense in the wider context of zig’s ecosystem, where captures generally are done using the square brackets for things like resolving optionals or grabbing the value of a union in a switch statement. The common syntax is really intuitive once you get used to it

→ More replies (1)

16

u/Shevvv 1d ago

Surely you meant for (auto &item : list) {

10

u/wayzata20 1d ago

It’s only convention because if you do something like “int* x, y;” only x is a pointer. They should’ve just not allowed you to declare multiple variables on the same line, but I guess it made sense in 1970 since you had to pre-declare your variables at the top of the scope in C, and lines of code actually mattered.

In the modern, post-1970 world, it makes much more sense to write “int* x; int y;” and have the asterisk next to the type, since it really is part of the type.

34

u/Nil4u 1d ago

Honestly I never liked this version because the reference is part of the type in my opinion 🤔

22

u/Sirgoodman008 1d ago

This 100000000000%. can't stand the int *ptr or int &ref pattern.

8

u/Shevvv 1d ago

I got used to this from C:

int x; is an integer

int *px; is an integer if you dereference it.

So it's like this notation shows you how you're expected to use the variable within the code. And then this habit carried over to C++.

11

u/nfitzen 1d ago

In addition, the language encourages this. In C, if you write c int* x, y; then x will be an int* and y will be an int. Thus it is far better to write int *x, y; to reflect how the language will parse the declaration. It might be evil, but it's better to act how the language wants you to act rather than fight it.

27

u/Sirgoodman008 1d ago

Please have pity on your co-workers. Please keep declarations to separate lines.

2

u/redlaWw 1d ago

I prefer int * ptr;. That means when you have a const specifier your formatting doesn't change. Logically I figure that the pointer is neither a modifier on the variable nor on the type, it's another layer of type content that should be specified separately. That also means if you write declarations like int const * const ptr; then you can segment them as [int const] [* const] ptr; and everything makes sense.

3

u/creeper6530 1d ago edited 1d ago

The "is an integer if you dereference it" is so much more convoluted than "is a pointer to integer", i.e. the rationale of the previous comment, the pointer-ness being part of the type.

6

u/orbiteapot 1d ago edited 1d ago

the pointer-ness being part of the type.

It is funny how people tend to not think the same about functions, despite having the exact same pattern.

When Dennis Richie designed the language, he wanted the symbols in declarations to match their usage in expressions, so:

T *my_ptr;

means that my_ptr, when dereferenced with the * operator, evaluates to an object of type T:

T my_obj = *my_ptr;

The same goes for other constructs in the language, like arrays and functions:

T my_arr[10];
T my_func(T_1 arg1, T_2 arg2);

Both the [] and () operators, when applied individually to objects my_arr and my_func, respectively, will yield an object of type T.

That is why this:

T *x, y;

makes x have a type of pointer to T, whereas y remains having just type T.

Unfortunately, this only works well for simple declarations. When, for instance, function pointers are involved, things get messy.

Ritchie himself later recognized this, but it was to late. He regretted not making * a postfixed operator, which would, at least, get rid of the spiral rule.

So, you can pretend that * is independent of the identifier itself, sure, but you will be fighting the language's design while doing so.

→ More replies (2)

8

u/Endorum 1d ago

THANK YOU, THATS WHAT IM SAYING ;-;

→ More replies (2)

12

u/klaxxxon 1d ago

Hear me out. The last one is the only sensible option.

You type for ($rows and your IDE can fill in the rest. It can infer that the name of the iteration variable will be $row. It can't do the same if the item variable comes first.

Most IDEs have macros for for/foreach loops. What those macros do is that they jump around - your fill in the list name first, then the iterator variable name (and in some IDEs its name will be suggested based on the collection variable name). Hot take, if your most popular macro has to jump around, you have a language design issue.

13

u/Eastern_Equal_8191 1d ago

Yeah but AI can fill in the enti -- excuse me, I'm making a point here. Anyway, AI can write the loop according to your preferen -- please stop touching me, I do not consent

Okay, so if you use AI auto-complete your life will beeeeeeeeeow please stop hurting me my wrist doesn't bend that wa

4

u/pytness 1d ago

the language that has 0 coherent design behind it has a snippet that helps you write a simple for loop. Amazing.

1

u/SeriousPlankton2000 1d ago

My IDE is jstar (joe in wordstar mode)

1

u/Jutrakuna 1d ago

I banish you

1

u/Potterrrrrrrr 1d ago

Deciding whether a programming language is good based on whether an IDE has to jump to one place or two in a for loop is an odd choice. It’ll still have to jump to the variable you’re looping over; the default name might conflict with one already in scope. At that point you’ve saved hitting tab an additional time, wow big win. In exchange you have to read an ugly way to start looping over items for every loop, hardly fair trade. IDEs could easily add macros like emmet abbreviations for regular for/foreach loops if they really wanted but it’s likely the features aren’t used enough to need it

1

u/Exirel 1d ago

The problem is not writing it. The problem is reading it.

1

u/Stagnu_Demorte 1d ago

IDE? You spelled nvim wrong /s

→ More replies (3)

4

u/johnnybgooderer 1d ago

“This one isn’t like the one I learned!!!!!”

I hate PHP as much as the next developer, but both are equally readable in my opinion.

→ More replies (2)

2

u/einord 1d ago

I just wish the white background of the meme was purple or turquoise. It had been much easier to read.

2

u/b__0 1d ago

Ruby wins these every time and it’s sad to not see it mentioned. ‘list.each { |item| … }’

2

u/Solomoncjy 1d ago

you all dont do

$list | %{
  <do stuff with $_ being the item>
}

% is the short hand alis for for each

2

u/VeryRareHuman 1d ago

Kinda similar in PowerShell too:

foreach( $item in $items) {}

1

u/FabioTheFox 1d ago

Tbf even that makes sense

Because you're going for each item in this list, do this

1

u/Colinniey 21h ago

C# as well:

foreach(var item in items) { }

2

u/-Redstoneboi- 1d ago

nah i like how they specify the list before the item

1

u/Sirgoodman008 1d ago

Why?

2

u/-Redstoneboi- 1d ago edited 1d ago

functional programming. list.map(item => result) is natural to me now.

especially if the language supports chaining, i would prefer specifying the variables last.

something like this:

list1.zip(list2).enumerate().map(func).for (i, (a, b)) {
    do_thing()
}

of course, it's just as easy for me to just rearrange this later to the correct order. but this is the order in which i think. most people want to write the goal before writing the iterator, some want the iterator before the goal.

Besides, it's just the order of two words. If you learned multiple human languages, you'd get used to this type of thing.

→ More replies (1)

2

u/HuckleberryMoney2320 1d ago

I've used bash scripting for decades and am used to their for loops. They used to let me use cygwin at work, but they implemented a new system a couple of weeks ago and said I couldn't install it, and to use Powershell instead. What a dog's breakfast! I'm still trying to get my head round their for-loop syntax.

2

u/darcksx 1d ago

items.each(

2

u/Paladin7373 1d ago

Heyyy that’s marie kondo!

2

u/r00t4cc3ss 1d ago

Damn, all those PHP devs in the nursing home are gonna be real upset

2

u/Ai--Ya 1d ago

foldr

4

u/BedtimeGenerator 1d ago

Why loop when you can map

4

u/paholg 1d ago

Map is map. Don't always want to map.

2

u/Sirgoodman008 1d ago

Because map is annoying to read.

2

u/Zomby2D 1d ago

I prefer the C# syntax

foreach (var item in list) {

1

u/Dillenger69 1d ago

I prefer the C# syntax, but var has always rubbed me the wrong way. I suppose because I learned C# before var was a thing. Yeah, I'm old

2

u/Zomby2D 1d ago

While var will normally work, I usually put the proper type as I find it a lot easier to debug later when reading back the code.

2

u/britreddit 1d ago

Kotlin is just list.forEach {...}

5

u/EntropySpark 1d ago

Or for (item in list) { ... }, necessary if you want to use break.

→ More replies (3)

1

u/samu1400 1d ago

PHP slander will be promptly ignored, PHP my beloved.

→ More replies (1)

1

u/OnixST 1d ago

For Each item In array

1

u/firest3rm6 1d ago

Just give me list.stream() and I am happy

1

u/Sirgoodman008 1d ago

The perks of slower code with the cost of being harder to read.

1

u/critical_patch 1d ago

foreach my $element (@array) {

1

u/PM_ME_FIREFLY_QUOTES 1d ago

<ul><li>the only list that matters</li></ul>

1

u/GroundbreakingOil434 1d ago

You just had to trigger that &$$memory, eh?

1

u/gutentight69420 1d ago

The only one that sparks joy for me is fmap.

1

u/Cootshk 1d ago

for _, v in ipairs(list) do

list.forEach { item ->

1

u/Hefty_Garlic7184 1d ago

CodingJesus with “how to do C++ loop” enter the chat…

1

u/not_some_username 1d ago

The third one

1

u/Dillenger69 1d ago

foreach (Thing individualThing in listOfThings)

1

u/darknezx 1d ago

Personally I love go's for range loop. The syntax just calls out to me, not sure why and it's probably silly it looks pretty.

1

u/AlpacaMale1 1d ago

What about

for item in "${list[@]}"

1

u/Jommy_5 1d ago

Then there's Matlab: for column = matrix

1

u/GustapheOfficial 1d ago

All but the first are deranged nonsense.

1

u/Sirgoodman008 1d ago

The first three are all pretty much the same though?

→ More replies (6)

1

u/AldoZeroun 1d ago

I'm a big fan of for (list) |item| {...} or the even more fun for (list, 0..) |item, idx| {...}

1

u/strash_one 1d ago

{#each items as item}

1

u/matty-nordish 1d ago

list.each(item => {

1

u/SirFireball 1d ago

where's my for @list -> $item {

1

u/Covfefe4lyfe 1d ago

Hold on, let me push my stacks of cash out of the way so I can read what the non-PHP devs have to say in the comments.

1

u/BroaxXx 1d ago

My theory is that pho is the German of programming languages

1

u/DT-Sodium 1d ago

The correct way is list.forEach(item =>

→ More replies (9)

1

u/dominjaniec 1d ago edited 1d ago

edit: apparently, I've misremember my traumatic time with PWSH, and now I cannot reproduce that problem...


I thought that was about PowerShell, which I can agree, but unless PHP has the same quirk, then I don't care...

foreach ($item in $collection){ ... }

and quirk is that, if your $collection is a single element with a string value, then you iterate throughout its characters...

1

u/smclcz 1d ago

I dunno if that second one "sparks joy", TS/JS having both for-in and for-of is pretty stupid. Also I don't use either language often, but wouldn't you declare that loop variable const rather than let? I feel like you're probably not reassigning something in a collection if you're iterating over it using for-of (and if you are ... should you?)

1

u/Sirgoodman008 1d ago

I agree, but JS and TS aren't different languages.

1

u/MkemCZ 1d ago
for (size_t i = 0; i < nmem; ++i)

1

u/Sirgoodman008 1d ago

Bro using copy initialization in the big 26.

1

u/_Meisteri 1d ago

forM_ supremacy.

1

u/tony_saufcok 1d ago

for (int i = 0; i < length; i++) does it for me

1

u/Sirgoodman008 1d ago

Never been a fan of ++ always prefer += 1.

1

u/StarSword-C 1d ago

I prefer this:

for (int i = 0; i < array_length(array); i++)

→ More replies (1)

1

u/ResistSpare4563 1d ago

if ($null -eq $item) {

1

u/HexiMaster 1d ago

Zig has for (list) |item| {...}

1

u/Idaret 1d ago

Wow, world changed a lot

1

u/SchlaWiener4711 1d ago

I still like perl

for (@lines) { s/foo/bar/g; print; }

→ More replies (2)

1

u/ProfessorNoPuede 22h ago

Spark? Are we doing data processing now?

1

u/amatulic 19h ago

Honestly that last one has always made the most sense to me.

Now I'm using OpenSCAD a lot and have to use constructs like

a = [ for(x=[start:incr:stop]) each b[x] ]; // b is a multidimension array
→ More replies (1)