Hacker Newsnew | past | comments | ask | show | jobs | submit | more cokeandpepsi's commentslogin

the refactored version of the example is much worse


Do you mind elaborating? I find the refactored version significantly easier to understand than the original. Readability is one of the top priorities for me and I find the original example too clever, in a bad way.


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(' '));
    console.log(styled);
In the beginning I wasn't a fan of it, as I do a lot of Haskell (and have point-free idioms on the tip of my fingers), and it's obviously unnecessary, as you said yourself. But with time I learned to appreciate this kind of function for its simplicity and consistence.

Now, of course, with a pipe operator (or other similar constructions) you can get the consistency without the intermediate names.


I just find it easier "thing" that happens is one self-contained statement, if that makes sense. Makes it easier to see what does what. I don't think one way is "better" or "worse" btw; all I can say to my brain, I find it harder to follow. This is what can make programming in a team hard.

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.


Oh, a kindred spirit. I also love single-letter variables where they make sense. I have a math-heavy background, so they're totally cool for me, BUT I get why most programmers would hate 'em. I also like them since they were the "norm" in old C# LINQ code where I learned functional programming. If I were alone in the programming world I would have written the example above with single letter vars.

I agree with your remarks, there's no right or wrong, it's like tabs and spaces.

Btw I'm also not smart enough for Haskell, but it hasn't stopped me so far ;)


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 this it would become "more readable" to me, but one has to wonder: just how many calling syntaxes does one language have to support? More syntax also means more potential for confusion, more ways to abuse the language/feature, more "individual programming styles", more argueing over "should we write it like this or that?", more overhead in deciding how to write something, harder to implement the language and write tooling for it, and things like that.

There is always a trade-off involved. The question to ask isn't "would this be helpful in some scenarios?" because the answer to that is always "yes" for practically any language feature. The question to ask "is this useful enough to warrant the downsides of extra syntax?" I'm not so sure that it is, as it doesn't really allow me to do anything new that I couldn't do before as far as I can see. It just allows me to make things that are already too complex a bit more readable (arguably).


> 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


Indeed it is, but it's kind of a different context than a "real" programming language. What works for one doesn't necessarily work well for the other.


Truly, one of the main reasons I might stop increasing the complexity of a bash one-liner and move it to a full shell script, or bail for Python, is specifically so I can turn those chains of pipes into imperative steps with temp vars so that they're actually legible and easy to reason about. I can't imagine why I'd want to go the other direction.


Those variables help to document intent by naming the intermediate values. They also make step-debugging more convenient. In languages with type declarations, they also serve to inform about the type of the intermediate value, which otherwise is invisible in a pipe sequence.


IDEs for languages with pipes allow break points on pipelines and can show inferred type annotations mid pipeline. Given the popularity of JS, this tooling will appear rapidly after pipe standardisation.


In this case I like that it gives you a hint about what's going on. "chalk.dim" sure doesn't.


The refactored version is doing what pipes would do in a language that doesn't support pipes; it's reordering the statements into execution order rather than having to use a mental "stack" to grok the original version.

Given that the OP stated that they like the pipe syntax, and the refactored version illustrates the hoops you'd have to jump through without it, I guess your comment is just a strange way to agree with the OP?


why? are you of a 'pointfree' opinion? what are your concerns? https://wiki.haskell.org/Pointfree

personally i detest pointfree syntax. having intermediate values makes it much easier to step through code with a debugger & see what is happening. and it gives the reader some name for what the thing is, which is incredibly useful context. the enablement of pointsfree styles is one of my main concerns about potential pipe operator syntaxes: the various syntaxes that have been raised often introduce implicit variables which are passed, and i greatly fear the loss of clarity pointsfree style brings.

maybe there's something beyond the pointsfree vs not debate here that i'm missing, that makes you dislike the refactored example. personally i greatly enjoy the flatness, the step by step production of intermediate values, each of which can be clearly seen, and then assembled in a last final clear step. that is much more legible to me than one complex expression.


I think it really depends on the language.

In languages that more easily support repl-driven development (e.g. Clojure), I think this is less of an issue. If you have a handful of pure functions, you can quickly and easily execute them via the repl, so you get a lot of clarity as to what those intermediate values look like even if the functions are ultimately used in a more point-free style.

But on the other hand, this would be a nightmare in C# (what I use in my day job). Sure, you can execute arbitrary expressions while debugging C#, but IMO you can't really achieve the same clarity. I'd rather see intermediate values like you suggest since it's easier while debugging, vs a bunch of nested function calls.


I agree that

(1) named intermediate values are sometimes more readable ... though I have examples where it's very hard to come up with names and not sure it helped

(2) debugging is easier.

For (2) though, this IMO is a problem with the debugger. The debugger should allow stepping by statement/expression instead of only by line (or whatever it's currently doing). If the debugger stopped at each pipe and showed in values (2) would mostly be solved. I used a debugger that worked by statements instead of lines once 34 years ago. Sadly I haven't seen once since. It should be optional though as it's a tradeoff. Stepping through some code can get really tedious if there are lots of steps.


Intermediate variables also have the benefit to make not just the last value available in a debugger view, but also previous values (stored in separate variables). Of course, a debugger could remember the last few values you stepped through, but without being bound to named variables, presentation would be difficult.


It's hard to understand which statement the debugger has a break point set to when you can put many breakpoints on the same line

I have tools that can do it, but I'll still have a better time splitting out a variable for it, especially since what I really want is a log of all the intermediate values, so I can replicate what it's doing on paper


Would be cool if it got up to 100% one day


Nope. In the "good old days" corpos got thay a move like this would kill morale. Nowadays in the "you should be grateful you have a job" days corpos no longer care. It's great because they can squeeze more work from the people left behind and they also have flexibility when it comes to opportunistically shedding workers around key date (ie earnings)


yeah most american's don't receive severance outside unpaid vacation, the funny thing is that the people who need it most usually don't


as long as they don't ban the sugardaddy apps I don't care what UT Austin does


i think the concept originated with lisa


Likely more with the Xerox stuff that Apple uhh... "improved upon"...

https://interface-experience.org/objects/xerox-star-8010-inf...


It wouldn't suprise me if that was the case


it was made to look like a car streo i guess


it's crazy how fast smoking died out in the US even 10 years ago it felt people were puffing away all over the place


Indeed. Now we just need to do the same for overeating.


I don't think mastadon will be around that long, it's the most antisocial of the microblogging platforms

I see a lot of posts but it's very rare that there's a reply or conversation in even 1% of them


I’ve been on it for the last 6 years and it has always been a very active place.

Don’t confuse:

"I’m discovering it now" with "it’s new and will not last long"

and

"Because I’m new, I don’t have the code thus very few engagement" with "there’s no engagement there".


I'm not new I've been "using" it on and off for almost as long


Yet you don't even know how to spell Mastodon.


well that's not a good sign


> it's very rare that there's a reply or conversation in even 1% of them

The interaction we used to see on Twitter is largely dead as well. Few people with followings in the thousands will engage with someone outside their small circle. Many block for trivial reasons. It's not what it was a decade ago.


Weird, my experience has been the precise opposite. I've gotten far more interactions on Mastodon than I ever did on Twitter, especially if I make sure to tag my posts appropriately. YMMV, I guess.


Not my experience at all. The people I follow have very active followers. It’s a much better experience compared with Twitter.


I don't know anyone who isn't in computers for work who even knows what mastadon is


I'd say the same about RSS!

Still love RSS :D


RSS during its heyday was much more will known since many sites had RSS badges/icons for you to add them to your reader. Mastodon is nowhere near as popular or well known as RSS and I think will never be.


Statusnet began more than 15 years ago.

You don't think mastadon (sp) will be around for long. How much longer do you think it has? Mastodon began 6 years ago and has seen nothing but upward growth since.


> I see a lot of posts but it's very rare that there's a reply or conversation in even 1% of them

Less than 1% of tweets have replies or conversations. Most of what people have to say just isn't interesting.


Interaction probably depends on community. I have no problem interacting, conversing, etc in the Rust and Art context. It's quite nice


masto, not masta


or, rather, -odon (i.e. tooth), not -adon.


He bought twitter and attempted a refund


also avoids adblock


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: