5 ms·
I don't want to be that guy, but why don't you try Go? It's the perfect server side language IMHO.
by simi_ 12y ago
I don't want to be that guy, but why don't you try Go? It's the perfect server side language IMHO.
- deleted 12y ago[deleted]
- lmm 12y agoWith a type system that's weaker than Java's? Look at e.g. the way spray handles HTTP headers; it eliminates a bunch of errors that are in some sense trivial, but almost all bugs are trivial when looked at in the right way. You just couldn't do something like that in Go.
- grey-area 12y agoLook at e.g. the way spray handles HTTP headers... For those of us not familiar with Scala it'd be interesting to see you expand on that statement. Are you talking about the type definitions in this file? https://github.com/spray/spray/blob/release/1.1/spray-http/src/main/scala/spray/http/HttpHeader.scala https://github.com/spray/spray/blob/release/1.1/spray-http/s...
- lmm 12y agoYeah. It means you can e.g. respondWithHeader(`Content-Encoding`(UTF8)) { ... } and the header and its parameters are typed, and so if you make a typo in the name or the value (or try to pass the value of one header to another) then you'll get a compile-time error.
- grey-area 12y agoYou 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 http://play.golang.org/p/GeUgsjitVS func respondWithHeader(h HttpContentEncoding) string {...}
- hderms 12y agoI 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.
- grey-area 12y agoNot 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.
- lmm 12y agoHah, 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/spray/ext/directives/AsDirective.scala 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".
- rkrzr 12y agoWell, if you want to do functional programming, as the OP indicated, then Go is not the way to go. Scala seems like a fine choice then, or e.g. Haskell if you want to go all the way.