Better HN
topnewbestaskshowjobs
Log inSign up

simplify

2,061 karma · joined May 24, 2009 (17y ago) · 911 submissions

Submissions

comment 7y ago · link · parent

Mithril is a true work of art. Rendering, routing, and XHR are all provided in a bundle under 10kb. All pure JavaScript with no compilation needed. Closure-style components that make React Hooks look wholly unnecessary. And the list goes on.

So many correct decisions made, slowly and carefully, by a fantastic community that values discovering the right way to do things above all else.

comment 7y ago · link · parent

This comment is classic bulverism. You need to explain how the author is wrong to have a valid argument.

comment 7y ago · link · parent

Happy to see this being pointed out. Sleep is the single most important factor in code quality & correctness https://twitter.com/hillelogram/status/1119709859979714560

comment 7y ago · link · parent

How is it easier to on-board new engineers? You mentioned but did not explain this point.

comment 7y ago · link · parent

Yes, the correct syntax is:

    const [foo, bar] = await Promise.all([async1(), async2()])

comment 7y ago · link · parent

But they did put a bunch of monkeys in a room, and to opposite effect. Read the link for more info.

comment 7y ago · link · parent

That story is entirely fiction: http://www.throwcase.com/2014/12/21/that-five-monkeys-and-a-...

comment 7y ago · link · parent

You can use short circuiting instead:

    <div>
      {items.length === 0 &&
        <p>No items.</p>
      }
      {items.length === 1 &&
        <p>Warning: You only have 1 item, at least 2 is required</p>
      }
      {items.map(...)}
    </div>
`false` is not rendered by react, so this code is perfectly fine.

comment 7y ago · link · parent

How do you invest a would-be down payment such that it compounds effectively?

comment 7y ago · link · parent

A fascinating part about Sorbet is it did not have to introduce any additional syntax to Ruby (unlike TypeScript, for example). This really speaks to the expressiveness of Ruby. Very cool.

comment 7y ago · link · parent

Yes, and it's also not as severe or "a sign of being stupid" as many think. Cognitive dissonance occurs in situations as simple as walking to a store and discovering the store is closed.

comment 7y ago · link · parent

Not just. It's the best one!

comment 7y ago · link · parent

Agreed. If Elixir had static typing then Phoenix would be my dream framework!

comment 7y ago · link · parent

Hindley-Milner is a solid place to start. Here's an introduction: http://akgupta.ca/blog/2013/05/14/so-you-still-dont-understa...

comment 7y ago · link · parent

> I just cannot take a type system seriously when workarounds like that are needed.

Are you familiar with type theory and how easy it is for a type system to require too much work to be useful? Especially with conditional types. TypeScript has been doing a phenomenal job.

For this particular use case, since version 3.4 you can write `'x' as const` which will work no matter how large your type is.

376.

Render – Heroku-like cloud hosting at a better price(render.com ↗)

2 points · by simplify · 7y ago · discuss

comment 7y ago · link · parent

What makes these ideas "micro"? They seem like normal SaaS to me.

comment 7y ago · link · parent

What's wrong with working with plain arrays? Genuine question, they seem to work fine for me so far.

comment 7y ago · link · parent

Mammoth https://github.com/Ff00ff/mammoth is also worth paying attention to. Still early, but a promising approach.

comment 7y ago · link · parent

Lots of replies saying it "depends on your use case", but zeit's departure from v1 to v2 clearly shows they think serverless fits most use cases.

comment 7y ago · link · parent

Context IS NOT the most important concept in React. It's basically CSS cascading. Not something you want to introduce into your project so easily.

comment 7y ago · link · parent

CSS variables are actually superior to SASS variables because you can change them at runtime via JS.

comment 7y ago · link · parent

It's not academic, but we just published a guide that goes over the pros/cons of each type.

https://medium.com/@cspa_exam/a-guide-to-building-your-own-t...

comment 7y ago · link · parent

Looking at the talk, how is this different from markojs?

comment 7y ago · link · parent

Mithril.js has been doing plain javascript variables for years :) Basically, React's decision to use setState is an overoptimization. Mithril (and flutter, interestingly) opts for global redraws, greatly reduces end-user code complexity while still being fast for most all cases.

comment 7y ago · link · parent

> If you force it, then no one knows why things are they way they are.

It's more accurate to say "if you don't teach why' then no one knows why". Forcing or not has nothing to do with it.

I would argue "forcing" is strictly better, since learning discipline requires experience in doing things in every other wrong way. While that's great for learning on your own, I wouldn't want developers to "learn discipline" like this in production.

comment 7y ago · link · parent

Types are not just for autocompleting, but also for making illegal states unrepresentable[0].

For example, let's say you have Question model with two types: MultipleChoice and ShortAnswer. In TypeScript you can model it like this:

    type MultipleChoice = {
      mode: 'mc'
      body: string
      choices: string[]
      expectedAnswer: number
    }
    type ShortAnswer = {
      mode: 'sa'
      body: string
      exampleAnswer: string
    }

    type Question = MultipleChoice | ShortAnswer
TypeScript's compiler will then enforce data structure consistency across your entire codebase. For example, if you were rendering a question in React:

    type Props = {
      question: Question
    }
    const MyComponent = (props: Props) => {
      props.question.body // Ok, since all questions have a body
      props.question.choices // Type error, since only MC has choices

      if (props.question.mode === 'mc') {
        props.question.choices // Ok now, since we checked the mode of question
      }
    }
You can also use these types to force certain code to always be correct. For example, if you wanted to display a human-readable version of a Question's mode, you could write:

    const prettyQuestionType: Record<Question["mode"], string> = {
      mc: 'Multiple Choice',
      sa: 'Short Answer',
    }
and now TypeScript will force prettyQuestionType to contain keys for all modes. That includes when you add a new Question mode later.

Once you learn how to lean on the type checker, you think less about such details, and your mind becomes freer to think at a higher level, increasing your overall productivity. There is a learning curve though, so be aware.

[0] https://fsharpforfunandprofit.com/posts/designing-with-types...

comment 7y ago · link · parent

If that's the case, then document.querySelector works like a charm.

comment 7y ago · link · parent

Prisma looks good and I hope it succeeds.

Another interesting and unique approach I'd love to see get more attention is Mammoth[0]. Instead of abstracting the database away, you define columns using its raw primitives (in this case, Postgres) and in return get a type-safe client, along with auto-generated migrations.

I imagine this approach allows you to leverage the features of the database much more easily. And Postgres has quite a lot of rich features to take advantage of! :)

[0]: https://github.com/Ff00ff/mammoth

1
121314
31