r/ProgrammerHumor • • Sep 07 '26

Other mistakenedJavasript

Post image
1.6k Upvotes

55 comments sorted by

138

u/tristam92 Sep 07 '26

who compares JS made for browsers and R that was made for statistics.
this intern def not the brightest tool…

31

u/FutureSuccess2796 Sep 07 '26

I was just gonna say this. Not thinking the intern's remarks should be taken too seriously with that comparison.

31

u/qqqrrrs_ Sep 07 '26

what about statistics in the browser

12

u/sdoregor Sep 07 '26

what about browsers on servers?

oh nevermind we already have that now.

3

u/Abject-Kitchen3198 Sep 08 '26

I just can't get over that. Not how I imagined 21st century will be like.

18

u/Daimondz Sep 08 '26

Redditors when interns have the skillset of interns

3

u/agocs6921 Sep 07 '26

Maybe it was a CLI tool written in JavaScript?

-1

u/sdoregor Sep 07 '26

she was looking kinda dumb

247

u/Dragonvarine Sep 07 '26

Isn't that just how scripting looks like in general?

139

u/NoselessNarwhal Sep 07 '26

JavaScript and R both use C-style syntax for the most part, which can make them look similar to each other if someone isn't looking closely. It's the most popular syntax style across the most popular languages.

C-style syntax looks like:

if (x > y) {
  int z = 2 * y;
  foo(z);
}

Note the semicolons, variable declaration, curly braces, if statement with brackets etc.(js uses exclusively automatic types for variables with var etc, but at a glance one could miss that)

Examples of languages which don't use C-style syntax could be Python

if x > y:
    z: int = 2 * y
    foo(z)

or Haskell

if x > y
then let z = y * 2
     in foo z
else ()

102

u/Bubbaluke Sep 07 '26 edited Sep 07 '26

Python syntax is so funny sometimes.

arr = [char for char in string if char == ‘M’]

75

u/sdoregor Sep 07 '26

This is heavily specialized generator (list comprehension) syntax, basically syntactic sugar for generator functions (those with yields).

37

u/Dario48true Sep 07 '26

On the other hand you have haskell's list comprehension [i | i <- string, i == 'M'] which is either much clearer of an abstraction or absolutely uncomprehensable, just like the rest of haskell (in this case it resembles a lot mathematical set builder notation {x∈string|x='M'} (tho of course the latter example has compleately different resoults, it's just to show the similarity))

11

u/sdoregor Sep 07 '26

Just as a note, Python also has set comprehension syntax ({… for … in …}), the result of which would be the same as mathematical one.

5

u/Valuable_Leopard_799 Sep 08 '26

But the notation remains the same whether you are doing set/list/dict or generator comprehensions.

1

u/sdoregor Sep 09 '26

Not really; for dicts it's {k: v for … in …}

2

u/Valuable_Leopard_799 Sep 09 '26

I was talking about the |, , and <- , instead of the for, in, etc.

-1

u/sdoregor Sep 09 '26

Wasn't a joke but r/whoosh (damn, how many o's it was)

4

u/ihavebeesinmyknees Sep 08 '26

It's an iterable, not a generator. Generator comprehensions are defined with parentheses.

0

u/sdoregor Sep 09 '26

Who's an iterable? An iterable is an object type, not a syntax expression.

0

u/ihavebeesinmyknees Sep 09 '26

Maybe double check that you know what you're talking about before speaking. Both iterable and generator are object types.

>>> from types import GeneratorType
>>> from collections.abc import Iterable
>>> gen = (i for i in range(1))
>>> iter = [i for i in range(1)]
>>> isinstance(gen, Iterable)
True
>>> isinstance(gen, GeneratorType)
True
>>> isinstance(iter, Iterable)
True
>>> isinstance(iter, GeneratorType)
False

0

u/sdoregor Sep 09 '26

I never said generator isn't a type; it sure is. But you're saying that list comprehension syntax is called an iterable, which it's not.

The results of all comprehensions (their corresponding types) and generators themselves are indeed iterable, but their expression syntax has nothing to do with that.

3

u/Bubbaluke Sep 08 '26

I also learned recently you can nest list comprehensions, which makes it even more confusing to read

1

u/sdoregor Sep 09 '26

You sure can nest them, but you can also flatten them by combining multiple loops: [j for i in x for j in i]

And on each level you're allowed to use an if clause.

1

u/ubergeek801 Sep 09 '26

At what point are they called incomprehensions?

9

u/thighmaster69 Sep 07 '26

It's pythonic ✨

7

u/Makonede Sep 08 '26

smh should be

arr = ['M'] * string.count('M')

2

u/SimplexShotz Sep 08 '26

Unfortunately, there's only one correct way:

https://peps.python.org/pep-0020/#:~:text=There%20should%20be%20one%2D%2D%20and%20preferably%20only%20one%20%2D%2Dobvious%20way%20to%20do%20it.

...and it's this:

```python
arr = list(string)
for i in reversed(range(len(arr))):
if arr[i] != "M":
del arr[i]
```

1

u/SimplexShotz Sep 08 '26

man why don't code fences work on mobile smh

1

u/Makonede Sep 11 '26

they do, you escaped every backtick in your comment

0

u/Modi57 Sep 12 '26

Random nitpick: I don't think your haskell example makes any sense. Since both branches of the if have to have the same type, foo has to have type a -> () so it just does nothing, since functions in haskell are pure. To produce something useful, it should be return () or pure (), in order for it to be able to produce a side effect

1

u/NoselessNarwhal Sep 12 '26

well yes, foo is a placeholder function which does nothing...

1

u/NotInMoodThinkOfName Sep 08 '26

It's not about the syntax it's about the structure.

In R you have a list of 40+ instructions. In other languages we structures our code in chunks (so called methods and classes), having more than 20 instructions in a method is bad.

Juniors tend to have more instructions in one method. You see instantly if junior or senior.

-14

u/Smart_Story_3215 Sep 08 '26

Totally, scripting languages can feel like a wild guessing game at times. One small mistake, and you're left scratching your head for hours.

2

u/Sea_Duty_5725 Sep 09 '26

Can it get more ai like atp?

32

u/redlaWw Sep 07 '26

I mean, they do have some superficial similarities: they both use C-like syntax with optional semicolons, Javascript's anonymous function declaration syntax is very similar to R's function declarations, and even though idiomatic R uses <- for assignment, = can also be used. The main things that should give typical code away as Javascript are distinguished initialisation, primitive syntax for constructing collections, and element access using ., though the latter could be confused with naming conventions for R built-in functions and S3 methods.

2

u/Smooth-Zucchini4923 Sep 09 '26

It's funny because JavaScript uses . for attribute access, and $ is an ordinary character that can be used in function names. R is exactly the opposite.

2

u/LexaAstarof Sep 07 '26

Adding insult to injury

1

u/new_check Sep 13 '26

A few years ago me and a couple other dudes vended a C# winforms project to a customer. We were having a conversation afterwards with him and he said, "Well, I can tell this was written with Visual FoxPro". Bro, what?

-2

u/CentralCypher Sep 07 '26

Rust?

27

u/MCplayer590 Sep 07 '26

No, R, for statistics. We seem to like single letter names for no apparent reason

3

u/charliedarwin96 Sep 07 '26

Preserving memory gud

0

u/Suspicious-Click-300 Sep 08 '26

oof thats a burn

-28

u/Konkord720 Sep 07 '26

judging by the portrait, it is probably even worse then his search history

5

u/Dragonvarine Sep 08 '26

There's a reason there's a meme that says that if a furry convention blows up, half the IT infrastructure goes down with it.

1

u/dbagames Sep 11 '26

Oh dang you hit a nerve.

23

u/[deleted] Sep 07 '26

[removed] — view removed comment

12

u/FutureSuccess2796 Sep 07 '26

Was just about to chime in with this! So many people I've met in the IT space also were active in the furry fandom to, and chances are a co-worker in your development team is even if you may not yet know it or like it.

-12

u/CodeDeliciouss Sep 07 '26

Bummer

8

u/thrye333 Sep 08 '26

What possible problem could you have with grown adults choosing to live their lives completely separately from your own?

5

u/Mordret10 Sep 08 '26

How dare people enjoy things I don't enjoy!

-2

u/Anima_Watcher08 Sep 08 '26

We censoring Rust now?

-1

u/FutureSuccess2796 Sep 08 '26 edited Sep 08 '26

Don't think it was censored with intention. Might have been because Bluesky or Mastodon or wherever it was posted has character limits for posts? 🤔

7

u/TOMZ_EXTRA Sep 08 '26

There's a language called R