HNHacker News
TopNewBestAskShowJobs

danneu

1,932 karma · joined February 2, 2011

submissionscomments
danneu··on Kotlin 1.1 Released with JavaScript Support, Coroutines and more
For fun, I've been working on a simple hobby web server in Kotlin that wraps Jetty: https://github.com/danneu/kog

I think Kotlin is the statically-typed language I've been waiting for, especially with the team's interest in native and JS targets.

danneu··on Show HN: Clozemaster – Learn language in context
Clozemaster is great and has already become part of my daily drill.

I noticed that my daily streak grows just from doing a single exercise that day.

I recommend letting us set a point threshold (maybe low | medium | high) that we must meet to include the day in our streak.

It's a lot more motivating and beneficial to maintain a streak that requires an investment of 15-30 min/day.

danneu··on Callback Hell (2016)
Now let's say you're in a route handler where the buck stops, and you need to compose any number of async calls, some branching on if-else logic and/or the results of other async calls.

This is where the "just wrap it" argument breaks down.

Though I think promises are only slightly better when you have if-else branches that add to the async chain. It's not til async/await where Javascript finally hits its stride.

danneu··on Callback Hell (2016)
Extracting inline callbacks leads to indirection, especially if you're only extracting to avoid indentation. It doesn't make the code simpler or easier to follow.

Promises and especially async/await let you read code top to bottom once more, with other benefits like monad chains that catch synchronous failure.

danneu··on No link between eating dinner after 8pm, obesity in children
Finally, an article to link to my girlfriend when she finds me eating ice cream at 3am. It's a stretch, but I'm easily convinced after 8pm.
danneu··on After a Stroke at 33 a Writer Relies on Journals to Piece Together Her Own Story
I can imagine a (tragic?) sci-fi love story where a once-couple meets again thousands of years in the future.

One of them opted to keep their memories of the other on every reincarnation all those millennia, but the other didn't.

danneu··on Show HN: Kog, a simple kotlin server inspired by clojure's ring (just for fun)

    val handler = Router {
        get("/", fun(): Handler = {
            Response().text("Hello, world")
        })
        get("/<a>/<b>/<c>", fun(a: Int, b: Int, c: Int): Handler = {
            Response().json(J.obj("sum" to J.num(a + b + c)))
        })
    }.handler()

    Server(handler).listen(3000)

It has a lot of features half-stubbed out to a hobbyware level from a type-safe router to content negotiation to JSON decoder combinators.

I was in the market for a statically-typed language to use on the server and gave Kotlin a shot.

After rewriting an old, large log-parsing program, I was impressed with Kotlin's mix of simplicity and expressiveness. The designers definitely spent some quality hammock time.

I wrapped Jetty's `(Request, Response) -> Unit` signature in a `(Request) -> Response` signature which I always liked because it's easier to test and it means middleware becomes a higher-order function `((Req) -> Res) -> ((Req) -> Res)`.

It has some goofy abstractions, too, and plenty of `// TODO:`'s in the code. I couldn't even figure out how to get it working with jRebel much less roll my own hot reload.

But I think I got it to a point where it might be interesting to other weekend-ware warriors.

danneu··on Ask HN: What mistakes did you make in your first software engineering job?
I refactored the User.rb file of a massive, legacy Rails app with that classic save-the-world beginner hubris.

For one, I thought I was helping out by alphabetizing all the methods.

Ended up with a diff that basically scrambled all 100k lines of the project's largest file. It's probably still causing merge conflicts to this day.

danneu··on Elm is Wrong
http://package.elm-lang.org/packages/eeue56/elm-all-dict/2.0... is an example of a Dict where you pass in a custom (key -> comparable) function when initializing the datastructure.
danneu··on Elm is Wrong
The restriction only applies to native modules (modules that ship with Javascript): https://groups.google.com/forum/#!msg/elm-dev/1JW6wknkDIo/H9...
danneu··on Async/await support in Firefox
Await doesn't synchronously block in Javascript.

http://docs.scala-lang.org/overviews/core/futures.html#block...

danneu··on Ask HN: Why is everything in JavaScript changing so fast?

    > if I'm server side and using something dynamic, I might as well 
    > use something nicer like ruby or python.
You could say the same thing about Javascript. "Might as well use the language I already use on the front-end."

The code is pretty much identical between Ruby, Python, and Javascript once you have a yield/await abstraction in the latter.

danneu··on Nintendo Switch – New Video Game System [video]
Growing up, my family would do a 24 hour drive to visit family in Pennsylvania, and my dad would get the Sega/N64 working in the van with an inverter for my sisters and me to play on this tiny 10in screen. I looked forward to the 24 hour drive because we'd play games like Mario Kart the whole time.

Not an easy drive to make with triplets, but we loved it. Didn't make a peep.

danneu··on Node v6.9.0 (LTS)
I'd rethink that. Every connection to the server closes, and whatever else it might be doing stops, because someone hits your syntax error? And they completely DoS your server by slowly refreshing the page?

Surely the best practice is to use something like koa or otherwise create a promise chain with a top-level 500 handler.

danneu··on Elm and Phoenix/Elixir in Production for France TV
Some interactions with 3rd party libraries (like rendering stuff, leaflet.js, pixi.js) fall along natural event-driven faults, like the game update tick finishing, something managed by Elm being clicked, that sort of thing. In these cases, ports (events) are the obvious fit.

Then there's synchronous 3rd party library stuff where you just want to execute a Javascript function, like a math function that you aren't going to reimplement in Elm. In that case, I wrap the function with a native module and call it like an Elm function. Since you talk of computation, is this what you're talking about?

The Elm community highly discourages native modules. For one thing, they aren't very well documented and the API seems to have recently changed. But I'm not sure what the alternative is.

danneu··on What should go into JSX 2.0?
And you can inline if-statements with an IIFE when you need a little more space:

    {(() => {
      if (cond1 && cond2)
        return <div>foo</div>
      else 
        ...
    })()}
Though it makes GitHub think it's a Clojure file.
danneu··on Elm and Phoenix/Elixir in Production for France TV
It's not much.

On the Javascript side, the Elm `app` is like an event emitter where you listen for updates and send it data.

    var app = Elm.Main.embed(...)
    app.ports.gameState.subscribe((data) => ...)
    app.ports.tileClick.send([x, y])
On the Elm side, you subscribe to incoming ports and map them into Msgs. And you emit to ports with Cmds from your update function.

    -- Ports.elm
    port gameState : Json.Encode.Value -> Cmd msg  // Outgoing
    port tileClicked : ((Int, Int) -> msg) -> Sub msg  // Incoming

    -- Main.elm
    update msg model =
      case msg of
        Tick ->
          -- Define `encode` to Json.Encode the game state
          (model, Ports.gameState (GameState.encode data))
        TileClicked (x, y) ->
          -- Handle tile clicks sent in from Javascript
          
    subscriptions model =
      Ports.tileClicked TileClicked
danneu··on Show HN: Styled-components – Use the best of ES6 to style React apps
The cutting edge of front-end development has been arriving at ways to split business logic from layout elements for some time now.

Redux, Om, Reframe, Elm, etc. They all amount to hooking up components to a state transactor where the business logic lives separately.

Semantic HTML seems like a trade-off where you clean your markup at the expense of indirection, not a universal aspiration. And components don't dictate where your styling should live.

danneu··on TypeScript Seals My Penchant for JavaScript
It's nice to fire up an old Elm app and be able to make changes immediately.

Not just because of the compiler errors, but also because of its other limitations, like having your effects isolated via `Cmd`s and ports.

danneu··on TypeScript Seals My Penchant for JavaScript
I used Clojure for three years before realizing that all of the dynamically typed languages you listed still have the same hard problems: making large code changes and reasoning about existing code. I also realized that in the real world, technical superiority is overrated, and the difference between these languages is overestimated.

Javascript is ubiquitous, runs in the browser + server, everyone I meet in the wild has to know it, and it has static typing options. It's not easy to shove those aspects under the rug to justify another language. It takes something else, mostly depending on just who I'm working with and then on what we're building.

danneu··on Adblock Plus now sells ads
Yes, I run such websites.

A paid tier is a surprisingly narrow business model. People aren't willing to pay for much, and not every website has such an explicit product. A lot of that is just conditioning, as people aren't used to having to pay for anything since ads. And most people see ads as zero-cost. The second you start charging a dollar, now you're the guy charging the dollar that nobody else is.

How many forums do you pay for?

And donations are almost always a joke. Else you wouldn't have to beg in a way that puts most ads to shame: https://dl.dropboxusercontent.com/spa/quq37nq1583x0lf/nv9ad0..., and that's for a website that brings value to just about everyone that touches the internet.

danneu··on Pgslice: Postgres partitioning as easy as pie
I meant that the code has to be deployed to a separate system.

Application code that touches the file system is still deployed along with the application code.

You might commit schema.sql into your application repository, but that's not the state of your database.

danneu··on Pgslice: Postgres partitioning as easy as pie
You're updating code that needs to be executed against an external layer instead of just the application layer.
danneu··on Nootropics
Also, "working hard" is pretty meaningless without context, especially if we're going to talk about regretting it.

For example, carving out some time at night for your side projects that might pay your rent one day vs. staying longer at work to get a leg up on imminent deadlines that were too aggressive vs. working hard to be Employee of the Month vs. working hard to learn programming.

danneu··on Practice coding with fun programming challenges

    > Start slow, build your foundation, learn your bits and bytes,
    > data structures and sorting algorithms first then venture out.
Maybe that works if you've already convinced yourself that you're going to learn to program no matter what. That certainly wasn't me, though.

In my experience, the challenge for beginners is that they lose interest and make no progress at all, not that they take some suboptimal path.

It's like picking up a guitar. You can come up with the Perfect Five-Year Roadmap and preach about how someone should first learn music theory and proper form before taking a crack at it. But for most people, that's dull and they'd never learn guitar if they had to do that before jumping in and just trying.

I think beginners should optimize for doing anything at all, and nothing should be advised against as a suboptimal route. The optimal route is the one that compels them, even if it amounts to faking it til they make it with a game framework and devoting 75% of their time to things completely unrelated to programming.

Sorting algorithms? Bits and bytes? Seriously? I started dozing off during that sentence and I've been programming in some form for at least 10 years. That's not how you're going to woo most people into programming.

danneu··on Static Website Generators
The comments on my technical blog were always so friendly and encouraging. People telling me how my tutorial helped them or answering each others questions.

Redirecting them to the HN pit of cynicism and leave-no-stone-left-unturnedism sounds awful. :)

danneu··on Static Website Generators
Well, hopefully an SSG is saving you time compared to just writing a quick crawler that saves each route of your local Express app into a deployable static folder.

If you find yourself credentializing in the source of an SSG because it turns out you're doing something it doesn't support, then there's a point where it might've been faster to build as a dynamic site (more general tooling) with a static site build step.

It's an easy place to find yourself since so many SSGs generalize around blogging.

danneu··on Amphetamine boosts rats’ recovery from brain injuries
In my experience, IR builds tolerance way too fast.

I agree that it would be nice to have IR for those times you want shorter bursts. But I ran into its shortcomings too quickly as a daily burner, not so different than trying to therapeutically bump cocaine.

There's also dirt cheap generic IR but there wasn't generic XR back then (still?).

danneu··on Amphetamine boosts rats’ recovery from brain injuries

    > Vyvanse put me to sleep, adderal-xr worked, but the "come down" sucks
Adderall does have a bad come down. Often depressive even on low XR doses.

Vyvanse is still amphetamine, so if it put you to sleep, are you sure you took enough?

20mg Adderall XR is about equivalent to 50mg Vyvanse, which is what I take.

Everyone I know switched from Adderall to Vyvanse and we all report the same thing -- much more gradual curve throughout the day and far less depressive on the come down. I'd consider Adderall XR to be a real tweak compared to Vyvanse and far less therapeutic for a day-to-day drug.

danneu··on Amphetamine boosts rats’ recovery from brain injuries
30mg instant release is a pretty high dose of Adderall as opposed to 30mg extended release.

I can't think of a single upside of IR over XR unless you use it recreationally and want that steep curve.

← PreviousPage 2 of 26Next →