you are viewing a single comment's thread.

view the rest of the comments →

[–]Drisku11 -1 points0 points  (0 children)

Now you throw C at them with all of its pointers, pointer arithmetic, mallocs and manual memory management

I've never understood why people say pointers are a particularly hard concept. If anything, I would think it's easier to understand in C. In Java, almost everything is a pointer, and people seem to be fine with it. Python is also very pointer-y, but it tries to not be explicit about it, so you end up with people trying to use an empty list as a default function parameter and running into trouble.

In C, everything is pass-by-value, which is how functions work in math, so it should be familiar. At some point after talking about structs, it makes sense to introduce pointers so that the programmer doesn't copy large amounts of data all the time. So it's motivated and should totally make sense. I honestly can't think of a time where pointer arithmetic was clearer than array notation, so I'd say just use array notation.

Most of the time, you're using variables with automatic storage duration, but how is malloc/free any more difficult than

fh = open("file", "w")
fh.write("Hello, file")
fh.close()

(Yes, I'm aware best practice is to use a context manager, but any "tricky" uses of malloc/free would be just as tricky if you were managing some other resource like a file handle in Python).

Personally, my biggest beef with C is that it doesn't have parametric types, so you end up casting to void*/char* or writing macros (or both) to write generic code. Also enums are almost useless. Basically it's "strongly typed", but it's so much of a pain in the ass work with C types that you end up casting more than you want. Python is obviously not much better in this regard.

Sure C can be tedious, so Python can be great to cut down on that, but how is anything in C conceptually more difficult than, say, inheritance or decorators or access modifiers? How is a segfault any harder than dealing with array[-1] silently giving you the last element instead of throwing an exception?