Good choices IMHO - they are both the "go to" languages when you want to realy get things done. They are included as standard on the Pi and there is good support for them. The main GPIO library support is for C and Python.JFamily wrote:I want to learn both C and Python, I just don't know which one I should start with so I'm making this post as a bit of a poll.
I'm not sure I'd call C "top" level. Its fairly close to the machine with a good correspondence between its data types and operations and those of the hardware. So it is very fast. Yet at the same time portable.JFamily wrote:I understand C is a much more top level (correct term?) language, in which other languages and entire OS's have been written with.
Pascal, Fortran, B, Algol 60, Algol 68, Forth, various assemblers, BCPL, REXX, C, Lisp and others I cant remember. Mostly long ago. Now I generally use C, with a little bit of python, and some assembler for fun.JFamily wrote:What languages have you all learned, what order did you learn them in, and would you do it the same way again?
I know what you mean. In my time I have had to learn and use: BASIC, Algol, C, C++, Pascal, Ada, Coral 66, PL/M 86, Lucol, and no doubt a few others I forget.Once you've learned one language the next twenty five are just a case of learning the differences and syntactic anomalies.
Cool, that's more or less what I was trying to expressbuja wrote:Funny, I would say things are the other way around: C is the more basic and low level language and Python is the high level language that will get you going a lot faster than C does in terms of programming effort (number of programming instructions/program lines). Python will take care of a lot of details that you will have to program yourself in C.
That's the direction I was leaning; I'm just afraid I'll learn Python, be satisfied, and not go any deeper.buja wrote:On the Pi I would recommend learning Python first, because it has excellent support on the Pi. In fact, almost every hardware extension has great support in Python, but only limited support in C (for example Explorer HAT, Sense HAT, etc.).
True. After I had a pretty good grasp on PHP, I started reading ASP code and quickly saw that they are more or less the same language with different syntax and rules. With a good understanding of PHP, I could easily read and understand ASP code (I just couldn't write it)DougieLawson wrote:Once you've learned one language the next twenty five are just a case of learning the differences and syntactic anomalies.
Python being an interpreted language gives instant gratification: edit, save, test, repeat. The compiled languages have a longer sequence: edit, save, compile, edit out the compiler errors, save, compile, test, repeat.
NotedDougieLawson wrote: If you're going to learn python assume that python2 never existed.
When I was young (in the mid 90's, about 3rd/4th grade), the first language I tried to take a crack at was C++. I learned a bit, wrote some hello world, a simple game, and some other stuff I can't remember. But was ultimately turned off from the language (not really sure what turned me off about it... I was young though). So I dropped it, and began my path to learn internet languages. I'm happy this happened, because it quickly evolved to building a 'server' (old computer w/ linux, apache, php, mysql installed), and of course learning about/how-to-use linux.bensimmo wrote:Whatever happened to C++?
When I was young fresh out of Basic and looking to self teach the next thing. C++ and Pascal were always the ones mentioned and C was the one not to do.
(Must be early/mid 90s)
Heater wrote:Worse it has no recognized standard and keeps changing.
Maybe that is what turned me off, and I just didn't have the words for it!Heater wrote:@bensimmo,
Whatever happened to C++?
Indeed. I was backwards in my phrasing (left-handed problems?). I've been down the quick calculations, visualization of data, save-test-edit-save-test-edit road with PHP. I'm definitely planning to learn both, just trying to decide which to learn first.jb63 wrote:I started with Fortran 77 (anyone remembers that?) then moved onto C (Kernighan & Ritchie) ... ultimately I ended up using Matlab more than any others.
Now, as others have said on here, C is a very 'low-level' programming language, in the sense that you can do bit/byte level manipulation, accessing hardware, etc rather easily. BUT, while some see this as powerful, others see it as prone to errors.
If you're after manipulating large data sets (e.g. multi-dimensional matrices), then you need to learn about pointers and handles (pointer to a pointer), then you have linked lists, ... and it gets even more involved. There are libraries you can call/use but typically those need to be purchased. Also, a C program is NOT always the easiest to read. In fact, I recall some competitions many years ago where the contenders were to write the most 'confusing' piece of code, to do the simplest of tasks (increment a counter).
In contrast, if you're after 'readability' of your code, then Python is the way to go.
I see them (C/Python or C/Matlab) as complementary. If you have ambitions to write serious code to access hardware, graphics, etc ... then C is the way to go. If you're after quick calculations and visualization of your data, stick with Python. Ideally? .. learn both
There are many Pythonistas who have extended their interests into C. The standard Python interpreter is written in C - so you will learn C if you get interested in the implementation details of the interpreter. Or, alternatively, you might end writing a Python program that just is not fast enough for you - and, instead of writing the whole program in a faster language, you might write a Python module in C and use that in your Python program to speed things up. Or maybe you would need some functionality for your Python program but there just is not a library available and you have to write your own - in C. The Python/C combo is a natural one, and should be very powerful.JFamily wrote: Without actually spending any time reading existing Python code, and only reading some C code, I would venture to say Python will be much more natural to pick up on. My fear is, will it make me more hesitant to get deeper into programming, and learn C?
I would start with bash and do the sorts of simple scripts, or not simple ones, that everyone needs to improve their use of their systems. Then you can learn by doing and that makes it more interesting. Since bash is a million times crazier than Python and C combined, figure it out and you'll be fine anywhere.JFamily wrote:I want to learn both C and Python, I just don't know which one I should start with My fear is, will it make me more hesitant to get deeper into programming, and learn C?
I learned BASIC before C, which is similar to learning Python first. However there is a lot to recommend learning C, especially of you are an adult and already have some computer experience.JFamily wrote:I want to learn both C and Python, I just don't know which one I should start with
Absolutely correct. I 'understood' many of the computer's architecture/logic from simply learning/using C. Then, the idea of files stored in non-contiguous locations haunted me for sometime, until I discovered some tools that not only confirmed that, but offered a way to de-fragment files. Possibly the best 'introductory' example is that of pointers in C. It took a while, but once you understand that, many more ideas open up 'naturally'.ejolson wrote:Moreover, knowing how to read and write C programs allows one to start understanding how all that software actually works.
I wrote a DOS-based application for machinery diagnostics back in 1989 ... but back then it was dynamic memory allocation with malloc and realloc ... and the error codes returned by such function calls were everything but trivial.ejolson wrote: stack-allocated variable-length arrays and complex numbers
That'll go a long way indeed. But... the 26th will be Clojure, the 27th will be Haskell, and the 28th PROLOG.DougieLawson wrote:Once you've learned one language the next twenty five are just a case of learning the differences and syntactic anomalies.
Python is compiled to bytecode, just like Java and C#. Then, a 'virtual machine' or a 'runtime' executes the bytecode. This is different than for example Shell or Tk, where the source instructions are parsed again and again and again, which makes them much slower.jb63 wrote:Python is an interpreted language, where instructions are read one at a time and executed
The reason that C runs faster is that it is much closer to the metal. Some would call C even a 'glorified assembler language'. There are tons of things Python does for you which C doesn't, like memory management and garbage collection, very nice data types and collections, object orientation throughout, dynamic typing.C must be compiled first, and that typically makes it run FASTER than Python.
Interesting. I guess that makes it easier to add C functions to Python programs.but the Python runtime (CPython's runtime at least) is not written in C++, but in plain C.
It is, but think about this: Python is compiled into bytecode on-the-fly probably a line at a time. That means the compilation must be quick with little optimization or the program would run terribly slowly. It certainly cannot take into account surrounding code. As noted above, C compiles the entire program first, with no time constraints. That means the whole program can take part in the optimization and many complex passes can be done leading to some very clever optimizations.Michiel O. wrote:Python is compiled to bytecode, just like Java and C#.
The reason that C runs faster is that it is much closer to the metal.C must be compiled first, and that typically makes it run FASTER than Python.
I used to think that as well. "Interpreted languages, bah, useless, they cannot even rebuild themselves"The fact that the Python run-time is written in C doesn't surprise me, but it is sad when a general purpose language (which is so powerful you can code things ten times as quickly ) cannot even run itself but has to depend on another, supposedly inferior language.
It can. There exist many implementations of Python. However, most of the time when people say Python, they mean CPython. PyPy is written in Python and can compile and run Python, and do optimisations, and when the program runs the JIT compiler will convert the running program to machinecode.it is sad when a general purpose language (which is so powerful you can code things ten times as quickly ) cannot even run itself
C is not inferior to Python, it just has a different place in the spectrum of programming languages. It is somewhat less high-level than Python, Swift and Ruby etc... but certainly not inferior. It depends on what you want to do with a language. If you need to do data extractions from relational tables in a database you'd probably use SQL instead of machine code. But if you have to write a boot program for an embedded system, machine code is the way to go....but has to depend on another, supposedly inferior language.
Yeah, C was my fourth language (after assembly, FORTRAN, Basic). Your statement about Python seems a bit biased to me, it isn't that bad. I write both and the differences are minimal from the perspective of an application programmer.Finally, C has been around for some 45 years, with new standards, but no one change broke it as badly as the Python2 vs Python 3 nonsense.
I agree! I switched to Python from C++ because of the nice, clean data structures and lack of arcane syntax. The indent-by-whitespace I found ridiculous, but only for 20 minutes or so. I was used to correctly indenting my source codes anyway, regardless of language.Actually this debate is wrong, both languages are good, just intended for very different purposes, and so should not be compared
Well said!Michiel O. wrote: C is not inferior to Python, it just has a different place in the spectrum of programming languages.
Its actually in C (of course) though I believe the "official" language changed to C++ a few years ago.In what language do you think the GNU C Compiler is written in?
I agree its not too bad. But the fact is there is still this division, old libraries in v2 that cant be updated, questions on the forum "shall I learn python 2 or 3", basic arithmetic (/) changing meaning, and so on. You didn't see any of that when C11 appeared.Yeah, C was my fourth language (after assembly, FORTRAN, Basic). Your statement about Python seems a bit biased to me, it isn't that bad. I write both and the differences are minimal from the perspective of an application programmer.Finally, C has been around for some 45 years, with new standards, but no one change broke it as badly as the Python2 vs Python 3 nonsense.
Which then has to interpret the Python code.Heater wrote: "The PyPy project has developed a tool chain that analyzes RPython code and translates it into C code,which is then compiled to produce a native interpreter."