News for hackers. Stuff that matters.
Re:Git's list of banned C functions by cletus on Thursday March 04, 2021 @06:51PM (#26350231)
If I had to choose a language to teach programmers to absolute beginners, I think I'd actually go with Go.

I understand the predilection for Python but there are some parts of Python that are just... odd.

Re:Git's list of banned C functions by hguant on Thursday March 04, 2021 @06:58PM (#26350308)
Python is great fun, and you can be really productive with it, but for people first coming into programming, a language with an explicit and strict type system is invaluable.

I used to think that everyone should be taught python first, because it lets you focus on the meat of computer science - algorithms, data manipulation, actually _doing_ something - but after helping my girlfriend out with some comp sci 101-104 projects, I really think Go, Java, or Rust should be everyone's first language. It's hard for someone new to the field to understand the nuances that come with python's corner cutting. You can work yourself into some weird corners because of how permissive the language is, where in a (strongly) typed language, the complier just says no.

Re:Git's list of banned C functions by harpiaharpyja on Friday March 05, 2021 @10:26AM (#26357837)
I use Python a lot professionally these days, after having been a C#/Java developer for a while (and some experience with C and Free Pascal). I absolutely love the language.

I always feel a little iffy when people talk about Python like it's a language ideally suited to beginners.

Dynamic typing puts so much power in your hands to create expressive structures. But it requires discipline to use properly. It's a great trade off for me but I don't think it would be for beginners.

Re:Git's list of banned C functions by InvOfSmallC on Saturday March 06, 2021 @04:47AM (#26366341)
My reasons for suggesting Python compared to Java for example is due to the fact that I teach to Electrotechnical engineers and there are plenty of libraries to experiment with Raspberry and stuff and it's a little bit higher level than C. Every language has its own difficulty to teach but the fact the companies have a banned.h it's basically saying "well C gives you functions for C, but don't use them". It makes it unecessary harder to explain something to people with no experience.
Re:Git's list of banned C functions by kab_al_ashraf on Thursday March 04, 2021 @09:56PM (#26351983)
> You can work yourself into some weird corners because of how permissive the language is, where in a (strongly) typed language, the complier just says no.

Could you share an example?

Re:Git's list of banned C functions by blahedo on Thursday March 04, 2021 @11:08PM (#26352563)
Here's one my (intro programming, non-major) students have just been tripping over this week:

  if word == "this" or "that":
      ...
Not an error, always runs. Very mysterious to a beginner. (Shared with C/C++) Another one:

  counter = "0"
  for thing in things:
      if matches(thing):
          counter += 1
The error is in the init, by someone who is overzealous with their quoting, but the error is reported, as a runtime error, on the attempted increment, which throws a TypeError and helpfully tells them "must be str, not int", and of course I know exactly why it's reporting the problem there and why it's giving that error, but it's a bit confusing to the newbie programmer and it doesn't even turn up until they actually test their code effectively, which they are also still just learning how to do.
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.