420 karma · joined Feb 20, 2009 (17y ago) · 99 submissions
comment 11y ago · link · parent
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
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
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
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
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
Bigger and longer-lived projects benefit enormously from an automated test suite no matter what they're written in.
comment 12y ago · link · parent
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
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'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
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
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
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
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
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
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 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
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
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
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
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
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.