Earlier quoted context omitted.
You could create class that keeps static Map with references to all created objects of given type. On creation it would check if structurally same object was already created and return reference to previous instance instead of creating a new one. If you freeze those objects and their prototypes you get exactly your records. === becomes structural comparison that costs exactly the same as reference comparison. I made…
I believe this approach was proposed, but implementers pushed back because the initial interning is expensive and there are a lot of scenarios where it would never be used. You don't really expect creating a Point to do a hash lookup.
Pipe Operator (|>) For JavaScript
341–350 of 437 posts
Re: Pipe Operator (|>) For JavaScript
#342Earlier quoted context omitted.
Is the point of those just immutability or something else too? Wouldn't it be better to have a way to easily make any type deeply immutable? EDIT: I think tuples and records are also supposed to have value semantics, which is great, but why not a mechanism that turns on value semantics for arbitrary object type instead. Also value semantics is separate concept from immutability. Maybe there should have separate ways…
Sadly, JS weirdness interferes with value semantics: > 0 === -0 true > #{v: 0} === #{v: -0} ???
Re: Pipe Operator (|>) For JavaScript
#343In 2021 (https://2021.stateofjs.com/en-US/opinions/) it fell to 7th place.
Re: Pipe Operator (|>) For JavaScript
#344Earlier quoted context omitted.
Exactly. As the proposal contemplates this alternative, it claims: > But there are reasons why we encounter deeply nested expressions in each other’s code all the time in the real world, rather than lines of temporary variables. And the reason it gives is: > It is often simply too tedious and wordy to write code with a long sequence of temporary, single-use variables. Sorry, but...that's the job? If naming things is…
and yet looking through code from the place you work I see something like this let field = ve.instanceContext.replace(/(#\/)|(#)/ig, "").replace(/\//g, ".") Which you apparently claim should be const fieldWithHashMarksUnesacped = ve.instanceContext.replace(/(#\/)|(#)/ig, ""); const field = fieldWithHashMarksUnesacped.replace(/\//g, ".") https://github.com/mirusresearch/firehoser/blob/46e4b0cab9a2... and this return m…
Those typos leak out to calling code and it's hilarious when the typo is there 10 years later once all the original systems have been turned off
Re: Pipe Operator (|>) For JavaScript
#345Earlier quoted context omitted.
Extracting `envStr` is definitely the highest impact change for me. I dislike temporary variables too when they don't represent a meaningful intermediary result, but in this case I see them as a lesser evil. I agree that `styled` is more about personal preference. This is why I'm happy to see the pipe syntax proposal, it avoids unnecessary temporary variables while simultaneously aiding readability.
> This is why I'm happy to see the pipe syntax proposal, it avoids unnecessary temporary variables while simultaneously aiding readability. The thing is I don't think it's all that much more readable. No matter which syntax you use, there's still the same number of "things" going on in a single statement. I do have to admit I never worked with a language that uses |>, so I'm sure that with increased familiarly with t…
Have you never worked with Bash? It's basically the same thing
Re: Pipe Operator (|>) For JavaScript
#346Earlier quoted context omitted.
I dislike variables that are used just once. Sometimes they're a "necessary evil", but rarely. For "envStr" it's defensible IMHO as it splits up some of the complexity, but I would rather just use a helper function, which has the same "splits complexity" effect and is re-usable. "styled" seems entirely pointless here.
This actually surprises me! One habit introduced to my current team by a former co-worker involves having even more intermediate keys than that: const sensitiveEnv = [...]; const envKeys = Object.keys(envars) const safeKeys = envKeys.filter(envar => !sensitiveEnv.includes(envar)); const safeEnv = safeKeys.map(envar => `${envar}=${envars[envar]}`).join(' '); const styled = chalk.dim(`$ ${envStr}`, 'node', args.join('…
I'm also one of those people that likes single-letter variables. I know some people hate it with a passion, but I find it very convenient. Just makes it easier to read as there's less to read.
I'm not smart enough to do Haskell, so I can't say much about that.
Re: Pipe Operator (|>) For JavaScript
#347I don't think that it's a good idea to introduce a left-to-right flow into a language, which strictly assigns righthand values by general design. The text mentions a back-and-forth in reading, this introduces a back-and-forth intellectually. (There's already a limited left to right capability, namely by chaining expressions using logical operators, especially when used outside of condition. It should be mentioned, ho…
!(funcA(transferObject) || true) || !(funcB(transferObject) || true) ...
// ceci n'est pas une pipe
function pipe(func, obj) {
return !(func(obj) || true);
}
pipe(funcA, transferObject) || pipe(funcB, transferObject) ...
// cecie n'est pas une pipe non plus
function pipeB(func, obj) {
func(obj);
return 0 | 0;
}
pipeB(funcA, transferObject) | pipeB(funcB, transferObject) ...
// no more pipes, please!
funcA(transferObject), funcB(transferObject) ...
// finally...
;-)Re: Pipe Operator (|>) For JavaScript
#348I * HATE* pipes. For example from Elixir School ( https://elixirschool.com/en/lessons/basics/pipe_operator ): ``` foo(bar(baz(new_function(other_function())))) ``` They offer this example of an improvement: ``` other_function() |> new_function() |> baz() |> bar() |> foo() ``` While yes, pipes improve readability, how do they deal with errors? How do they deal with understanding what each thing is supposed to return?…
I think there is merit to the argument that if naming is one of the hard problems , programmers writing that code are having to do a lot of ‘naming’ and that is hard for them. The proposed pipe operation eliminates those names and lets the programmer just use %. But these variables are rarely the kind of thing it’s hard to name, so it feels like a slightly disingenuous argument.
Getting rid of the name moves the hard problem, rather than solve it
Re: Pipe Operator (|>) For JavaScript
#349Earlier quoted context omitted.
> This is why I'm happy to see the pipe syntax proposal, it avoids unnecessary temporary variables while simultaneously aiding readability. The thing is I don't think it's all that much more readable. No matter which syntax you use, there's still the same number of "things" going on in a single statement. I do have to admit I never worked with a language that uses |>, so I'm sure that with increased familiarly with t…
> I do have to admit I never worked with a language that uses |> Have you never worked with Bash? It's basically the same thing