News for hackers. Stuff that matters.
Re:Go After 2 Years in Production by neya on Tuesday August 27, 2013 @01:19PM (#6284775)
Another Scala user here. And I've been using Scala for the last six months. Mostly developing web applications on Scalatra and Play. I love Scala - It still has its goodiness and it's an excellent alternative to Java.

If you notice in all of the Scala books (I've read the one by Martin and the One by David Pollak as well), they all seem to push you towards the functional programming model instead of the much more common imperative model.

But you know, there's a problem with that. Not with the language itself, but with the web development side of Scala. There's only certain ways by which you can program with a particular function that accepts a request and returns a response. So, most of the time, I would find myself wasting time thinking "How can I make this more functional?"

Functional programming is really great when you can actually enforce it - When writing algorithms and so forth, but otherwise, you are forced to fallback to this imperative model which sucks, because you have to constantly keep changing your mindset between these two models.

Another downside of Scala is its HUGE syntax. Processing strings? Here's a ten million ways to do it.. (a bit over-exaggerating). Oh and if you chose this way, then you should use this syntax. No, not that one, THIS one. Oh no, not that one, this variation of that one that looks like this.

I've advocated Scala to many HN members here in the past, you can even check out my comments, for instance. But from my experience, I think Scala is an Academic language. But it's superior in its own ways - I just LOVE the concept of avoiding nulls and passing an Option. It's beautiful. But the downside is its huge academic complex syntax. I want to be able to write code which shouldn't reduce my hair count even if I look at it after 6 long months. I don't want to refer to an 800 page book each time I'm confused about something.

That's why I think Go is beautiful. The syntax is just enough to keep it inside your head forever. I fear that as the language matures, this might also evolve into something as complex as Scala, but let's hope not so.

Go isn't a magic bullet though. It has its own downsides, but nothing w.r.t performance or similar. For the most part, it's awesome.

Once you go Go, you never go back.

P.s - I still love Scala as well ;)

Re:Go After 2 Years in Production by rybosome on Tuesday August 27, 2013 @03:43PM (#6285751)
I've historically been pretty pro-Scala 'round these parts, so my response to this should be considered in that light. So, with that disclosure out of the way... =)

I have to admit, I don't agree with the assertion that the cognitive dissonance associated with programming in an imperative way versus a functional way is a major problem to Scala. I realize personal preference is a very big part of this, but there are many problems which are just easier to solve in a functional way versus an imperative way. Of course, the opposite holds true as well. This is the beauty of Scala; one can write performance-critical imperative code while exposing a functional interface; or, one can consume a fluent functional interface to produce imperative code.

Frankly, I guess I've become something of a functional zealot, so my problem with Go is that it's so stubbornly imperative. This is why I can't get behind Go, as much as I want to. I feel like it doesn't consider many of the lessons that have been learned about FP making life easier. Set operations (map, filter, reduce) are insanely common, yet doing them imperatively sucks to the point of discouraging them. Excessive mutability is difficult to reason about. Nobody expects the nil/null/none inquisition. We tend to forget about side effects. Without an extensible language, which requires truly first-class functions, you're at the language designer's mercy.

Hell, Scala probably isn't the be-all, end-all answer to all of this. I just don't think that a doggedly-imperative, non-composable, statement-oriented language is the future of programming "in the large", not when the past has shown us that we tend to produce buggy, unmaintainable software this way. I'm pragmatic enough to realize that pure FP isn't a solution, but I feel strongly that sticking to traditional imperative because it's familiar is a costly mistake.

I can't argue with your take on the syntax, though, since that's personal preference. =) If you have any thoughts on why you feel productive in Go, I'd love to hear them; as I've said, I've been really struggling with motivating myself to learn and enjoy it.

Re:Go After 2 Years in Production by caciquefun on Tuesday August 27, 2013 @07:20PM (#6286947)
Maybe you would try nimrod language, it's similar to go but a bit more functional, and it has generics and the concurrence is managed using actors (also supports channel's) , and rust also is a good language for functional programmers trying to find a good system language...

Go language is so different to scala or Haskell because it follow the principle what a simple language is better than a complex one (the less powerful principle). The type system is a bit weak in go, probably one simplest type system ever, nimrod has a basic oop joining with algebraic data types and something similar to clojure multi methods, rust I believe has type classes..... So yes, I if you're happy writing functional code and using powerful languages maybe you will not totally happy with go language...

Re:Go After 2 Years in Production by rybosome on Tuesday August 27, 2013 @07:25PM (#6286985)
I'll have to look at Nimrod. You're correct about Rust; I've only read bits and pieces, but everything I've seen so far has left me with a positive impression.
Re:Go After 2 Years in Production by neya on Wednesday August 28, 2013 @01:50AM (#6288225)
I agree with everything you say. I think functional vs imperative is a matter of taste, though. Even I tend to incline towards Functional Programming (FP) in most scenarios, but in some cases imperative languages are 'good enough'.

And since my background used to be client-side Javascript mainly (I was a front-end designer), I find it fairly confusing to switch myself between the two mindsets (FP and IP), which like you said is something more of a personal preference.

And like I said, I still love Scala, for the reasons you've cited. But then again, there are a couple of reasons which I have in mind for going with Go.

The main problem with Scala for me:

1) Difficult to find good Scala engineers. IF you find one, you still need to figure out if he's comfortable with the Functional or Imperative model.

2) Syntax:

This is an example from one of my previous commenters (dxbydt, thank you) on my thread:

    scala> def test1 = println ("hello world")
    scala> def test2(f: =>Unit) = println ("hello world")
    scala> def test3(f:Unit) = println ("hello world")
    scala> test1
    hello world
    scala> test2()
    hello world
    scala> test3()
    hello world
    scala> val t = test2 _
    scala> t apply Unit
    hello world
    scala> t()
    hello world
    scala> t(())
    hello world
It is mostly a personal preference, but I still feel too many ways to do one thing is a recipe for disaster.

With all that said, I know of people writing a Scala program and not touching it for a year or two unless they wanted to update their OS on their servers.

Re:Go After 2 Years in Production by rybosome on Wednesday August 28, 2013 @04:31AM (#6288665)
Nice example. It combines aliases for the Unit type with the sort of hybrid function/value nature of Unit to produce a truly baffling array of options. =)

I'll agree that this set of cases does not reflect well on Scala; at the very least, it supports your point that the syntax is too large. Still, I don't mind it too much. Although the "multiple ways to skin a cat" nature of Scala means you can get very WTF-y code like above, it also means that you can construct a list by writing `1 :: 2 :: 3 :: Nil`, or send an actor a message with the Erlang-inspired `actor ! Message("hello")`.

I don't want to be an apologist for it, though. You're correct that there are some nasty corner cases. Using Scala for serious work is difficult if people don't agree on a consistent style.

Re:Go After 2 Years in Production by realrocker on Tuesday August 27, 2013 @04:09PM (#6285941)
Have ever tried programming in Go?

Edit: Functional Programming in Go 1. http://stackoverflow.com/questions/4358031/functional-progra... 2. http://golang.org/doc/codewalk/functions/

Re:Go After 2 Years in Production by rybosome on Tuesday August 27, 2013 @04:47PM (#6286172)
I'm currently in a study group at work for Go, and I'm writing a few one-off personal tools with it. This is hardly serious experience, but it's enough to get a flavor for the language.

As the other answer to your question states, adopting a functional style in Go is technically possible, but practically it is so inconvenient as to be unusable.

EDIT: Take a look at this article, which explores developing a library that adds runtime-checked type parametric functions. http://blog.burntsushi.net/type-parametric-functions-golang

Choice quote:

"There’s no such thing as a free lunch. The price one must pay to write type parametric functions in Go is rather large:

Type parametric functions are SLOW. Absolutely zero compile time type safety. Writing type parametric functions is annoying. Unidiomatic Go."

Re:Go After 2 Years in Production by gnuvince on Tuesday August 27, 2013 @04:24PM (#6286035)
Go doesn't lend itself to functional programming, in part because of its lack of type parametrization. In a language like Scala or Haskell, using functions like map, fold, and filter is clean an idiomatic. In Go, it is so ugly and convoluted that you immediately reject this approach and use for loops instead.
Re:Go After 2 Years in Production by mseepgood on Tuesday August 27, 2013 @06:22PM (#6286667)
Standing firmly in one paradigm is a good thing for a language IMHO. I've worked in multi-paradigm languages and they suffer from the fact that their communities can't find a common style. "Should I use a fold or a loop or a tail recursion?", or some library designers want to be as typeful as possible, others don't, etc.
Re:Go After 2 Years in Production by eru on Wednesday August 28, 2013 @02:18AM (#6288296)
> "Should I use a fold or a loop or a tail recursion?"

Neither, use a combinator, like map or traverse. (And that applies to all languages that support this style.)

Re:Go After 2 Years in Production by m0th87 on Tuesday August 27, 2013 @01:25PM (#6284813)
> I think Scala is an Academic language

Sometimes "academic" seems like a catch-all for stuff people don't like. Scheme has a strong academic history in its use and implementation, yet it seems to be described as "academic" only when someone is unhappy with how minimalistic it is, which is the opposite issue described here.

Re:Go After 2 Years in Production by winter_blue on Tuesday August 27, 2013 @02:19PM (#6285168)
Has anyone here used Haskell in a production environment?

I want a language that is small, clean, and can provide a lot of static guarantees. I know many people find static guarantees and unacceptable curtailment of their "programming freedom", but frankly I think it's the answer to many of the problems we face in software today. Small is another thing. E.g. Go and Scheme are small. C++ and Scala are large. You know what I mean..

Now, static typing is just one kind of static assertion[1] I'd like to have. Side effect isolation (i.e. language-enforced purity) would be another feature I'd like to see become common. For example, the D programming language has a "pure" keyword that lets you mark a function as side-effect free. (In Haskell, all function are pure by default, and you escape the confines of purity via monads.)

I'd like to do research into (inventing) other forms of static assertions. One thing that's been on my mind lately, has been static "complexity assertion" for programs. I don't know if this even possible, but it would be nice to be able to ascertain before running a program, certain time & space complexity bounds on it. This would perhaps require us to drop the programming language itself to some level "slightly below" Turing machines -- but this in itself could be achieved via a keyword like D's "pure" or something more elegant. (Note: my point is not that we're going to make the entire language non-Turing complete -- but rather that we'll have subsets of the language that are not, and this reduction of power would/could bring with it a greater possibility for statically asserting stuff.)

[1] FYI I made this term up. Let me know if there's something better that describes this.

Re:Go After 2 Years in Production by chas on Tuesday August 27, 2013 @04:47PM (#6286174)
Total functional programming (and the associated analysis of codata has already been touched on), so I'll just address your interest in static guarantees for space usage. The Virgil programming language[1] has been designed with exactly this in mind. It is aimed at embedded systems where memory is extremely constrained and running out of memory could kill people. Heap allocation is not possible in the language and all data structures are initialized during compilation (like C++ templates, but more sophisticated). The compiler can use the initialization information for advanced optimization and analysis as well as serving as a bound on the memory usage. [2] The language also has some interesting static typing ideas, but they are not as distinct from other languages.

Further discussion on LtU: http://lambda-the-ultimate.org/node/2131

[1] https://code.google.com/p/virgil/ [2] http://compilers.cs.ucla.edu/virgil/overview.html

Re:Go After 2 Years in Production by e12e on Tuesday August 27, 2013 @09:35PM (#6287484)
I wonder if a restricted subset of a stack based language like Forth might also work?
Re:Go After 2 Years in Production by scott_s on Tuesday August 27, 2013 @02:29PM (#6285236)
User thirsteh talked about his experiences with Haskell in production yesterday: https://news.ycombinator.com/item?id=6278588
Re:Go After 2 Years in Production by obeattie on Tuesday August 27, 2013 @02:32PM (#6285255)
> it would be nice to be able to ascertain before running a program, certain time & space complexity bounds on it

I don't know about knowing what "space" a program will consume ahead of time, but I believe the halting problem[1] means there'd be no way of computing a time requirement.

[1] http://en.wikipedia.org/wiki/Halting_problem

Re:Go After 2 Years in Production by scott_s on Tuesday August 27, 2013 @03:07PM (#6285459)
The halting problem assumes a program from a Turing-complete model of computation. Not all computational models are Turing-complete. The parent is pointing out that if you limit yourself to a language or a sub-set of a language that is not Turing-complete, then you can make static assertions about things such as halting.

A trivial example would be a programming language that did not allow any loops or explicit backward branches. You would be able to provide upper bounds on how many operations such programs can perform.

Re:Go After 2 Years in Production by winter_blue on Tuesday August 27, 2013 @03:21PM (#6285572)
I was just going to make the same reply.

> if you limit yourself to a language or a sub-set of a language that is not Turing-complete, then you can make static assertions about things such as halting

There's already something that is non-Turing complete, but comes with a halting guarantee -- it's called total functional programming[1]. This paper (linked below) is actually what got me thinking about this whole thing. The author argues in it how functions in functional programming languages aren't really like mathematical functions, because they have the possibility to execute infinitely (never halt) and thus not have a proper return value. To mitigate that, he creates "total functional programming".

Total functions are guaranteed to have a return value (i.e. terminate eventually), but they could take very long to run. If we could actually have complexity bounds, or be able to determine a given function's complexity, that would be a great boon to software engineering (i.e. assuming they adopt it... which is a whole different matter).

The author also makes a very good point that most parts of your program are meant to terminate (i.e. the vast set of functions and algorithms that comprise you program). Only the top-level needs to be Turing-complete, the rest can at least be total.

I actually want to see if it's possible to push this concept further, to create a ring-like hierarchy of languages -- the lowest one being the weakest and the one we can extract the most static assertions out of, and so on. There's a language called Hume[2] that sounds like it accomplishes at least part of this goal, but I haven't really looked into it.

[1] http://www.jucs.org/jucs_10_7/total_functional_programming/j...

[2] https://en.wikipedia.org/wiki/Hume_%28programming_language%2...

Re:Go After 2 Years in Production by kenko on Tuesday August 27, 2013 @03:14PM (#6285505)
"(In Haskell, all function are pure by default, and you escape the confines of purity via monads.)"

This is not true. Nothing about monads, in themselves, allows you to write impure functions.

Re:Go After 2 Years in Production by lmartel on Tuesday August 27, 2013 @03:51PM (#6285819)
It's pretty common on HN for people to say "monads" when they mean IO. For some reason.
Re:Go After 2 Years in Production by sridharvembu on Tuesday August 27, 2013 @02:48PM (#6285348)
Your point on "slightly below" Turning machines caught my attention - exactly the same terminology I have used. I want as many proofs (assertions) as possible about code, and Rice's Theorem is a problem, so slightly below Turing is on the radar. If you are interested, we can discuss this. Shoot me an email at svembu at zoho ...
Re:Go After 2 Years in Production by doublec on Wednesday August 28, 2013 @12:38AM (#6288062)
Inch [1] has an example using complexity annotations, showing that a red-black tree insert/delete are linear in the black height.

ATS [2] is my go-to language for static guarantees with C's efficiency. Not sure if it counts as small but the implementation is not big.

[1] https://github.com/adamgundry/inch [2] http://www.ats-lang.org

Re:Go After 2 Years in Production by creatio on Tuesday August 27, 2013 @05:54PM (#6286546)
For the "complexity assertion" I think you may be referring to something like this: http://resourceanalysis.cs.ru.nl/

Maybe its not totally exactly what you meant, but it can do basic analysis for loops.

Re:Go After 2 Years in Production by neya on Tuesday August 27, 2013 @01:53PM (#6285007)
Sorry, maybe like the other commenter mentioned below, the word I probably was looking for was 'industrial'. Or whatever refers to it as 'massive and complex'.

Not necessarily a bad thing, for web development, most of it's depth is an over-kill.

Re:Go After 2 Years in Production by fsniper on Tuesday August 27, 2013 @02:10PM (#6285114)
"enterprise-y"? But I don't believe it is.
Re:Go After 2 Years in Production by djhworld on Tuesday August 27, 2013 @03:49PM (#6285795)
I liked Scala, but it's just the sheer weight of it that puts me off using it in my personal projects, and it still comes with JVM baggage.

What it needs is some leadership. A few weeks ago Rob Pike and Andrew Gerrand (developers of Go) appeared on The Changelog podcast, which I recommend listening to, and one thing that Rob Pike said really intrigued me. He said that a policy they have when designing Go is to ensure that all members of the core team agree on any design decision before it gets put into the language. If one of them disagrees it gets tossed.

That's probably one of the main reasons why Go is such an "opinionated" language and very small in nature. This probably infuriates some people as their favourite feature from other languages is missing in Go, but it keeps the language where it is and steers it on a path that the designers are maintaining complete control of.

Re:Go After 2 Years in Production by dragonwriter on Tuesday August 27, 2013 @01:31PM (#6284855)
> But from my experience, I think Scala is an Academic language.

Your complaints about Scala's size are more on point and oppose this; Scala is such a big language because it is designed to be an industrial language (academic languages tend to be small and focussed) specifically targetting the enterprise uses of Java.

Academic functional languages that aren't designed to provide an easy glidepath for users of a particular large imperative OO language and provide access to that industrial ecosystem tend to be smaller than Scala.

Re:Go After 2 Years in Production by neya on Tuesday August 27, 2013 @01:54PM (#6285014)
Thanks for the correction. I probably meant industrial when I said academic.
Re:Go After 2 Years in Production by noelwelsh on Tuesday August 27, 2013 @02:21PM (#6285179)
I find your comment quite odd, as a web service is just about the most functional thing you can get -- it's just a function request => response as you note. I don't see where you'd need to make it "more functional."
Re:Go After 2 Years in Production by eranation on Tuesday August 27, 2013 @01:27PM (#6284827)
For an academic language (which I assume is factually true as it was developed in a university) it is one of the most developer friendly academic languages out there IMHO, I rather write Scala than Java in terms of complexity, and if I would need to rewrite a Ruby code base, I would give it a shot in Scala before trying Go (feels more natural to me, they have way more similarities than I thought) I have the parts I need from Scala easily fitting in my head, which is perhaps just a subset, but enough for me to be very expressive in it.

I think one of Scala's biggest issues is people being turned off by what sometimes feels as functional zealotry[0]. But people perhaps are not aware that it is also a great imperative language, you get no compiler warnings if you use a var or a mutable collection. I find it very close to Ruby actually and I think Ruby developers will feel at home with it [1]

The other thing that holds it back IMHO is the compile time. (But this is improving from version to version)

[0] https://twitter.com/wycats/status/372107196617592832 [1] https://twitter.com/yukihiro_matz/status/372181477909200896

Re:Go After 2 Years in Production by winter_blue on Tuesday August 27, 2013 @02:11PM (#6285120)
> The other thing that holds it back IMHO is the compile time.

Now that you mention compile time -- one of the biggest things that the Go designers cared about was compile-time. Go touts it as one of its major pros; and I do agree for personal experience that compile time matters.

You can often cut down compile-time by making "run-time compromises". For instance, with C++ code, dyn-linking rather statically linking everything can speed up things significantly. This is because with massive C++ codebases, when you change a couple of lines, rebuilding the relevant objects only takes a few seconds - but the static linking stage can take forever.

On memory constrained system (4GB) of RAM, I've seen a particular codebase that I've worked with take up to 28 minutes just to link. The same code on a machine with 8 gigs of RAM (just double) took less than 4 minutes to link. Due to the sheer number of objects that need to be linked, your system ends up thrashing (swapping pages out to disk).

That being said, I read somewhere that Go doesn't support incremental compilation. I don't if this is still true, but that's a major problem that needs to be fixed right away.

With interpreted languages, practically everything is done at run-time and you have no compilation stage -- but at a massive performance penalty. Tracing JITs do help though.

Re:Go After 2 Years in Production by pkinsky on Tuesday August 27, 2013 @02:25PM (#6285216)
>Another downside of Scala is its HUGE syntax. Processing strings? Here's a ten million ways to do it.. (a bit over-exaggerating). Oh and if you chose this way, then you should use this syntax. No, not that one, THIS one. Oh no, not that one, this variation of that one that looks like this.

On the other hand, Scala lets you deal with collections and Strings using the same enormous set of methods.

    "\"foo\"".drop(1).dropRight(1)
is just

    List('"', 'f', 'o', 'o', '"').drop(1).dropRight(1)
Re:Go After 2 Years in Production by islon on Friday August 30, 2013 @10:33AM (#6301946)
I had more or less the same experience with Scala but I just jumped all the all way to functional programming and started using Clojure, never looked back =)
Re:Go After 2 Years in Production by ulisesrmzroche on Tuesday August 27, 2013 @01:34PM (#6284886)
For real? That's cray. I didn't know the syntax was so hard to internalize.
Re:Go After 2 Years in Production by teddyh on Tuesday August 27, 2013 @01:52PM (#6285001)
For a while I thought you meant Seymour Cray, or one of the supercomputers he designed and built.

Was it so hard to type one letter in support of readability? Or is "cray" its own word now?

Re:Go After 2 Years in Production by munificent on Tuesday August 27, 2013 @03:29PM (#6285645)
"Cray cray" and by extension just "cray" are vernacular ways of saying "crazy".
Re:Go After 2 Years in Production by teddyh on Tuesday August 27, 2013 @05:40PM (#6286483)
I was aware of this, but was genuinely confused for a few moments, since I would have hoped that a reference to Seymour Cray was more likely on this forum than such, as you put it, “vernacular” forms of expression.
[deleted]
Re:Go After 2 Years in Production by rthomas6 on Tuesday August 27, 2013 @02:53PM (#6285380)
For a while I thought you meant Vladamir Bro, father of the idea of pedantry.

Was it so hard to type four letters in support of readability? Or is "bro" its own word now?

Re:Go After 2 Years in Production by ulisesrmzroche on Tuesday August 27, 2013 @02:58PM (#6285404)
So are ya'll here to talk about Scala and Go or to pull some scrub trolls?
Re:Go After 2 Years in Production by asdasf on Tuesday August 27, 2013 @03:21PM (#6285568)
>When writing algorithms and so forth, but otherwise, you are forced to fallback to this imperative model which sucks

You don't need to fallback to imperative style. The fact that people write web apps in pure functional languages should make that obvious.

>Once you go Go, you never go back.

That depends where you came from. I really tried to like go, but went running back to haskell. Go is just way too primitive.

Re:Go After 2 Years in Production by cgag on Tuesday August 27, 2013 @04:16PM (#6285983)
Yeah, I'd like to hear more about what kind of things make you fall back to imperative style.
Re:Go After 2 Years in Production by marincounty on Tuesday August 27, 2013 @02:09PM (#6285109)
I think there should be a 500 page law. If you go over by one page, even if it's blank--the book is free?