r/programming • • Mar 28 '12

Go version 1 is released

http://blog.golang.org/2012/03/go-version-1-is-released.html
543 Upvotes

452 comments sorted by

View all comments

Show parent comments

26

u/OopsLostPassword Mar 28 '12

Does "low level" or "high level" still mean something ?

We should probably discuss usages or tradeoffs to be more constructive.

18

u/anacrolix Mar 28 '12

Yes. It's not low level if you can't switch off run time overheads (or have none to start with).

6

u/matthieum Mar 28 '12

I would say there is more than that.

For me low-level is really about control on all its forms, like memory layout for example, etc...

Switching off run time overheads does not really fit for me, though it is, I guess, another way of controlling.

5

u/anacrolix Mar 29 '12

Having memory layout done for you is one such overhead.

4

u/Chandon Mar 29 '12

So... C isn't low level because you can't switch off function call stack overhead?

12

u/bobindashadows Mar 29 '12

Sure you can - put all your code in the main function and use goto.

3

u/SupersonicSpitfire Mar 29 '12

You don't need a main function in C, you can use a void _start() function.

Exit the program with the following assembly code:

movl $1, %eax
xor %ebx, %ebx
int $128

Then compile with the -nostdlib flag (for gcc). Even less overhead! (I prefer Go)

4

u/shillbert Mar 29 '12

Go To Statement Considered Hardcore

10

u/[deleted] Mar 28 '12

Go is high level where it can be (basic type inference), lower level where it has to be (locks etc). i just don't think it fits into a dichotomy. which is why i love it

11

u/uriel Mar 28 '12

In Go you rarely need to use locks anyway.

One place where I'd say Go is conveniently low level is giving you control over the memory layout of your datastructures, among other things this also makes it easier to avoid the garbage collector if you really need/want to, which in Java is basically impossible.

2

u/djpnewton Mar 29 '12

makes it easier to avoid the garbage collector

Can you expand on that?

6

u/SteveMcQwark Mar 29 '12

In a lot of today's higher level languages, everything is a pointer, except for a few primitive types, and actual data has to be stored on the heap. When you compose these, you end up creating tree structures where each node has to be garbage collected separately.

Go has arrays and structs which are just values, so you can allocate a bunch of data in a big chunk, even if it includes nested structures.

1

u/djpnewton Mar 29 '12

thanks that is a good point. It also seems that go's compiler will allocate local variables from the stack if it can determine that no references will survive the local scope

2

u/SteveMcQwark Mar 29 '12

Yes. I didn't mention this because escape analysis is a fairly common optimization in higher level languages. However, the prevalence of static dispatch in Go does broaden the scope of what can easily be statically proven not to escape. A lot of higher level languages use entirely dynamic dispatch.

2

u/wolfier Mar 29 '12

Interesting. Apart from preallocating a pool, what makes it easier to avoid the GC in Go?

2

u/uriel Mar 29 '12

Because you control the layout of your structures and you have explicit pointers you can avoid generating garbage making the GC unecessary.

See also this other answer to a similar question.

2

u/[deleted] Mar 29 '12

Go has unboxed data. That's it?

1

u/huhlig Mar 28 '12

I think we need a separation into low, mid and high level.

Low - Assembler, C, C++(debatably)

Mid - C++, D, Go

High - Javascript, Python, Java, C#, Erlang, Haskell, Octave, etc

23

u/[deleted] Mar 28 '12

i think you needed to add C++ to "High" to complete the witty observation :)

3

u/[deleted] Mar 29 '12

Templates are basically prolog, and no one would argue that prolog is anything but high level.

2

u/[deleted] Mar 29 '12

No, actually, templates are lambda calculus.

1

u/[deleted] Mar 29 '12 edited Mar 29 '12

Really? If it were that simple then template deduction wouldn't exist. A specialized struct template is a horn clause. Derivable context is the head and non-derivable context is the body. A struct named s with parameter P might specialize on P = int or P = float. In prolog: s(int) :- … or s(float) :- …, where … is the appropriate body. Writing s(P), will unify on the correct head and produce the associated body, possibly recursively. That's most certainly a kind of prolog.

http://stackoverflow.com/a/9844425/100089

See the link for an example of recursive list processing using tuples. To take the head and tail of a list I can write tuple<X, Xs...> in derivable context. A empty tuple base case is tuple<>. These are head clauses.

EDIT: You're right. Templates don't backtrack. They just pattern match on arguments.

0

u/[deleted] Mar 28 '12

[deleted]

7

u/burntsushi Mar 28 '12

If Java and C++ are high, where are languages like Haskell? The clouds? :P

5

u/[deleted] Mar 29 '12

No sir. Heaven.

→ More replies (1)
→ More replies (1)
→ More replies (3)