User avatar
PeterO
Posts: 5006
Joined: Sun Jul 22, 2012 4:14 pm

Re: The MagPi does C :-)

Mon Oct 17, 2016 10:01 am

I've started to rough out some chapter titles and content. More later...

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

User avatar
PeterO
Posts: 5006
Joined: Sun Jul 22, 2012 4:14 pm

Re: The MagPi does C :-)

Mon Oct 17, 2016 6:50 pm

Rough idea of book structure : http://www.peteronion.org.uk/Cbook/CBookOutline.pdf
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

mob-i-l
Posts: 267
Joined: Sat Dec 29, 2012 2:45 am
Location: Lund, Skåne/Scania, Sweden
Contact: Website Facebook Google+ Twitter YouTube

Re: The MagPi does C :-)

Tue Oct 18, 2016 8:41 am

PeterO wrote:
mob-i-l wrote:I think the book should include function pointers and longjmp, because it’s what’s needed to emulate polymorphism and exceptions from C++ in C, respectively.
You do know that the book is intended for beginners don't you? I can't see why you would think such topics are suitable for a beginners book.
Why aren't you using C++ if you want C++'s OO and exception handling ?
C++ for e.g. Arduino/AVR doesn't have exceptions, so longjmp is necessary. Sometimes you just want function pointers instead of using inheritance to accomplish the same thing. I think function pointers and longjmp should be part of a beginners book on C because inheritance and exceptions would be part of a beginners book on Java. It is difficult to sell C as a language if you cannot write elegant programs in it, and you can't without function pointers and longjmp. Even Scratch 1.4 and 2 have function pointers, because you can use variables as messages when sending. In ScratchJr for 5-7 year old kids you can't use function pointers. One could say one has longjmp in all versions of Scratch because of the message-system. I think most kids today learn Scratch or Blockly first, and then they would like to translate those programs into C.
Have Pi0&1A&1B&1B+&2B&3B&4B w/ Raspbian. Started w/ BASIC on ABC80&ZX81 then Forth, Z80… https://scratch.mit.edu/users/mobluse/ https://github.com/mobluse/ https://twitter.com/mobluse/ https://YouTube.com/MOBiL4u/

User avatar
PeterO
Posts: 5006
Joined: Sun Jul 22, 2012 4:14 pm

Re: The MagPi does C :-)

Tue Oct 18, 2016 8:52 am

mob-i-l wrote:
PeterO wrote:
mob-i-l wrote:I think the book should include function pointers and longjmp, because it’s what’s needed to emulate polymorphism and exceptions from C++ in C, respectively.
You do know that the book is intended for beginners don't you? I can't see why you would think such topics are suitable for a beginners book.
Why aren't you using C++ if you want C++'s OO and exception handling ?
C++ for e.g. Arduino/AVR doesn't have exceptions,
But since we are targeting C on the PI that is irrelevant.
so longjmp is necessary. Sometimes you just want function pointers instead of using inheritance to accomplish the same thing.
Again we are talking C so inheritance is irrelevant.
I think function pointers and longjmp should be part of a beginners book on C because inheritance and exceptions would be part of a beginners book on Java.
What has Java got to do with it ? We are talking about C not Java.
It is difficult to sell C as a language if you cannot write elegant programs in it, and you can't without function pointers and longjmp.
That's a non sequitur. Function pointers are useful, longjump very much less so. In 35 years of C programming I can't remember having used setjump/longjump once. Ofcourse YMMV.
Even Scratch 1.4 and 2 have function pointers, because you can use variables as messages when sending. In ScratchJr for 5-7 year old kids you can't use function pointers. One could say one has longjmp in all versions of Scratch because of the message-system. I think most kids today learn Scratch or Blockly first, and then they would like to translate those programs into C.
Scratch can do what it likes, we're talking about C here.... Got the message yet ?
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

Stiller
Posts: 206
Joined: Fri Oct 14, 2016 9:03 am

Re: The MagPi does C :-)

Tue Oct 18, 2016 9:11 am

I love the current MagPi C tutorial (thanks to the author Simon Long for his efforts!), 8-)
I appreciate the extension posted by PeterO http://www.peteronion.org.uk/Cbook/CBookOutline.pdf
I also agree that for newbies to C and the Pi practical projects similar as shown in Python tutorials should have 1st priority (leastways for reasons of motivation) and so I would appreciate a application-oriented curriculum like mentioned
C for GPIOs
C for UART, i2c and SPI (edit, added: USB)
C for HATs
C for graphics
C for the Pi Cam (edit, or a USB cam)
C for audio
C for game programming
but IMO it makes no sense to argue about pixilated details like long jump if there is no compelling reason to use it for a special problem in the tutorial to handle.

edit 2:
perhaps for some applications (e.g., game programming ?) also a future C++ tutorial might be taken into account... :geek:

mob-i-l
Posts: 267
Joined: Sat Dec 29, 2012 2:45 am
Location: Lund, Skåne/Scania, Sweden
Contact: Website Facebook Google+ Twitter YouTube

Re: The MagPi does C :-)

Tue Oct 18, 2016 11:13 am

PeterO wrote:Scratch can do what it likes, we're talking about C here.... Got the message yet ?
I don't agree with the message. I think one must take into account what the readers know before (e.g. Scratch) and the competition (e.g. Java, C++, or ARM-assembly). Maybe one also needs to add fork() to a beginners book on C, since Scratch-programs can have parallell processes, e.g. with clones in Scratch 2. If you don't explain fork() you can't easily translate all Scratch-programs to C.

One advantage with C is that it is useful on smaller systems e.g. Arduino, and that it can result in programs that use less electrical power.
Have Pi0&1A&1B&1B+&2B&3B&4B w/ Raspbian. Started w/ BASIC on ABC80&ZX81 then Forth, Z80… https://scratch.mit.edu/users/mobluse/ https://github.com/mobluse/ https://twitter.com/mobluse/ https://YouTube.com/MOBiL4u/

Stiller
Posts: 206
Joined: Fri Oct 14, 2016 9:03 am

Re: The MagPi does C :-)

Tue Oct 18, 2016 11:37 am

mob-i-l wrote:
PeterO wrote:Scratch can do what it likes, we're talking about C here.... Got the message yet ?
I don't agree with the message. I think one must take into account what the readers know before (e.g. Scratch) and the competition (e.g. Java, C++, or ARM-assembly). Maybe one also needs to add fork() to a beginners book on C, since Scratch-programs can have parallell processes, e.g. with clones in Scratch 2. If you don't explain fork() you can't easily translate all Scratch-programs to C.

One advantage with C is that it is useful on smaller systems e.g. Arduino, and that it can result in programs that use less electrical power.
IMO this discussion and all this nitpicking and arguing about trifles doesn't bring us much benefit, just unpleasant quarrels.
Hopefully there will be a follow-up tutorial, and even more important: who will be able and be willing to write it?
Maybe this discussion will even vanish into thin air if onece being published. :geek:

User avatar
PeterO
Posts: 5006
Joined: Sun Jul 22, 2012 4:14 pm

Re: The MagPi does C :-)

Tue Oct 18, 2016 11:49 am

mob-i-l wrote:
PeterO wrote:Scratch can do what it likes, we're talking about C here.... Got the message yet ?
I don't agree with the message.
The First book says "This series is an introduction to programming in C for absolute beginners;
you don’t need any previous programming experience, and a Raspberry Pi running
Raspbian is all you need to get started."

Keeping to that spirit, comparisons with YOUR favourite languages are irrelevant. The aim is to teach C, nothing more.

If you don't like what I'm trying to do, then feel free to try and organise something more to your liking.

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

ejolson
Posts: 3563
Joined: Tue Mar 18, 2014 11:47 am

Re: The MagPi does C :-)

Thu Oct 20, 2016 4:05 am

PeterO wrote:Rough idea of book structure : http://www.peteronion.org.uk/Cbook/CBookOutline.pdf
PeterO
While it is an interesting idea to write additional chapters, what I'd really like to do is make a few small changes to the existing book so it works better for my students. The book says

"Learn to Code with C is freely licensed under Creative Commons (BY-SA-NC 3.0)"

It also says

"It’s free and open source, so you should pick up a copy right now."

Are there easily modifiable source files, or should I use a pdf editor to make a derivative work?

User avatar
bensimmo
Posts: 4175
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: The MagPi does C :-)

Thu Oct 20, 2016 5:58 am

Given there is no 'learn to code in Python', only a book that jumps straight into making a game. A python one similar to this would be nice ;-)

But all that would be needed next for C is to mirror the basic examples on the website with C coding for the physical parts. Pupils would then learn by example and any 'topics' can spin-out at the time for detail information if it's needed or a link to somewhere for more info.
Once that has been done, do as they do for the other books and compile them into a 'MagPi issue'.

Some of you seem to be wanting to write a full on book :o
Keep it simple.
Learn by example.
The website has examples
Just repeat them.

User avatar
PeterO
Posts: 5006
Joined: Sun Jul 22, 2012 4:14 pm

Re: The MagPi does C :-)

Thu Oct 20, 2016 7:03 am

bensimmo wrote:Some of you seem to be wanting to write a full on book :o
:lol: I thought it was pretty obvious ! :roll:
Keep it simple.
Sadly not all problems or aspects of programming are simple ! And oftern begginers don't realise this when they ask questions for which there are no simple solutions.
Learn by example.
The website has examples
The URL would be helpful ! :roll:
Just repeat them.
I'm all for avoiding "reinventing the wheel", but just repeating existing ones is rather unimaginative !

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

User avatar
bensimmo
Posts: 4175
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: The MagPi does C :-)

Thu Oct 20, 2016 9:18 am

The website... (we are on the Raspberrypi.org website ;-) )

Repeat them ...
as in repeat the website example (wrt the website I am now typing on), that they already have in place, just do it for C.

I believe anyone can edit-ish and such like for the site, it just needs approval/some system for C setup (EDIT that should read copy and alter the github parts, no idea how they are published on the site if it's relevant)

Go through this, switch python for C https://www.raspberrypi.org/learning/ph ... worksheet/ for example.

The basics are done and they can follow the MagPi Essentials in a Pi styled magazine, now show them some uses on the website and then collate them, not more advance boring stuff as a reference book.
I can type 'Learn C' into google and I see many places that will show the advanced stuff.

tito-t
Posts: 298
Joined: Thu Jan 07, 2016 5:14 pm

Re: The MagPi does C :-)

Thu Oct 20, 2016 9:32 am

bensimmo wrote:The website... (we are on the Raspberrypi.org website ;-) )

Repeat them ...
as in repeat the website example (wrt the website I am now typing on), that they already have in place, just do it for C.

I believe anyone can edit-ish and such like for the site, it just needs approval/some system for C setup (EDIT that should read copy and alter the github parts, no idea how they are published on the site if it's relevant)

Go through this, switch python for C https://www.raspberrypi.org/learning/ph ... worksheet/ for example.

The basics are done and they can follow the MagPi Essentials in a Pi styled magazine, now show them some uses on the website and then collate them, not more advance boring stuff as a reference book.
I can type 'Learn C' into google and I see many places that will show the advanced stuff.
yes, I fully agree, this is exactly what I meant in my former posts
tito-t wrote:as people might wish to learn programming the PI with C (e.g., instead of Python, and perhaps also not just learning C in general, also for PCs and even domain servers and MCUs), and then using their own C programs on the Pi for proprietary tasks and applications (robots, weather stations, LED cubes, ambient lighting, IoT, home automization, gaming, multimedia), it's perhaps a good advice to focus on how to use GPIO pins, input, output, serial communication and Wifi to achieve a practical goal, not to flog the detailed C functions and syntax until to aversion.
tito-t wrote:yes, provide practical C programming tools, for application-oriented programming, step by step (...).
in principle, not much different from what is written in the Raspi Python tutorials, but now using C code instead.
Porting the Python code to C and then explaining what it's about, that would be practical learning C by doing, and addtionally then providing background knowledge for C "internals".
- Tim

User avatar
PeterO
Posts: 5006
Joined: Sun Jul 22, 2012 4:14 pm

Re: The MagPi does C :-)

Thu Oct 20, 2016 9:57 am

bensimmo wrote:The website... (we are on the Raspberrypi.org website ;-) )
No, we are on the Forums, not the web site....

Repeat them ...
as in repeat the website example (wrt the website I am now typing on), that they already have in place, just do it for C.

I believe anyone can edit-ish and such like for the site, it just needs approval/some system for C setup (EDIT that should read copy and alter the github parts, no idea how they are published on the site if it's relevant)

Go through this, switch python for C https://www.raspberrypi.org/learning/ph ... worksheet/ for example.

The basics are done and they can follow the MagPi Essentials in a Pi styled magazine, now show them some uses on the website and then collate them, not more advance boring stuff as a reference book.
I can type 'Learn C' into google and I see many places that will show the advanced stuff.
Sorry, but that's not what I'm interested in doing....

Those examples are very simple. If all you want to do is flash a led, then Python is a perfectly good language to use. If someone is going to the trouble of learning C (which is undeniably harder than Python to learn as a first language)
then I think any examples used should try to show the kinds of things where C would be a better choice than Python.

But feel free to do it yourself.

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

Stiller
Posts: 206
Joined: Fri Oct 14, 2016 9:03 am

Re: The MagPi does C :-)

Thu Oct 20, 2016 10:29 am

PeterO wrote: Those examples are very simple. If all you want to do is flash a led, then Python is a perfectly good language to use. If someone is going to the trouble of learning C (which is undeniably harder than Python to learn as a first language)
then I think any examples used should try to show the kinds of things where C would be a better choice than Python.
But feel free to do it yourself.
PeterO
I have to disagree completely.
1st, this discussion is more about a general approach to teach C programming for the Pi.
2nd, no one wrote that YOU have to write a C tutorial following the one from MagPi.
3rd, starting with GPIO control to flash a LED or to read a button press would not mean to stay at that level, what do you think ?!?
But for a more advanced Pi programming one will have to learn the essentials, not only about the basic C syntax, but also for the basic GPIO control, and then proceed further and further, from quite simple to more and more advanced.

I already pointed out to that sort of practical approach when I stated
Stiller wrote:... I also agree that for newbies to C and the Pi practical projects similar as shown in Python tutorials should have 1st priority (leastways for reasons of motivation) and so I would appreciate a application-oriented curriculum like mentioned
C for GPIOs
C for UART, i2c and SPI (edit, added: USB)
C for HATs
C for graphics
C for the Pi Cam (edit, or a USB cam)
C for audio
C for game programming
perhaps for some applications (e.g., game programming ?) also a future C++ tutorial might be taken into account... :geek:

User avatar
PeterO
Posts: 5006
Joined: Sun Jul 22, 2012 4:14 pm

Re: The MagPi does C :-)

Thu Oct 20, 2016 10:45 am

Stiller wrote:I have to disagree completely.
That's fine, but I don't see anyone else actually trying to do anything constructive .....
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

Stiller
Posts: 206
Joined: Fri Oct 14, 2016 9:03 am

Re: The MagPi does C :-)

Thu Oct 20, 2016 10:53 am

if some one is doing some work for a target group he will be well adviced to ask the target group what would be wishful - and listen very carefully to the replies.
Otherwise it might probably happen that a lot of work has been done but no one actually reads it and cares about it.

tito-t
Posts: 298
Joined: Thu Jan 07, 2016 5:14 pm

Re: The MagPi does C :-)

Thu Oct 20, 2016 10:57 am

Stiller wrote:if some one is doing some work for a target group he will be well adviced to ask the target group what would be wishful - and listen very carefully to the replies.
Otherwise it might probably happen that a lot of work has been done but no one actually reads it and cares about it.
I fully agree.

+1 to this post:
Stiller wrote: 1st, this discussion is more about a general approach to teach C programming for the Pi.
2nd, no one wrote that YOU have to write a C tutorial following the one from MagPi.
3rd, starting with GPIO control to flash a LED or to read a button press would not mean to stay at that level, what do you think ?!?
But for a more advanced Pi programming one will have to learn the essentials, not only about the basic C syntax, but also for the basic GPIO control, and then proceed further and further, from quite simple to more and more advanced.
Last edited by tito-t on Thu Oct 20, 2016 11:07 am, edited 1 time in total.
- Tim

User avatar
bensimmo
Posts: 4175
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: The MagPi does C :-)

Thu Oct 20, 2016 11:06 am

I wasn't talking about what you wanted, but what may be a way for RaspberryPI Foundation/MagPi to go.
Do what you want, I'm not stopping you and I don't think anyone else here is.

This forum is on the RaspberryPI website, says so up at the top, it's all one place.
If I go to London, I'm still in England.

User avatar
PeterO
Posts: 5006
Joined: Sun Jul 22, 2012 4:14 pm

Re: The MagPi does C :-)

Thu Oct 20, 2016 11:14 am

Stiller wrote:if some one is doing some work for a target group he will be well adviced to ask the target group what would be wishful.
Except that you are not the target group.
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

Stiller
Posts: 206
Joined: Fri Oct 14, 2016 9:03 am

Re: The MagPi does C :-)

Thu Oct 20, 2016 11:18 am

what an utter nonsense!
But do what you want, I agree to bensimmo
I wasn't talking about what you wanted, but what may be a way for RaspberryPI Foundation/MagPi to go.
Do what you want, I'm not stopping you and I don't think anyone else here is.

texy
Forum Moderator
Forum Moderator
Posts: 5157
Joined: Sat Mar 03, 2012 10:59 am
Location: Berkshire, England

Re: The MagPi does C :-)

Thu Oct 20, 2016 12:27 pm

Good - so any more bickering and the thread will be locked, which would be a shame :roll:
Various male/female 40- and 26-way GPIO header for sale here ( IDEAL FOR YOUR PiZero ):
https://www.raspberrypi.org/forums/viewtopic.php?f=93&t=147682#p971555

tito-t
Posts: 298
Joined: Thu Jan 07, 2016 5:14 pm

Re: The MagPi does C :-)

Sun Oct 23, 2016 2:39 pm

here is another topic which shows very clearly, what newbies to C and the Pi really wish to learn:
again GPIO control and cam control by C commands
viewtopic.php?f=33&t=163416
And again Python tutorials with functioning applications (also perhaps using 3rd party libs) are available, and again similar tutorials in C are missing.

Exactly my point, as I stated above about the next wishful steps for learning C to become able to program the Pi:
C for GPIOs
C for UART, i2c and SPI
C for HATs
C for graphics
C for the Pi Cam
C for audio
C for game programming

as people might wish to learn programming the PI with C (e.g., instead of Python, and perhaps also not just learning C in general, also for PCs and even domain servers and MCUs), and then using their own C programs on the Pi for proprietary tasks and applications (robots, weather stations, LED cubes, ambient lighting, IoT, home automization, gaming, multimedia), it's perhaps a good advice to focus on how to use GPIO pins, input, output, serial communication and Wifi to achieve a practical goal, not to flog the detailed C functions and syntax until to aversion.
(by wiringPi already a lot of it is admittedly availble for GPIOs)
- Tim

tito-t
Posts: 298
Joined: Thu Jan 07, 2016 5:14 pm

Re: The MagPi does C :-)

Sun Oct 30, 2016 8:14 pm

another good example about what beginners would wish to know about C/C++ programming for the Pi:

viewtopic.php?f=33&t=164189

As you may may observe, many Raspi newbies are already a little experienced in C/C++ for Arduino (i.e., at least with the very C/C++ basics), so making them/us able to program the Pi accordingly (i.e., the GPIOs, the serial and i2c and SPI communication to external devices...) and upgrade them/us from Arduino-ish to "real C"...:

that would be a big leap for the Pi-C-beginner community !
- Tim

Stiller
Posts: 206
Joined: Fri Oct 14, 2016 9:03 am

Re: The MagPi does C :-)

Thu Nov 03, 2016 12:54 pm

I fully agree!

and here's another one:

things that newbees need to know about C, the Pi, and everything:

viewtopic.php?f=33&t=164678

Return to “C/C++”