7 ms·
The following example code is a bit hard to read: const { status } = await send(capitalize(greeting) + "!") console.log(status) I disagree, I find this ex
by smilingemoji 3y ago
The following example code is a bit hard to read:
const { status } = await send(capitalize(greeting) + "!")
console.log(status)
I disagree, I find this example code very easy to read because it reads like idiomatic Javascript. Unlike this library.
- Piisamirotta 3y agoI agree, I really don't understand this library
- knubie 3y agoI think the implication is that it's difficult to read because it's read non-linearly. You first need to start in the middle at `greeting`, then work your way out to `capitalize` on the left, then to `+ "!"` on the right, then work your way out one more layer to the left with `send`. Some kind of pipe operator can make this easier to read by arranging the operations linearly from left to right (or top to bottom as is the case with this library). Although in my opinion this library has its own readability issues.
- moritzwarhier 3y agoI agree. In the example case, I don't see why left-to-right or top-to-bottom would be more readable. Sure, it is good most of the time, but operator precedence rules exist for a reason. I don't want to read 2.chain(x => x * 2).chain(f) instead of f(2*x) These patterns have their place for async programming, pure FP, streams and more. They can also be a distraction. E.g. the library introduces its own promise-unwrapping semantics and more. I don't see the use for such a generic implementation, although I applaud the effort.
- madeofpalk 3y agoRight - because this library tries to fake a new language syntax feature without the actual support for it, it ends up being the worst of both worlds. Even ignoring the lines-of-code explosion, the non-standard use of parens/spacing makes it incredible difficult for me to parse. Props to the author for trying out something neat, but this is probably a bit to clever for my liking.
- spoiler 3y ago> the non-standard use of parens/spacing makes it incredible difficult for me to parse. Same here. Not to mention this wouldn't work in a codebase with an autoformatter.The idea/API is clever. So, a pretty cool experiment I suppose
- FroLeMageBlanc 3y agoAuthor here. Thanks for your nice comment. I added a note to say it does work with autoformatters too. Actually someone in a comment below said he or she prefers the autoformatted syntax.
- spoiler 3y agoOh, that's good to know! I haven't tried it and assumed an auto formatter might misalign some of it or put things on the same line, so the visual "downward arrow" appearance would be lost Edit: I just checked the docs again and while it does look a bit "misaligned" at the start, I do think it looks more readable with the autoformatted version. Pretty cool!
- newtom 3y agoJust an FYI to folks, there has been a proposal to add pipes to JavaScript for a few years: https://github.com/tc39/proposal-pipeline-operator https://github.com/tc39/proposal-pipeline-operator
- BerislavLopac 3y agoWhich supports the age-old notion that readability is in the eyes of the reader.
- weego 3y agoYeah, it's concerning when even the contrived first example is less clear in the 'solution' than it is in the alleged problem.
- gnfargbl 3y agoIf you read all the text, it seems like the entire repo is intended to be a satire on https://github.com/tc39/proposal-pipeline-operator https://github.com/tc39/proposal-pipeline-operator.
- code_runner 3y agoUnfortunately I’m not getting satire vibes from that blurb. I’m only more scared for JavaScript. I love JavaScript but this pipe thing is horrific.
- toastercat 3y agoTell that to Unix/FP lovers.
- code_runner 3y agohahaha i mean this implementation. piping things in the shell is great
- toastercat 3y agoAhh OK. Yeah, I always find trying to shoehorn language semantics via functions to be kinda awkward. The best attempt I've seen is this addition of async/await to Lua, which actually looks pretty usable [1]. [1] https://github.com/ms-jpq/lua-async-await https://github.com/ms-jpq/lua-async-await
- jeroenhd 3y agoIs it? I think it's an implementation of the pipe operator rather than satire of it. Javascript doesn't provide the flexibility to extend the language with pipe operators (though tools like Babel will let you use the pipe operator already). The clunky syntax removes all the benefits of the pipe operator. The entire thing is syntactic sugar, wrapping it in confusing functions just breaks the entire concept.
- pwdisswordfishc 3y ago
- afavour 3y agoI agree with the author that it’s a little confusing, but that’s why I wouldn’t write code like that. const msg = capitalize(greeting) + “!”; const { status } = await send(msg); console.log(status); Now it’s perfectly readable, no weird shenanigans required.
- jameshart 3y agoBut at what cost? You had to name two intermediate variables - and naming things is hard.
- progx 3y agoIn this case the variable is the documentation of the code. You don't have to write something like "this is the message", you can see it.
- amadeuspagel 3y agoWhat if it isn't a message? What if "msg" is already used for another variable?
- afavour 3y agoThis is some wonderful performance art you’re doing here
- Bjartr 3y ago`greetingMsg`? `greeting`? Naming the other one differently? Splitting the work done with that message and the work done with this message into their own functions?
- wruza 3y agoFrankly, this always sounded like a readability issue seeking a readability problem. Splitting because the names clash, because you decided to name things, because a one-liner was less than ideally readable.
- toastercat 3y agoThe strength of the pipeline operators comes when you have to do method chaining things like: const foo = capitalize(underline(reverse(exclaim(indent(value))))); I already forgot the amount of parentheses I needed to close with while typing that.
- rat9988 3y agoNo worries your ide will help you for the parentheses.
- toastercat 3y agoIDEs and linters should not be a crutch methinks because not everyone uses the same IDE or text editor. Either way, it will still be awkward to read. Better that you either avoid that pattern or at least indent it in such a way that its not so visually confusing. Or yknow use a pipe operator.
- fshr 3y agoPeople do tend to use the same linter and LSP. That’s why they exist in the first place.
- williamcotton 3y agovalue.indent() .exclaim() .reverse() .underline() .capitalize() There’s always the OOP version of method chaining!
- jonahx 3y agoThis won't look as good when you include all the boilerplate which defines those methods, and which needs to be repeated or otherwise included for every "value" type. You don't have to worry about this when they are pure utility functions.
- mhink 3y agoWhich is great until Prettier, in its infinite wisdom, decides it's better to stick four of these function invocations on one line and two on the next, so you have an obnoxious mishmash of tokens!
- slmjkdbtl 3y agoIt's funny that their example is much harder to read
- kderbyma 3y agoAgreed.
- deleted 3y ago[deleted]