HN user

mgreenw

55 karma
Posts1
Comments18
View on HN

Try using `run` in the return of a React (or similar) component and you'll never go back ;)

There is always a balance here. I'm not saying to never extract a named function, and there is certainly good reason to do that, especially if the function is called elsewhere or is quite complex.

But, in many cases, the inline logic is more readable because it's right there, and the function really doesn't need a name.

I am in love with “everything is an expression” from my time with Rust

Totally agreed! I wish JS had if expressions (maybe in the future?). It doesn't seem like such a huge change if it were rolled out slowly like other new syntax features but maybe I have no idea what I'm talking about.

Hopefully things like `run` can help move the needle on this. I like it because it feels more FP and intentional than IIFE's everywhere.

Yes, I do think the extra parens are less readable.

Its not about number of characters, its about reasoning that the inline function that you just wrapped in parens is then called later, potentially after many lines. At least with `run` it's immediately clear based on the name that you are running the function.

Edit: This is pretty funny. I'm a parensaphobe! (not really) https://www.reddit.com/r/ProgrammerHumor/comments/qawpws/the...

Completely agreed, and I use this if-based early return syntax frequently! That being said, I like using `if` and `else if` and `else`, but maybe that's just me! I don't think there's a substantial difference in readability or utility.

Well you definitely can do that to my somewhat contrived example that is loosely based off of an example from the `do` expression proposal, but I'm not sure its better.

Part of the beauty of `run` is that you don't have to declare and name a function `calcX`. In longer and more complex examples, declaring a function inline like this is potentially confusing because you don't get to see where it is used, whereas with `run` you assign the return value immediately to a variable.

Yea that's fair, and I totally understand when sites limit to newer (last 2-3 years) versions of browsers or limit to Chrome, Safari, and Firefox.

But to cap it at just Chrome like its 2012 when browser compatibility has come such a long way is likely unnecessary and frankly lazy on their part. I can't think of an API that they definitely would need to use that isn't in Firefox.

How is it possible that in 2023 they can't support Firefox and Safari?

Update: It works totally fine on Firefox if you use an extension to lie about your user agent. What a joke.

Rooted Farmers | Full Stack Software Engineer (Typescript, React, PostgreSQL) | Remote (Northeastern US) | Full-Time | https://www.rootedfarmers.com

Rooted Farmers is an agricultural technology startup dedicated to providing small farms with the tools and resources necessary for growing and scaling their businesses. We serve as an online sales platform, connecting farmers with local businesses and shoppers.

Rooted is comprised of a small but growing team of passionate doers based in the Northeast. We are seeking a mission-driven Software Engineer who is committed to empowering women-led businesses; you will be responsible for tackling major development projects, building simple and beautiful application interfaces, and expanding the company's technical infrastructure.

Requirements:

  - 1+ years experience with Typescript (Node.js and React)
  - Previous work or internship experience

Rooted Farmers | Full Stack Software Engineer (Typescript, React, PostgreSQL) | Remote (Northeastern US) | Full-Time | https://www.rootedfarmers.com

Rooted Farmers is an agricultural technology startup dedicated to providing small farms with the tools and resources necessary for growing and scaling their businesses. We serve as an online sales platform, connecting farmers with local businesses and shoppers.

Rooted is comprised of a small but growing team of passionate doers based in the Northeast. We are seeking a mission-driven Software Engineer who is committed to empowering women-led businesses; you will be responsible for tackling major development projects, building simple and beautiful application interfaces, and expanding the company's technical infrastructure.

Requirements:

  - 1+ years experience with Typescript (Node.js and React)
  - Previous work or internship experience