News for hackers. Stuff that matters.
Re:Git's list of banned C functions by int_19h on Thursday March 04, 2021 @07:21PM (#26350557)
There are parts of Go that are similarly odd. Arrays and slices, and the hoops you have to jump through to do something as simple as adding a new item to a list, are very unlike anything else, for example.

In Python, the weird stuff is generally easy to avoid/ignore until it's actually needed.

Re:Git's list of banned C functions by ericbarrett on Thursday March 04, 2021 @09:46PM (#26351901)
Very true, but if you're teaching CS then this also exposes students to the topic of ownership-versus-reference in a much gentler way than C.
Re:Git's list of banned C functions by int_19h on Friday March 05, 2021 @07:02AM (#26355880)
If I remember correctly, slices in Go also have ownership semantics, in a sense that so long as any slice exists, the array is kept alive by the garbage collector.

Or do you mean value vs reference semantics? In that case, I think C pointers are simpler as a fundamental concept, and slices are best defined in terms of pointer + size.

Re:Git's list of banned C functions by wbl on Friday March 05, 2021 @02:02AM (#26353729)
In Java you do the exact same reallocation dance as append does behind the scenes when using arrays.
Re:Git's list of banned C functions by int_19h on Friday March 05, 2021 @06:59AM (#26355859)
Java standard library does that, not you directly. The issue here is not performance, but rather ergonomics. For example, in Go, you can forget to assign the result of append to the variable, and it'll even work most of the time (because there was still some unused capacity in the array, so there was no need for reallocation).
Re:Git's list of banned C functions by wbl on Sunday March 07, 2021 @09:19PM (#26381755)
Which method? Note im talking about the language level array, not ArrayList. Also this was years ago.
Re:Git's list of banned C functions by int_19h on Sunday March 07, 2021 @11:35PM (#26382318)
Java arrays don't have add() at all - they're fixed-size once allocated.

ArrayList etc do have add(), and they implement it by re-allocating the backing array once capacity is exceeded.

In practice, you'd use the ArrayList anyway. I don't think it's worthwhile comparing Go and Java "language-only", because the standard library is as much a part of the language definition as the fundamental syntax; indeed, what goes where is largely arbitrary. E.g. maps in Go are fundamental, but the primary reason is that they couldn't be implemented as a library in Go with proper type safety, due to the lack of generics.