News for hackers. Stuff that matters.
Re:On comparing languages, C++ and Go by npalli on Saturday October 05, 2013 @05:01PM (#6502068)
That's interesting. I had the opposite reaction regarding Golang capabilities while following this saga. Not sure how 'idiomatic' the Golang code is, at first glance it just seems less expressive (more lines of code) than either c++ or java!. I didn't think that was possible.

So whenever people talk about expressiveness of Golang it just seems like a design gone bad. The designers wanted a programming language with the expressiveness of python and the speed of C, they ended up with a language with the expressiveness of C and the speed of python.

Re:On comparing languages, C++ and Go by pbsd on Saturday October 05, 2013 @05:10PM (#6502093)
I agree, I honestly don't see where the expressiveness claims of Go come from. I've always put it in the Java-like bin of languages (which is not necessarily a bad thing).

I suppose the one thing that Go does well (compared to C++ or Java) is builtin concurrency and communication across tasks.

Re:On comparing languages, C++ and Go by tptacek on Saturday October 05, 2013 @06:42PM (#6502352)
My first impression of it was that it was like a cross between Java and Python. It is unmistakably similar to Java conceptually and syntactically; they are sibling languages, both designed to streamline, simplify, or modernize C.

I'm a Java-literate C/C++ programmer. I would avoid writing straight Java code at all costs; I find it immiserating. Here are some reasons off the top of my head that Golang is more pleasant to work in:

* The syntax is deliberately streamlined, including implicit declarations, semicolon insertion, lightweight expression syntax, the capital-letter-exports-a-symbol thing

* It has fully functional idiomatic closures

* Interfaces get rid of adapter class BS

* The table type (maps, in Golang) is baked into the language, like Python, not a library, like C++ and Java

* Clearer, more direct control over memory layout; data structures in Golang feel like C

I don't know if Golang's standard library is that much better than Java's, but it was obviously designed carefully by and for systems programmers, so I find it remarkably easy to work with.

It also feels like a much smaller system than Java. Almost every time I write a significant amount of Golang code, I find myself answering questions by just reading the standard library source code. It's easy to get your head around. I've written compiler/runtime-level code for the JVM and I still don't have a great grip on all of Java.

Re:On comparing languages, C++ and Go by georgemcbay on Sunday October 06, 2013 @03:46AM (#6503467)
I agree with all of the above and I write Java code for a living currently (Android/Dalvik though, not for the JVM).

Another cool aspect of the last point (Go being small and lightweight) is that if you've got gcc and mercurial on a supported platform, building latest go from source is as easy as:

hg clone http://code.google.com/p.go cd go/src ./make.bash

Got to build a local copy of the JVM and/or JDK for some reason? Good luck with that (even ignoring all the licensing, OpenJDK vs closed, etc)

Re:On comparing languages, C++ and Go by lmm on Sunday October 06, 2013 @05:33AM (#6503603)
Have you compared it with ML or Haskell?
Re:On comparing languages, C++ and Go by RamiK on Saturday October 05, 2013 @05:26PM (#6502132)
Brevity and expressiveness are not the same.
Re:On comparing languages, C++ and Go by yohanatan on Saturday October 05, 2013 @06:43PM (#6502356)
Are you sure about that? Given that any [Turing-complete] language feature can be implemented in any other [Turing-complete] language, the only conceivable difference is in fact length of implementation.

In other words, it is possible to express anything in one Turing-complete language that is possible to express in another.

Re:On comparing languages, C++ and Go by hetman on Saturday October 05, 2013 @07:54PM (#6502530)
Except my brain isn't a Turing machine. What expressiveness means then is how easily I can fit the concepts of the code in my head (not on my harddrive). This is not the same as how short the code is, though the two are often closely related.
Re:On comparing languages, C++ and Go by yohanatan on Saturday October 05, 2013 @10:17PM (#6502812)
Expressiveness is power and it applies to the act of writing code, not reading it. I agree that it is ideal if one's code can be read and comprehended easily by others although that has little to do with expressiveness.

http://www.paulgraham.com/power.html

Re:On comparing languages, C++ and Go by cgag on Saturday October 05, 2013 @07:49PM (#6502513)
To me, expressiveness is about expressing an idea with as little incidental complexity as possible, which is definitely different from as in as few characters as possible.
Re:On comparing languages, C++ and Go by yohanatan on Saturday October 05, 2013 @10:12PM (#6502805)
I don't think it is different actually. 'Kolmogorov complexity' (which is essentially the global minimum 'essential complexity' of a particular algorithm) is specified in terms of length.
Re:On comparing languages, C++ and Go by fauigerzigerk on Sunday October 06, 2013 @03:46AM (#6503465)
Applying Kolmogorov complexity in this context is a bit more tricky than you make it appear. Kolmogorov complexity measures the complexity of a string as the length of the shortest possible program that generates that string.

So to measure the complexity of a program P we have to write another program G that generates P and then take G's length. It's not a given that a generator for a verbose language is necessarily longer than a generator for a terse language.

But more importantly, what we want to measure is the mental effort required to write and understand code in different languages. To measure that effort in terms of Kolmogorov complexity, we'd have to write a program that generates our states of mind while programming.

Good luck with that ;-)

Re:On comparing languages, C++ and Go by yohanatan on Sunday October 06, 2013 @07:43PM (#6505920)
Actually, given a Turing Machine M which outputs x when given x, then we would have the description of program T0 (for terse language T) equal to the concatenation of the [specification of the] machine M with T0, M T0. Given program J1 (for verbose language J), its description equals M J1. Given sufficiently small M and large T0, the M factor's importance is quite reduced and we see that Kolmogorov complexity is roughly analogous to the respective sizes of T0 and J1 themselves (for this specific Turing Machine M).
Re:On comparing languages, C++ and Go by fauigerzigerk on Monday October 07, 2013 @01:33AM (#6506643)
You're forgetting that Kolmogorov complexity is the shortest possible description, not just any description of the desired output. The concatenation you're suggesting is highly unlikely to be the shortest possible one.

You have to think of it in terms of compression, because that's what Kolmogorov complexity is really about. It is certainly possible that after compression J1 is shorter than T0.

Re:On comparing languages, C++ and Go by yohanatan on Monday October 07, 2013 @12:41PM (#6509422)
You're forgetting that I get to pick the Turing machine to use. Kolmogorov complexity is the shortest possible description relative to a particular Turing machine. Re-read my previous post with that in mind.
Re:On comparing languages, C++ and Go by fauigerzigerk on Monday October 07, 2013 @01:49PM (#6509910)
No you don't get to pick the particular Turing machine if by "particular Turing machine" you mean a Turing machine including a particular transition function, which is the conventional definition of Turing machine (http://en.wikipedia.org/wiki/Turing_machine#Formal_definitio...)

In terms of this definition we need two Turing machines, one whose transition function can be proven to be the shortest that describes L1. And another one whose transition function can be proven to be the shortest that describes T0. These two Turing machines or transition functions are compressed representations of L1 and T0 respectively.

What I'm saying is that the one describing L1 can be shorter than the one describing T0 even if L1 is longer than T0.

Re:On comparing languages, C++ and Go by yohanatan on Monday October 07, 2013 @02:24PM (#6510172)
I think we are approaching this from different angles. I am thinking of a single contrived M for whom a simple copy input to output is the primary supported operation and all other operations/modes, although still capable of performing arbitrary computation [hence able to execute 'compressed' programs if you should wish to attempt to provide them and also, by definition, still Turing complete], are exceedingly clumsy/verbose.

I have not only the transition function but 6 other entities to define to accomplish this (really 5 barring the 'blank symbol') so I am certain that it is not only possible but likely much smaller than one might think at first. With such a small M (that penalizes attempts to compress T0 and J1), and a large T0 [such as the code base for Microsoft Windows ported to F#] and an even larger J1 [such as the same code base written in C], we still see my desired result.

Re:On comparing languages, C++ and Go by fauigerzigerk on Monday October 07, 2013 @03:34PM (#6510629)
I understand what you're saying but I fail to see how your M is related to Kolmogorov complexity. You're not free to define some contrived M with particular properties that make your assumption true. Kolmogorov complexity explicitly asks for the shortest possible M for each individual string (i.e L1 and T0). Here's the definition from Wikipedia (http://en.wikipedia.org/wiki/Kolmogorov_complexity):

"More formally, the complexity of a string is the length of the shortest possible description of the string in some fixed universal description language".

M is not that universal language. M is a program written in the universal language of Turing machines. I guess that is our misunderstanding. If you define M itself as that universal language but M only ever does that one contrived thing you said (i.e. there is only one program written in that language) then it is not a universal language any longer and any comparison of lengths would become completely pointless.

Re:On comparing languages, C++ and Go by yohanatan on Monday October 07, 2013 @04:09PM (#6510858)
In my case, the 'universal description language' is one that supports a single operation, let's say CC for 'carbon-copy', and some other number of operations (contrived to have a quite clumsy/verbose interface). The CC operation takes one input--the 'text' to output (which in my case would be T0 and J1). The 'other operations' would be only the minimal set required to still be Turing-complete (and once again would be devised such that no sane person would want to use them for any sufficiently complicated task). So, M is the implementation of the above UDL.

Then, the question becomes, how much logic do we have to put into M itself to achieve the above? I posit that it would not be very much in fact (but that should be demonstrable if someone were sufficiently motivated).

I think KC requires that M be constant across the texts you wish to compare (so that texts across various languages are normalized to an underlying architecture).

If one views M in this light (as an attempt to level the playing field across competing hardwares/algorithms/languages), then we could see it as the concatenation of the following:

1 - the specification of the raw hardware. 2 - the microcode for the hardware. 3 - BIOS, drivers, HAL, OS, etc. 4 - language implementation/runtime/shared libraries etc.

Now, to compare any two real-world implementations, we need to port them both to the language implemented in #4, for running on the hardware specified by #1-3 and sum their length with M's length.

And if we want to compare two algorithms from different languages (but running on the same 'machine'), we can shift the codes in #4 into the 'texts' of the programs themselves (so as to keep M constant between them). We can do this all the way down to the minimum M required to be Turing complete (and nearly all the way 'up' to the programs under test); i.e., the division between M and a particular text, L0, is somewhat variable.

Re:On comparing languages, C++ and Go by fauigerzigerk on Monday October 07, 2013 @05:37PM (#6511447)
So you are constructing a particular universal language that is designed to make any compression algorithm written in it so long that the concatenation of the algorithm and its own output would always be longer than its input.

First of all, I doubt that this is even possible, because the input, i.e L1 and T0 is arbitrarily long in the general case, while the algorithm's length must be determined before it sees any input, i.e it is constant. That's related to the invariance theorem: http://en.wikipedia.org/wiki/Kolmogorov_complexity#Invarianc...

But even if it were possible or if we agree to arbitrarily limit the size of the input for practical purposes, you wouldn't have achieved your original goal, which was to show that a verbose language can never be as expressive as a terse language.

Your universal language is neither a Turing machine nor any other generally accepted universal language, so no one would agree to accept this particular language as a test of Kolmogorov complexity.

If you can disprove the invariance theorem you may have come up with a valid criticism of Kolmogorov complexity itself, but you were the one who initially based his argument about the expressiveness of programming languages on Kolmogorov complexity. If you invalidate Kolmogorov complexity you invalidate your own argument as well.

In any event, this has been a fun thought experiment.

Re:On comparing languages, C++ and Go by yohanatan on Monday October 07, 2013 @06:53PM (#6511870)
Yes, fun thought experiment indeed.

I think I am suggesting to construct a particular universal language designed to make any compression of some reasonable T0 and J1 written in that UL (e.g., the source code of Microsoft Windows written in F# and C respectively) longer than T0 and J1 themselves, hence leaving them to be their own Kolmogorov limit (if you will). This seems entirely doable to me within the confines of the 5-tuples afforded me by the formal definition of a Turing machine (although I can see how others, including you, might be less convinced). :-) Maybe I, or someone else sufficiently motivated, will attempt it someday.

Re:On comparing languages, C++ and Go by kvb on Saturday October 05, 2013 @10:16PM (#6502810)
See Felleisen's "On the Expressive Power of Programming Languages"[1] for one formalization that differs from conciseness. Essentially, Turing complete languages can express the same programs at the very coarse "whole program" level, but the paper advocates taking a more local view to assess expressiveness (e.g. what programs in L1 can you write in L2 without having to do a whole program transformation). See also Neal Gafter's related commentary[2] (in the context of the various proposals for closures in Java).

[1] http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.51.4...

[2] http://gafter.blogspot.com/2007/03/on-expressive-power-of-pr...

Re:On comparing languages, C++ and Go by yohanatan on Saturday October 05, 2013 @10:35PM (#6502847)
One doesn't have to look far before he finds a fatal flaw in the commentary. Particularly this:

"In my mind, a language construct is expressive if it enables you to write (and use) an API that can't be written (and used) without the construct." - Neil Gafter

Once more, there is no such construct. All APIs can be written and consumed without language support. Otherwise, Boost would not have had all the new C++ goodies (as an add-on library) before they became part of the language itself. And, of course, one can always put the 'human compiler' to work to produce boilerplate that would be produced by the compiler if the language in question supported the feature in question (if there isn't an add-on library providing the feature in question). One can always do this but the discriminating one tries to avoid it and instead chooses 'expressive' (i.e., conciseness-facilitating) languages. [In the case of closures in Java, one [human-compiler] would merely use one-off interfaces or anonymous classes].

I will take a look at the other links but I gave up on the commentary after seeing such a blatant falsehood.

Re:On comparing languages, C++ and Go by kvb on Sunday October 06, 2013 @02:18PM (#6504867)
C++ has features like operator overloading that make faking lambdas via Boost feasible. And even Java has anonymous inner classes that allow a rather ugly local transformation somewhat akin to closures. But if you removed that feature, then you'd need a non-local transformation to fake them.
Re:On comparing languages, C++ and Go by yohanatan on Sunday October 06, 2013 @07:47PM (#6505927)
You apparently didn't read all of my comment as I mentioned Java's anonymous inner classes being used to fake lambdas near the end. And, the point remains, given any TC language L, all possible language features for all possible languages are implementable within L itself. It doesn't matter if L has operator overloading or not; only that it be TC.
Re:On comparing languages, C++ and Go by cmccabe on Saturday October 05, 2013 @07:34PM (#6502489)
Are you sure about that?

Yes.

Re:On comparing languages, C++ and Go by yohanatan on Saturday October 05, 2013 @09:58PM (#6502781)
You can be sure if you want but unless you back up your claim with some reasoning, others will consider you wrong.
Re:On comparing languages, C++ and Go by CCs on Sunday October 06, 2013 @12:57PM (#6504602)
A line from a real code (a library):

    "* ^^"._? #> (a.!?(1, Get())) must be_==(Full(Answer(1))) ?~! eventually
It is very short, most of the people would implement the same thing using 5-10 lines of code. I prefer 5-10 lines of code over regex-like syntax.
Re:On comparing languages, C++ and Go by cmccabe on Sunday October 06, 2013 @06:51PM (#6505761)
A more obvious example is minified JS versus regular JS. Briefer? Definitely. More expressive? Definitely not.
Re:On comparing languages, C++ and Go by cmccabe on Sunday October 06, 2013 @01:22AM (#6503234)
"Brevity and expressiveness are not the same."

"Are you sure about that?"

"Yes."

Do I need to explain?

Re:On comparing languages, C++ and Go by yohanatan on Sunday October 06, 2013 @08:43PM (#6506042)
I think you're confusing expressiveness of the language with expressiveness of a particular text written in that language. English certainly affords you the opportunity to share more thoughts but given that you seemingly only wanted to express an affirmative, in English 'yes' is pretty much the minimum. You could have said 'Ya' but that is slang. If you open up the choice of language then you could have said 'si', or '#t' or even just '1'. But with such a short intended message, language choice hardly matters.

Certainly if you intended to say more than 'yes' then you failed at adequately expressing the message to begin with so comparisons at that point are moot: i.e., two pieces of text must both express precisely the same ideas before comparisons of them make sense.

Re:On comparing languages, C++ and Go by charlieflowers on Sunday October 06, 2013 @02:50AM (#6503380)
He gets points for brevity. You gotta admit that :)
Re:On comparing languages, C++ and Go by cgag on Saturday October 05, 2013 @06:43PM (#6502355)
I'm not sure if it's because the JVM has a bad rep or people like the familiar feeling of Go (smaller learning curve) or some other reason, but it surprises me so many people jump to Go for performance similar to what you'd get on a modern JVM language (Clojure, Scala), but with less expressiveness, fewer libraries, and (I believe) less tooling.

Of course this only really applies to long running apps (web servers), if startup time matters then certainly Go wins.

Perhaps I need to try Go out, but I just don't see what the selling point is.

Re:On comparing languages, C++ and Go by fauigerzigerk on Sunday October 06, 2013 @03:56AM (#6503482)
People are trying to get as much space as possible between themselves and the Java community's culture of complexity. I don't think it's a technology issue.
Re:On comparing languages, C++ and Go by adamc on Sunday October 06, 2013 @12:21PM (#6504489)
"the Java community's culture of complexity" -- great evocative phrase.
Re:On comparing languages, C++ and Go by pjmlp on Sunday October 06, 2013 @12:56PM (#6504597)
s/Java/Enterprise/g
Re:On comparing languages, C++ and Go by azth on Sunday October 06, 2013 @03:08AM (#6503403)
> but it surprises me so many people jump to Go for performance similar to what you'd get on a modern JVM language

In a word: hype. If Go did not have the Google brand name attached to it, it wouldn't have gone anywhere.

Re:On comparing languages, C++ and Go by kkowalczyk on Saturday October 05, 2013 @05:34PM (#6502158)
You're empirically wrong.

I actually did write a fair amount of Go code (my primary languages are C++ and Python).

On real, non-toy programs it is significantly more concise than C++, in the ballpark of Python code.

This isn't visible on code snippets (less than 500 loc) like the toy raytracer, but trust me: you'll see a big difference on 10k loc codebase.

Re:On comparing languages, C++ and Go by m0th87 on Saturday October 05, 2013 @07:01PM (#6502395)
I've just wrapped up a go program that's not a toy, albeit not as large as 10k - it's a little over 3k. It was not nearly as terse as python, although the performance increases made it well worth it. This is something that surely varies a great deal from one application to another.
Re:On comparing languages, C++ and Go by npalli on Saturday October 05, 2013 @06:08PM (#6502264)
Without knowing what your program did, it is hard to see what language features caused the difference. In any case, why was Java not a better option than Golang?
Re:On comparing languages, C++ and Go by TylerE on Saturday October 05, 2013 @06:11PM (#6502271)
Go outputs a statically linked binary that just RUNS. Java needs a quite heavyweight runtime to be installed, that imposes quite a bit of startup overhead. That's just one reason - for short runtime CLI-type utilities it's not in the same ballpark.
Re:On comparing languages, C++ and Go by npalli on Saturday October 05, 2013 @06:47PM (#6502369)
Ok, so lets go with your use case. You can run basic java ("hello world") under 3MB with a startup time of about 0.1 second. So that is the true overhead if you really care about tight code. The default values are pretty large. Everything else (memory/startup) is added due to external libraries that are needed and additional memory as the program grows.

Given that "kkowalczyk" talked about 10K line programs, what applications are you thinking of that are 10K lines and cannot tolerate a 0.1 second/3 MB overhead. Would you restart java everytime? Note that even a simple helloworld c program has about 0.01second/0.5MB overhead.

Re:On comparing languages, C++ and Go by m0th87 on Saturday October 05, 2013 @07:12PM (#6502426)
I was going to say there's no way java programs boot in 0.1 seconds, but looked it up to be sure. Here's the results on my mac/i7, defaulted to server mode:

    $ time java HelloWorld
    Hello, world!

    real	0m0.101s
Touche. 0.1 seconds is exactly right, at least on my setup. That said, javac is slow given the program is 5 lines of code:

    $ time javac HelloWorld.java 

    real	0m0.511s
    user	0m0.833s
    sys	0m0.050s
And I'd ventured to guess that there must be something to the JIT being pretty slow for real-world applications, otherwise people wouldn't complain so frequently about it. Maybe aspects of JIT optimizations increase linearly-ish with the amount/complexity of code?

FWIW, we went with go at my work instead of java because our application is memory-intensive, and there's huge gains there in go over java.

Re:On comparing languages, C++ and Go by bchjam on Saturday October 05, 2013 @07:37PM (#6502494)
A program that consists solely of println("Hello, World!"); is pretty stateless and trivial, there's not much that a JIT could do with this.

Somewhat anecdotally, I remember hearing Rich Hickey talking about how the JVM JIT loves stateless code. I'm pretty sure the vast majority of Java code in use is deeply stateful. I don't know how much of a difference this actually makes but it seemed like a relevant data point.

Re:On comparing languages, C++ and Go by tptacek on Saturday October 05, 2013 @07:18PM (#6502444)
You are off by two orders of magnitude in the C case, at least with my trivial test case of writing hello world, and then a runner program that forks/execs/waitpids 10,000 times.

If you know what crt0.c does, you can see C is also pretty much the asymptote of what you're going to get from program startup, so it's a little silly to make the comparison.

Re:On comparing languages, C++ and Go by eliasmacpherson on Sunday October 06, 2013 @07:41AM (#6503785)
Is that with the JVM already running or not?
Re:On comparing languages, C++ and Go by pjmlp on Sunday October 06, 2013 @12:53PM (#6504590)
> Java needs a quite heavyweight runtime to be installed, that imposes quite a bit of startup overhead.

One can always use one of the commercial native compilers for Java, any of them can easily produce static binaries with fast startup times.

Don't measure Java the language, by Oracle JVM the implementation.

Re:On comparing languages, C++ and Go by myg204 on Saturday October 05, 2013 @05:27PM (#6502137)
A lot of the verbosity in Go comes from error handling; the language forces you to deal with errors (I think it's a good thing, some may disagree). Expressiveness is real, 'duck typing' does give it a feel of scripting language like Python, and it is way less verbose than Java (apart from error handling). And to be fair, Go is faster than Python (the numbers tell you that), and (slightly?) more expressive than C --and just in a league of its own for concurrency.
Re:On comparing languages, C++ and Go by azth on Sunday October 06, 2013 @03:03AM (#6503393)
> and just in a league of its own for concurrency.

Not really. Other languages are far superior in this regard (see Scala or Rust for instance).

Re:On comparing languages, C++ and Go by nly on Saturday October 05, 2013 @05:43PM (#6502188)
I think the reason both versions lack conciseness is because they're faithful translations of one another. I wouldn't call either well structured, but maybe that's because I don't understand the problem domain well enough. T() in the C++ versions especially looks awful.
Re:On comparing languages, C++ and Go by corresation on Saturday October 05, 2013 @05:58PM (#6502238)
To concur with what kkowalczyk, there is little expressiveness advantages to be gained for this specific example -- math is math, and outside of compressing it down to a couple of library calls, what could possibly be done better?

"they ended up with a language with the expressiveness of C and the speed of python."

This is just pure troll. Apparently you have a Python variant of this renderer that matches the already impressive Go performance? Please reveal it.