Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You could type things like headers in Go too if you want to, by introducing a new type for each header in a similar way, get them to check values are valid on being assigned etc. (std lib does it in a simpler less robust way but it's quite possible). Go could then do compile time checking for those types, e.g. something like:

http://play.golang.org/p/GeUgsjitVS

    func respondWithHeader(h HttpContentEncoding) string {...}


Hah, true enough. But the other half of what makes Spray work is the high-level abstraction possible, which makes it easy to handle these different things generically. Consider e.g. https://github.com/4lex1v/Sprayed/blob/master/src/main/scala... , which is an example of abstracting a possible "context" for a value, with implementations for futures or possible errors (both things that go has direct support for, but it's much less clumsy to work with these things when they're just ordinary objects that follow the ordinary rules of the language). You can abstract over those contexts, writing one method that can handle a list of async calls or a list of possibly-failing calls. You can extend it with your own data types, e.g. you can do session-in-view in a principled way, using ordinary language features rather than magic annotations, by having a context that represents "database operation".


I would imagine having union types and such would make something like this a bit more powerful. Not entirely sure, but having a hierarchy of http contentencoding types, and http error/success types could make it easier to write code that handles all error conditions. Also having a type for sanitized strings versus unsanitized strings. That being said, I've never used a language with a sophisticated type system to do web programming.


Not entirely sure, but having a hierarchy of http contentencoding types, and http error/success types

Yes the Scala server shown was an interesting example, though I'm not sure if it would be impossible to do in other languages or just harder.

Also having a type for sanitized strings versus unsanitized strings.

The golang stdlib does do this, it's quite handy as a reminder.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: