Better HN
topnewbestaskshowjobs
Log inSign up

implicit

420 karma · joined Feb 20, 2009 (17y ago) · 99 submissions

Submissions

comment 11y ago · link · parent

Is ASI really worth the amount of time that has been spent discussing it?

It would be nice if it were deleted from the language entirely.

comment 11y ago · link · parent

In a normal ghci repl, you would be able to use the syntax "let name = expr", but this repl doesn't seem to support that.

My best guess is that it's because it's implemented as an HTTP service that happens not to retain the ghci process between expressions.

comment 11y ago · link · parent

This should be a perfectly fine answer and any interviewer who knows what they're doing should be prepared to roll with it. (by, for instance, pointing at the Sort() function and asking how it works)

The goal is never to see if a candidate can produce a specific program, but to watch them reason and explain that reasoning.

comment 11y ago · link · parent

Errors do indeed percolate down to 'e' at the end.

Data.Aeson.TH[1] can automatically generate JSON decoders and encoders for data types, if that's what you want.

[1] http://hackage.haskell.org/package/aeson-0.8.0.2/docs/Data-A...

comment 11y ago · link · parent

Meanwhile in Haskell

    instance FromJSON Person where
        parseJSON = withObject "Person" $ \o -> do
            name <- o .: "name"
            age  <- o .: "age"
            return (Person name age)

    let person = case decode some_bytestring of
            Success p -> p
            Error e   -> error "Malformed JSON"
It works with arbitrary data types (including enums!), lets you easily, exactly specify what sort of data to accept, and doesn't require stepping outside the language.

comment 11y ago · link · parent

If the generated JS were easier to read, js_of_ocaml would be very nearly perfect. I think OCaml's surface syntax is a bit ugly, but the semantics are great.

Particularly, I really like their solution to async programming. I'm paraphrasing a bit, but it looks very nearly identical to an ordinary let ... in binding:

    lwt result       = xhr "http://example.com" in
    lwt secondResult = xhr "this url will be fetched after the first one completes"
    and thirdResult  = xhr "this url will be fetched in parallel with the second"
    in (* use result, secondResult, and thirdResult here *)
This desugars into a nested callback structure having the right shape.

comment 12y ago · link · parent

Judging by the documentation, Urbit looks to be less about leveraging pre-existing work and more about reinventing computer science and software engineering from the ground up.

comment 12y ago · link · parent

We haven't hit the insanity limit quite yet.

It looks like Alon Zakai is working on something the "Emterpreter," which is a bytecode format that Emscripten could compile to to sacrifice some runtime performance for startup time. (JS parse time is quite a big deal for Emscripten applications)

I am hoping that this effort goes really really well. So well that browser engines start natively supporting this bytecode.

Then JS can actually die.

comment 12y ago · link · parent

My experience is that you can generally skate along on Haskell's type system and get further into a project without hitting the complexity threshold where you need tests to confidently make improvements.

Bigger and longer-lived projects benefit enormously from an automated test suite no matter what they're written in.

comment 12y ago · link · parent

About 23 minutes in, Mr. Blow says that lambdas has "questionable performance," but the actual cost is relatively predictable.

Current C++ compilers will try to inline lambdas. Mr. Blow's specific example will be inlined by both g++ and clang, (I haven't tested MSVC) depending on the optimization level you set.

std::function does introduce overhead, and the reason why is important:

How can you implement an array of lambdas that all accept the same signature, but close over different kinds of environments? You need to be able to copy and destruct those environments without static knowledge of how big they are and what's in them.

std::function makes this work by allocating the environment on the heap and hiding it from the type signature. If you are averse to this extra overhead, there's a really easy rule to follow: Until you actually explicitly write "std::function" in your code, you do not pay its cost.

I know a few ways around this:

If you always use auto when dealing with function-local lambdas, you don't pay any extra overhead. You can think of each lambda as being the sole instance of a struct that contains the environment to be closed over, plus a non-virtual method. Just be aware that no lambda is type-compatible with any other. (exception: two lambdas are type-compatible if they have empty environments and the same type signature)

You can templatize lambda-consuming functions over the type of the lambda. This can work out really well if you pay attention to how function inlining happens, as the compiler can not only inline the template function, but the lambda as well. You can generally assume that the compiler is capable of fully inlining maps and folds.

Lastly, if your lambda doesn't close over anything, you can cast it as a C-style function pointer.

comment 12y ago · link · parent

A lot of the mines are here for good.

I'd love to hear that someone is proposing that JS raise exceptions when you use mathematical operators on non-numeric data.

I really hope the Dart team succeeds. Their language has some problems, but nobody else working on the JavaScript Problem has both the motivation and the actual ability to challenge JavaScript's invincible monopoly on the web.

comment 12y ago · link · parent

I'm also really curious about the runtime performance of such a stack.

I like Haskell, but it's not what I reach for when I feel the compulsion to hoard memory carefully, and I'm very interested in precisely controlling memory on mobile devices.

comment 12y ago · link · parent

Guess the result of this fragment:

    ["1", "2", "3"].map(parseInt)

comment 12y ago · link · parent

Hi. I wrote that article.

I've never seen a Java application that hasn't succumbed to an unexpected NullPointerException at least once over its entire development cycle. That doesn't mean that the language isn't a reasonable choice. It's just a common problem that you have to accept on that platform.

Space leaks in Haskell are similar. You're going to run into them every so often, and you'd really rather not, but they're easy enough to deal with.

comment 12y ago · link · parent

I agree that shadowing is bad.

Implicitly scoping variables to their lexically-outermost point of use is a terrible solution, though: changing anything in any outer scope can completely change the meaning of code in all nested scopes. That's really really bad.

A much better syntax would is to require the 'var' keyword to denote the scope of every variable, but reject shadowed symbols at compile time.

comment 12y ago · link · parent

Agreed. I was responding more to the assertion that CoffeeScript doesn't have a problem with variable scoping rules.

It does and the consequences are scary.

comment 12y ago · link · parent

The argument that "you just don't understand" can excuse any flaw in anything.

If someone can reasonably choose to formulate something, and for that formulation to pass static verification but do something totally unexpected, the language is at fault, not the author.

comment 12y ago · link · parent

It's useful to consider developer maturity in terms of the maximum project complexity they can handle:

A junior developer can effectively build a software solution to something, given some advice about the interfaces and algorithms to be used.

A senior developer just needs a high level description of the desired technical solution. They can be trusted to instrument, refactor, collaborate, rewrite, invent, and get the problem solved.

A lead developer can be given bigger problems and organize an entire team of developers to tackle it.

This line of reasoning still works if you keep going:

A product manager can be given a metric to improve or a customer to satisfy. No further direction is required. They can be relied upon to do research, come up with a plan, hire staff (technical and nontechnical) and organize it all.

All CEOs have the same problem to solve: "Grow the business."

comment 12y ago · link · parent

One of my coworkers wrote a really cool bit of software to do this. I want him to open source it.

Basically, you can share a single socket amongst many servers. The OS ensures that just one process accepts each connection.

You can therefore have a manager process that owns the socket and passes it on to application processes.

To update, start new processes, then politely tell the old ones to go away.

comment 12y ago · link · parent

It's a huge help to ask a newcomer to start off by make changes to an already-established project that has best practices and idioms already sorted.

If you just start with the full language, there are just too many ways to solve every problem and it's not clear which is better for your particular use case. It's a bit like Perl, except moreso: even basic flow control is a library.

comment 12y ago · link · parent

We track Haskell threads.

edit: Found the code. :)

We rolled our own implementation. Our WAI application action increments a counter and decrements it again whenever an HTTP request is received and completed.

It doesn't track threads created as a part of HTTP request handling, but we don't allow those actions to forkIO anyway. There hasn't been any demand for it.

comment 12y ago · link · parent

It looks like you're right. I misspoke.

We track total threads, working or not. It works great as an indicator because it tends to stay below the number of CPU cores on the server.

comment 12y ago · link · parent

I'm the author of the article.

This is very true in every language, and doubly so in Haskell. If you just take the language as it is without any context, the language leaves whole classes of problems with a ridiculous overabundance of potentially viable solutions.

The one that springs to mind most prominently is error handling. What's the right way to do this? Option types? Exceptions? EitherT? We even explored a library that used type classes to provide Java-style checked exceptions.

We sorted this out early, when the "team" was just 2 people working in extra hours, but if we'd still been in that state when we scaled up, the project would have been a disaster.

FYI, the solution we came up with was to use option types for all recoverable errors. We only use exceptions for nonrecoverable failures that should trigger production alerts.

comment 12y ago · link · parent

We deal with Haskell resource leaks the same way you would in C++ or Java.

We have production monitors on every host that show basic metrics like memory, disk, and CPU utilization. Atop that, we added a tracker for the number of suspended Haskell threads. (that is, threads which are not blocked on I/O, but are also not running)

We found that the machines are usually able to handle requests as soon as they come in, so if the number of Haskell threads goes above 0 for any length of time, the machine is about an hour away from melting down.

We can restart the process without losing any connections, so this leaves us a very comfortable margin of error.

Once we know we have a problem, it's usually pretty simple to run the heap profiler on the process and look at recent commits. We continuously deploy, so there's only about a 10 minute delay before a particular commit is running in front of customers. This makes tracking regressions down really fast.

Even in cases where we can't figure out why a bit of code is leaking, we can almost always identify it and revert it until we understand what's going on.

comment 12y ago · link · parent

Author here.

We've trained a few people up on Haskell at IMVU now, and I'm starting to think that learning Haskell is at its very hardest when you're building tiny toy applications and all you have for answers are google searches and books.

It seems to help a lot to root the learning process in a specific concrete goal, in an existing codebase that already has idioms and patterns in-place, and to offer direct access to people who have answers to newbie questions.

comment 12y ago · link · parent

Hi, I'm the author of the article.

I think you're right, and I think Haskell delivers on your definition of "better." I chose to try Haskell because I've been through a lot of agonizing maintenance work and I'd much rather do it in an environment that has mandatory, pervasive static analysis and tests that are by default isolated from all possible nondeterminism.

We don't have any 8-year-old Haskell yet, so I can't fairly compare it to refactoring our PHP codebase, but I have made a few sweeping changes to our 60k lines of Haskell over the past year and a half. It tends to be mostly effortless, no matter how much code needs adjusting.

comment 12y ago · link · parent

In practice, I've found space leaks in Haskell code to be a bit analogous to extraneous copies in C++ code or NullPointerExceptions in Java: They're usually not a huge problem, but sometimes you get it wrong even if you're experienced and know what you're doing.

We've only had one really disasterous space leak and it was caught and reverted right away. The hardest ones are generally the slow ones where the servers take 3-7 days to run out of RAM and fall over. If you never go more than a few hours without a code push, you might not even notice it.

88.

Haskell at IMVU(engineering.imvu.com ↗)

13 points · by implicit · 12y ago · discuss

comment 12y ago · link · parent

I convinced the company I work at to use Haskell for REST services.

The technical leadership team was already interested improving the reliability and rigor of our web backend, but weren't thinking about exploring other programming languages. (we primarily use PHP)

I knew Haskell would be hard to sell, but I also had concerns about it myself, so I ran a live-fire test:

In my spare time, I wrote an interface-compatible Haskell implementation of a particular service that drove a lot of load, but was noncritical. I load-tested this service by flipping an nginx switch to divert traffic to the Haskell implementation. Leadership was ok with this because we could just flip the switch back if there were any issues: The risk of customer impact was miniscule. After some initial tests, we left it to run for a few months without manual intervention.

Over the course of this side-project, I got a few curious coworkers to learn Haskell to help out.

When the right project came along, leadership still had concerns, but I had lot of hard evidence to show that Haskell superbly fit our technical requirements and that the nontechnical problems (like hiring and training) were probably surmountable.

comment 12y ago · link · parent

That's not all. This code:

    foo = do
        result <- do_first_thing
        do_second_thing result
Kinda sorta roughly desugars into something like this:

    function foo(cb) { do_first_thing(function(result) { do_second_thing(result, cb); }); }
Synchronous and asynchronous Haskell APIs can have the exact same interface.
1234