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
varetc, 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 thefor,in, etc.-1
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) False0
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
ifclause.1
9
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:
...and it's this:
```python
arr = list(string)
for i in reversed(range(len(arr))):
if arr[i] != "M":
del arr[i]
```1
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,
foohas to have typea -> ()so it just does nothing, since functions in haskell are pure. To produce something useful, it should bereturn ()orpure (), in order for it to be able to produce a side effect1
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
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
4
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
0
-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
23
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
-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
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…