Readit News logoReadit News
mcaruso commented on PHP 8.5 adds pipe operator   thephp.foundation/blog/20... · Posted by u/lemper
donatj · 4 months ago
I had this argument in the PHP community when the feature was being discussed, but I think the syntax is much more complicated to read, requiring backtracking to understand. It might be easier to write.

Imagine you're just scanning code you're unfamiliar with trying to identify the symbols. Make sense of inputs and outputs, and you come to something as follows.

    $result = $arr
        |> fn($x) => array_column($x, 'values')
        |> fn($x) => array_merge(...$x)
        |> fn($x) => array_reduce($x, fn($carry, $item) => $carry + $item, 0)
        |> fn($x) => str_repeat('x', $x);
Look at this operation imaging your reading a big section of code you didn't write. This is embedded within hundreds or thousands of lines. Try to just make sense of what "result" is here? Do your eyes immediately shoot to its final line to get the return type?

My initial desire is to know what $result is generally speaking, before I decide if I want to dive into its derivation.

It's a string. To find that out though, you have to skip all the way to the final line to understand what the type of $result is. When you're just making sense of code, it's far more about the destination than the path to get there, and understanding these require you to read them backwards.

Call me old fashioned, I guess, but the self-documentating nature of a couple variables defining what things are or are doing seems important to writing maintainable code and lowering the maintainers' cognitive load.

    $values = array_merge(...array_column($arr, 'values'));
    $total  = array_reduce($values, fn($carry, $item) => $carry + $item, 0);

    $result = str_repeat('x', $x);

mcaruso · 4 months ago
People use method chaining all the time and don't have any issue with it? It's equivalent to something like:

    $result = $arr
        ->column('values')
        ->merge()
        ->reduce(fn($carry, $item) => $carry + $item, 0)
        ->repeat('x');
I think this just comes down to familiarity.

mcaruso commented on JavaScript dos and donts Mu-An Chiou   muan.co/posts/javascript... · Posted by u/mpweiher
another-dave · a year ago
To me, I think this is where HTML standards went off the rails.

Rather than working on, say, the vibration API, give us built in web components that are stylable but also accessible by default.

In 2024, half of the things in Bootstrap or Tailwind UI should be obsolete. Where's our OOTB carousel, date picker, rich drop-down with icon/subtext, form elements supporting AJAX state, modal windows? etc etc.

All of these things should be as foolproof as an unordered list for devs to implement & the quality of websites in terms of performance & accessibility would be lifted massively

mcaruso · a year ago
> Where's our OOTB carousel, date picker, rich drop-down with icon/subtext, form elements supporting AJAX state, modal windows? etc etc.

You might want to take a look at what browsers have been working on lately, because a lot of what you're asking is either already here or actively developed. Some of it driven by the Open UI working group (https://open-ui.org).

- Modal: see the <dialog> element, with its focus trapping out of the box, stylability through the top layer, entry and exit animations through @starting-style and the ability to transition discrete properties like `display`, etc.

- Rich dropdown: browsers now support popovers, which allow you (without any JS) trigger a popover that overlays the screen in the top layer, and with automatic focus management. See also the work being done on stylable <select> elements, there's a great episode of Off The Main Thread that goes deep into all the work being done to make this happen [1].

- Carousel: see the recent work on stylable <details> elements [2], and in general the carousel project at Open UI. After <select>, the carousel is one of the main focus areas.

[1] https://offthemainthread.tech/episode/stylable-select-elemen...

[2] https://chromestatus.com/feature/5112013093339136

[3] https://open-ui.org/components/carousel.research

mcaruso commented on HN's HTML Is Invalid   validator.w3.org/nu/?doc=... · Posted by u/dickfickling
petee · 2 years ago
I'm mistaken then; from the block you copy and pasted I misread it to suggest only IE 9 cares about quirks. In my personal use I'd never seen it matter cross-browser before

That said, HN works fine.

mcaruso · 2 years ago
Of course HN works fine, if it didn't work fine it'd be fixed by now. "Working fine" is an extremely low bar for any site. As a developer you will still want to avoid quirks mode because it just makes your life harder for no reason.
mcaruso commented on Abstraction: Not what you think it is   pathsensitive.com/2022/03... · Posted by u/tempodox
dgb23 · 4 years ago
The discussion about abstraction in this article is interesting and thought provoking. It's useful to think about the different things we call abstractions. Very much worth a read.

But I feel like it tries a bit too hard to re-define what abstraction means ("only this subset of abstractions are real abstractions"), instead of just putting "abstract interpretation" next to it. This idea can stand on its own without trying to re-define the world.

Secondly I understand the discussed notion of abstraction as a domain model, which is information (data and functions) _about_ the world. I like the term model better here than "idealized mapping" because the former implies a bit more that there are assumptions about the data and usage context of said model (often implicit, unstated) and that it is incomplete.

mcaruso · 4 years ago
From the article:

> But we've had a pretty good definition of abstraction since 1977, originally in the context of program analysis, and — I claim — it actually translates quite well into a precise definition of “abstraction” in engineering.

So I don't think the author is saying that all these other people are "wrong", but rather that this one particular definition seems to capture the underlying essence of what we intuitively think of when we say "abstraction", and the rest of the "hodgepodge of different concepts" break down if you analyze them a bit deeper (as the author did in the "Not Abstraction" section).

mcaruso commented on Fetch API has landed into Node.js   github.com/nodejs/node/co... · Posted by u/yamafaktory
thyrox · 4 years ago
My biggest issue with node when I was working on it briefly was I couldn't do the 'import' statements like wepback. Are they supported too now?

I'm not a web developer so I had a very hard time understanding why there are so many different type of imports in JavaScript like require, import, umd, amd, etc and which one works in browser and which one works in node?

Also why do so many libraries have this strange 5 line header code for this umd, amd, business. Is that to make their packages work with nodejs?

Does anyone who knows enough JavaScript point me in the right direction about it. I find all this very confusing.

mcaruso · 4 years ago
Node supports ES Modules (the import statements you mention) natively now: https://nodejs.org/api/esm.html
mcaruso commented on A pipe operator for JavaScript: introduction and use cases   2ality.com/2022/01/pipe-o... · Posted by u/kiyanwang
irrational · 4 years ago
I disagree. A true begineer is unlikely to be familiar with bash or these other languages.

Syntax like + - / * () = etc. are not esoteric since, for the most part, they work similar to math they learned in school.

But => and |? They are esoteric. As a beginner you have no idea what they will do without study.

mcaruso · 4 years ago
=> also comes straight from math learned in school. There it's written → (for function signatures), and (the more rare) ↦ for function definitions.
mcaruso commented on Semver doesn't mean major.minor.patch, it means fails.features.bugs   twitter.com/willmcgugan/s... · Posted by u/Tomte
dexterhaslem · 4 years ago
yes but didn't react do a big jump? like 0.13 -> 14.0 or such many moons ago. at any rate agree with the point
mcaruso · 4 years ago
0.x releases are also major versions according to semver, just pre-stable. So many people were referring to React 0.x releases as "React x" that they just bumped it straight to version x.
mcaruso commented on Functools – The Power of Higher-Order Functions in Python   martinheinz.dev/blog/52... · Posted by u/gilad
roenxi · 4 years ago
Because an if statement is very constrained in what it can do. Every if statement has two branches (maybe one is a no-op) and one of them executes. If someone sees an if statement, it is implementing a fork in the code path.

A function can do literally anything. Seeing a function call, it hasn't narrowed down the realm of what might be happening even a little bit.

"lambda f:" gives away very little information about what is about to happen. "if f:" gives away some information about what is about to happen.

Not a perfect rule of thumb, convoluted if statements do exist. But that is why functions are more in need of hints and comments than other control structures.

mcaruso · 4 years ago
Lambdas are constrained by their type. If you see a lambda being passed to, let's say `map`, then (assuming you know the type of `map`) you know the type of the passed lambda.

Of course this assumes the lambda is pure, but in the kind of code we're talking about (pseudofunctional code with lots of higher-order functions) they should be pure for the most part.

mcaruso commented on Koka: A Functional Language with Effects   github.com/koka-lang/koka... · Posted by u/pjmlp
bitmapper · 4 years ago
eh, iirc fused-effects is used in production, along with haskell (obviously)
mcaruso · 4 years ago
Was just pointing out a nice (probably unintentional) pun
mcaruso commented on Koka: A Functional Language with Effects   github.com/koka-lang/koka... · Posted by u/pjmlp
nerdponx · 4 years ago
Others off the top of my head in no particular order (all effectively research languages): Multicore Ocaml, Eff, Frank, Effekt, Helium, Links. Also Fused Effects in Haskell and an experimental library for it in Idris. I guess the Common Lisp condition system could be used for general effect handling too, albeit without type-level guarantees.
mcaruso · 4 years ago
> (all _effect_ively research languages)

:)

u/mcaruso

KarmaCake day165November 12, 2009View Original