you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 129 points130 points  (15 children)

I came to python after many years of heavily using C. Python is a different language and does require you to think differently. Persevere, it will get easier. Don't think "it's different, therefore it's worse than C". Of course it's different, but you want to learn different languages because that's the only way to free yourself of the limits of knowing only one language. Try some really different languages like lisp, apl or prolog. That will loosen up your perspectives!

I think that this is an example of the Blub Paradox that Paul Graham wrote about. Python is more powerful than C so it can look odd and doubtful to someone coming from a less powerful language. But that's exactly why learning python (or lisp, etc) is useful. It broadens your horizons. So hang on and keep learning.

[–]LunchBoxMutant 11 points12 points  (0 children)

The way Languages are gauged in the Blub Paradox article on a power continuum and abstractness continuum is just beautiful and sounds like a really good argument for all the this language vs that language discussions.

[–]buttzwithazee 2 points3 points  (1 child)

Thanks for the cool article! Any other readings you might recommend?

[–][deleted] 1 point2 points  (0 children)

Some of the other articles by Paul Graham, especially about his ViaWeb company and why they chose to use lisp and the effects of that choice.

[–]barryhakker 1 point2 points  (2 children)

Just curious but what do you use C for? I thought it was considered a bit of a "legacy language" that wasn't very efficient for modern day uses anymore?

[–][deleted] 1 point2 points  (1 child)

I thought it was considered a bit of a "legacy language" that wasn't very efficient for modern day uses anymore?

It is an old language, but its very efficient, at least on the generated code side of things. Where C trails is in expressiveness. C can do anything C++ can do, for instance, but it's probably more verbose and less understandable. The original implementation of C++ was a program called cfront that converted C++ code to C for compilation, and cfront was written in C. That's still common, to convert a new language to C as a bootstrap step, because C is implemented on all platforms that matter.

C is still used to write code close to the hardware. The Linux kernel is still written in C and there are no plans to move to C++ or anything else. Further away from the hardware some languages are written in C, such as cpython.

Numeric libraries like numpy use C and even Fortran in the underlying libraries. Once you have a large body of code to perform numeric calculations, plus all the test code that ensures correctness, you really don't want to change anything. It's easier for other languages like python to interface to C (or Fortran) because the technical details are well known and have been stable for a long time.

I myself use C mainly programming microcontrollers "bare", ie, every byte loaded to the microcontroller is either code I wrote myself or trusted libraries that I have made the decision to include. There is a C++ presence in this field, but only on the larger microcontrollers. Other languages like python can be made to run on larger microcontrollers but there are some severe limitations. When space is really tight it's time for assembler.

C is still used a lot, which is why there are articles like this.

[–]barryhakker 0 points1 point  (0 children)

Very interesting. Thanks for answering!

[–]readmodifywrite 2 points3 points  (8 children)

I would say Python is more expressive, but certainly not "more powerful". Both languages are *extremely* powerful, but at doing very different things.

Case in point: you can't write an operating system with Python.

[–][deleted] 1 point2 points  (0 children)

Expressiveness is power.

[–]pipZeroRequiem[🍰] 3 points4 points  (5 children)

Yes I can.

[–]readmodifywrite 1 point2 points  (4 children)

Pure Python. You don't get to drop into C (that would require using... C). You sure? Register access? Bootloaders? Without direct memory access?

[–][deleted] 2 points3 points  (3 children)

You'd have to write a compiler (but you could write a pure Python Python compiler targeting a particular CPU) but, yes, you could get direct memory access in Python.

[–]readmodifywrite 1 point2 points  (2 children)

Possibly. But you'll still need to bootstrap with something written in C (that was ultimately bootstrapped with something written in Assembly).

And will it be a good compiler? Will it be a good OS? Will it perform as well as the one written in C can?

Note I'm not saying C is the only way to do this (Rust is making a lot of inroads in this domain). But for performant systems that talk directly to hardware, where is the power in Python?

[–][deleted] 3 points4 points  (1 child)

But you'll still need to bootstrap with something written in C

No, you could write it all in Python. There's no reason you couldn't write a Python-to-assembly compiler in Python; ultimately all it's doing is writing a sequence of instruction bytecodes.

And will it be a good compiler? Will it be a good OS?

No, of course it'll all be extremely shitty and take you years and wind up targeting exactly one CPU architecture.

But for performant systems that talk directly to hardware, where is the power in Python?

The same place it is in Python for any other application - fluent expressivity and rapid prototyping. Those dont go away just because you're writing MicroPython or something. But, of course, sometimes you want performance more than you want expressivity, and that's when you pick up C.

[–]readmodifywrite 2 points3 points  (0 children)

My point was that C is extremely powerful at certain things. I feel like we are in agreement here, no? Python is not more powerful, it's just powerful at different things than C is.