In JavaScript, due to historical reasons, the function keyword is not very strict. You can declare the same function using the same name, and the runtime will simply use the last definition. On top of that, function is hoisted.
let addresses both of of these points. Though best would be using const.
This is awful and guaranteed to incite rage down the line. I'd much prefer full-text variable names over obscure abbreviations. Sure, it takes a bit more time and doesn't look the best, but no one will question intent.
inhales So func is a pointer to a function that receives int and returns a pointer to a function that receives an int that returns void and you assign null to it.
Dunno. And lambda is "correct enough" imo. It communicates what it is without communicating anything it isn't, such as "closure" would, and is as familiar as possible (as opposed to "functor")
Why use Promise.resolve().then()? Like, what's the point here?
What is func???
Now, even ignore the variables altogether, why are they assigning the value of rinside a promise, at the same time executing other scripts outside of the promise without async await?? This technically won't work if the promise is not coming back in time.
Tried so hard to understand the bare minimum of this but I can't 😆😆😆.
whfunc is recursive-ish but the next step in the recursion won't execute until whpro resolves.
If exp is truthy then whpro will become a promise of func which when resolved will
set r to a, the resolved value of func,
subract r from b.
If exp is falsy then whpro remains resolved (since it's not reassigned) and the rest is synchronous:
set r to ano,
subract r from b. (Same always)
Every step in the recursion is counted until b becomes less than or equal to 0.
The only part where all of this falls apart is on the last line where he "thens" either the promise returned from func() or the original Promise.resolve(). That means count is guaranteed to be 1 *(or 2) unless func is actually synchronous.
What worries me is that I think they may have thought that that was a good answer. As if OP didn't understand the most basic thing about the language or something.
The question asked: is this right? Well, depending on what the code is supposed to do technically it could be. Problem is determining what is this code supposed to do? Someone suggested this is part of the code for Summon_Satan.js which I believe is plausible but unlikely. It looks more like Summon_Wilford_Brimmley.js to me.
It’s actually (supposed to be) I couldn’t give less of a fuck. I could give less of a fuck implies that you currently do give at least a little bit of a fuck, when the whole point of the phrase is to say that you don’t care one bit whatsoever.
I’m a scrub, but I always just write out my variables in full length and I comment everything. Stuff like this is why, and I know future me won’t know.
You'd think so, but no. This person wrote several different versions of it. I and others have tried several times to talk to them about using descriptive names, but our pleas fall on deaf ears.
At least the names aren’t actively deceptive…I remember seeing a piece of code where (in the same file) multiple variables where called “widget” to either mean an actual widget, the name of the widget or a struct holding a information about a widget. And the same piece of code did this for lots of other concepts and variables, which meant that when reading the code, I was doing a lot of 3-sided die tossing to guess the meaning (didn’t help that it’s not a strongly typed language)
This is the syntax for an arrow function. The full syntax is (arguments) => { /* body */ }. If you have exactly 1 argument, you can leave the round brackets of. argument => { /* body */ }. If the body is a single expression, you can leave the curly brackets off, and the function will implicitly return the result of that expression. (arguments) => "body". Both of these shortcuts can be freely combined.
Yeah variable names can be improved, but if nothing else write some notes too so people know what your code is doing without having to sit and completely read through it in depth.
Good names will do a lot of that. Also, putting small chunks of functionality into separate functions with good names. Then the code reads like a comment.
Its an unpopular opinion because absolute rules are rarely correct in all contexts. Some popular counters to your opinion:
Variables that are relatively abstract, to the point that there is no additional information to give via a name beyond what is immediately obvious from the syntax. Consider the x:xsformat that's ubiquitous in Haskell as the pattern match for non-empty lists (often in a context where the type of x is generic).
Indexes and counters. If you wrote a piece of code like for(int i=0; i<xs.length; ++i) { foo(xs[i]); }, a meaningful name for xs and foo would be helpful, but i is self-explanatory.
Domain-specific single-character names. Consider a function handling colours using r,g,b,a; or a function dealing with geometry using x,y,z; or even a basic physics calculation using s,u,v,a,t.
Short, even single-letter variables, aren't always bad, and long variable names aren't always good. Absolutes like that tend to be wrong because they're focused on dogma rather than practical concerns, just like the old "goto BAD!" cargo cult that ignores any nuance in favour of a blanket "never use this thing EVER" view.
I used to think the same because that's what I had been taught, but over time I realised there are situations where there's no real benefit to a longer name, and even arguably makes a longer name actively harmful because it adds pointless noise to the code. /u/WalditRook gives a pretty good summary of example cases already, but I wanted to add some additional context specifically to the first point about naming variables for abstract things.
If you're writing code that's dealing in something concrete or a chunk of code that has a bunch of arguments and variables it makes sense to use concrete names, but it becomes less useful in certain contexts, like when dealing with parametric polymorphism (generics) or small data transformation functions. For example, map is a function that takes a function argument and a list of any kind and applies that function to each element of the list to return a new list. Naming the list values_to_transform and the function function_to_apply isn't particularly beneficial over fn and list or l and f when implementing map, it just adds noise:
let rec map function_to_apply values_to_transform =
match values_to_transform with
| [] -> []
| head :: tail -> function_to_apply head :: (map function_to_apply tail)
let rec map f l =
match l with
| [] -> []
| hd :: tl -> f hd :: (map f tl)
The same can be said for the resulting function signature ('a -> 'b) -> 'a list -> 'b list: The first argument is a function that transforms a thing of type 'a to a different thing of type 'b, the second is a list consisting of things of type 'a, and it returns another list of things of type 'b. How could you name this more descriptively when nothing is known about either type? Longer names add noise without adding meaningful information.
Same goes for the functions that you give to map as an argument. They tend to just be short names for the same reason, because you're writing a short function that typically gets no benefit from using a longer name for its argument. What do you gain from calling map (fun number -> number + 1) [1; 2; 3; 4; 5]) instead of map (fun n -> n + 1) [1; 2; 3; 4; 5]? Nothing, it's already obvious it's a number.
When writing functions to use with folds it's the same thing, they tend to be in form of (fun a b -> ...) to represent first/second arg, or maybe sometimes (fun l r -> ...) (for left/right arg), because they're data transformations that often don't benefit from longer names.
Sometimes you gain clarity by making the name slightly longer, but usually it's still basic stuff like nums and len because you're writing small functions, rather than the overly descriptive stuff you tend to expect in many languages.
in one project, i have a variable named poopoo. it's no longer there but yep, i've coded things with absolutely no regard for naming variables. i also make music and most of my project files consist of almost all names being purely arbitrary, which can make finding things(including the projects) very hard to find.
6
u/Thenderick Jul 19 '21
Can someone please explain me why you often use
let name = ()=>{...}instead offunction name(){...}?24
u/satoristyle Jul 19 '21
This is awful and guaranteed to incite rage down the line. I'd much prefer full-text variable names over obscure abbreviations. Sure, it takes a bit more time and doesn't look the best, but no one will question intent.
309
u/[deleted] Jul 19 '21
This code is so bad it looks like it's been minified
165
u/WpGgs Jul 19 '21
It could be worse, like this variable in C:
55
u/afunworm Jul 19 '21
Promise.resolve().then()? Like, what's the point here?func???rinside a promise, at the same time executing other scripts outside of the promise withoutasync await?? This technically won't work if the promise is not coming back in time.Tried so hard to understand the bare minimum of this but I can't 😆😆😆.
43
u/valschermjager Jul 19 '21
>> they are variables
100% correct. 100% useless.
122
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Jul 19 '21
Image Transcription: Discord Messages
Redacted User
ok then
is this right?
Bronzdragon
Man, this is so hard to read. What is
b, what isr, what isa? What iswhproandwhfunc?Redacted User
variables
I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!
111
u/clemesislife Jul 19 '21
Do you have the slightest idea how little that narrows it down?
48
u/Kraftdamus02 Jul 19 '21
variables
37
u/RyanNerd shameless Jul 19 '21
The question asked: is this right? Well, depending on what the code is supposed to do technically it could be. Problem is determining what is this code supposed to do? Someone suggested this is part of the code for Summon_Satan.js which I believe is plausible but unlikely. It looks more like Summon_Wilford_Brimmley.js to me.
29
u/random_rascal Jul 19 '21
/r/technicallythetruth
26
u/[deleted] Jul 19 '21
Variable names should just be curse words. No problem finding or remembering them then.
6
u/[deleted] Jul 19 '21
I’m a scrub, but I always just write out my variables in full length and I comment everything. Stuff like this is why, and I know future me won’t know.
5
u/DexterFoxxo Jul 19 '21
Oh no that's so fucking cursed that guy has 0 clue on how promises work
1
u/[deleted] Jul 19 '21
Could be output from decompiler...
1
u/Chibi_Ayano Jul 20 '21
Hey while I’m here can anyone explain to me the => syntax in js, it might also be () => I’m not too sure
2
u/Shipwreck-Siren Jul 19 '21
Yeah variable names can be improved, but if nothing else write some notes too so people know what your code is doing without having to sit and completely read through it in depth.
2
u/Furry_69 Jul 19 '21
What?? I.. Why!? What is.. Anything here?? I.. What!?
2
u/[deleted] Jul 19 '21
This is what happens when you try to learn from min files
2
u/noXi0uz Jul 19 '21
he's just trying to confuse the interpreter
2
u/AnythingWithJay Jul 19 '21
This is how competitive programmers code lmao
1
u/7incent Jul 19 '21
shoutout to TCD
1
u/Kurtisdede Jul 19 '21
That answer made me laugh hard hahahaha
1
u/[deleted] Jul 19 '21
This is seemingly an unpopular opinion but it is never acceptable to name a variable one letter
1
u/calio Jul 19 '21
if you're doing this, at least have some fun with it and make the variables puns and wordplay.
1
u/Alberiman Jul 19 '21
We have wide screens now, just fricken write out the whole purpose of it
1
u/world--citizen Jul 19 '21
ano means anus in Italian
1
u/Blip1966 Jul 19 '21
What is “ano” in that code? Another variable or a short reserved word I don’t know about? I don’t see it anywhere else.
1
u/isnortpreworkout Jul 20 '21
This gave me an unnecessary amount of anxiety
1
u/Subterfuge- Jul 20 '21
Atleast he won't need an obfuscator anymore
1
u/ftgander Jul 20 '21
“variables” damn thanks guy, it all makes sense now
1
u/harolddawizard Jul 20 '21
Flips table
1
u/[deleted] Aug 23 '21
in one project, i have a variable named poopoo. it's no longer there but yep, i've coded things with absolutely no regard for naming variables. i also make music and most of my project files consist of almost all names being purely arbitrary, which can make finding things(including the projects) very hard to find.
0
u/MoonParkSong Jul 19 '21
Nothing wrong with short naming local variables used in loops.
314
u/[deleted] Jul 19 '21
[removed] — view removed comment