A picture book written in C code
-
Hey everyone, I’m writing a unique programming book…it's called A Day in Code and it's a picture book written in C code! The code consists of simple C programs that represent situations in the story. The illustrations next to the code show the situations. The code is also explained below each program.
I launched it on Kickstarter a few weeks ago:
https://www.kickstarter.com/projects/914595512/a-day-in-code
I’d love to hear your feedback!
-
@Byte9 is it like Necronomicon? It's not proper C code if it doesn't look like Necronomicon.
-
@Gąska said in A picture book written in C code:
Necronomicon
I have no idea what that is! An online search doesn't really help...
-
The Necronomicon, also referred to as the Book of the Dead, or under a purported original Arabic title of Kitab al-Azif, is a fictional grimoire (textbook of magic) appearing in stories by the horror writer H. P. Lovecraft and his followers.
The book was originally called Al Azif, an Arabic word that Lovecraft defined as "that nocturnal sound (made by insects) supposed to be the howling of demons", drawing on a footnote by Samuel Henley in Henley's translation of "Vathek". Henley, commenting upon a passage which he translated as "those nocturnal insects which presage evil", alluded to the diabolic legend of Beelzebub, "Lord of the Flies" and to Psalm 91:5, which in some 16th Century English Bibles (such as Myles Coverdale's 1535 translation) describes "bugges by night" where later translations render "terror by night". One Arabic/English dictionary translates 'Azīf' (عزيف) as "whistling (of the wind); weird sound or noise". Gabriel Oussani defined it as "the eerie sound of the jinn in the wilderness". The tradition of 'azif al jinn' (عزيف الجن) is linked to the phenomenon of "singing sand".
-
@Gąska I was hoping that wasn't what you were referring to...lol I don't see the connection.
-
@Byte9 also, I categorically disagree with the statement in the trailer at timestamp 0:56-1:00. No, knowing C is rarely ever useful, and certainly it doesn't make you any better at more modern languages based on C - if anything, it makes you worse, so suggesting people should learn C first is actively harmful.
But as a funny reading and not educational material - it's passable choice, although I'd really rather if another language was used. If only because of all this enormous boilerplate require in every function that does anything remotely interesting. Although since this is not real code (as in, not designed to be actually run), it might not be that bad in the end.
I like the idea very much, though! I'm always on lookout for programming books that aren't about teaching you something, but rather just for fun. It's really weird how few of these there are. So far I only found 2 - "Beautiful Code" (highly recommend, but it's for advanced programmers) and "How NOT to program in C++" (couldn't find it anywhere in the past so didn't read, but it seems there's easily googleable PDF now).
-
@Byte9 said in A picture book written in C code:
@Gąska I was hoping that wasn't what you were referring to...lol I don't see the connection.
C being the programming language of dark magics, perhaps?
-
@Tsaukpaetra Just trolling, apparently.
-
@Byte9 welcome to the forum!
-
@Tsaukpaetra said in A picture book written in C code:
@Byte9 said in A picture book written in C code:
@Gąska I was hoping that wasn't what you were referring to...lol I don't see the connection.
C being the programming language of dark magics, perhaps?
As one whose career has involved direct access to obscure hardware registers, almost always in C essentially unchanged, except for syntatctic sugar, from the 1980s, yes.
-
@Tsaukpaetra (cf. The Laundry Files)
-
@Gąska said in A picture book written in C code:
knowing C is rarely ever useful
And something I've made most of my career out of. As with so much in this industry, it really depends on what you're doing.
I tend to define C as the first sane stop above Assembler.
-
@dkf said in A picture book written in C code:
I tend to define C as the first sane stop above Assembler.
Hmmm, IDK... When I were a nipper, assemblers cost serious money (not to mention poor availability for the platform in my location), so if you wanted to go beyond what BASIC was capable of, you had to READ in a bunch of DATA statements and BSAVE 'em like a man.
Sigh... those were better days...
-
@GOG said in A picture book written in C code:
When I were a nipper, assemblers cost serious money
I wrote my own. It was terrible, but it worked.
-
Also don't think that C is an ideal choice for a beginners book, but that's not very constructive criticism because it seems too late to change that. I like the idea overall. Hope you'll be successful with it.
-
@topspin Did you see my "// Why C Programming?" section? One particular application for beginners is the Arduino, a popular platform for kids and students.
-
@Byte9 said in A picture book written in C code:
@topspin Did you see my "// Why C Programming?" section? One particular application for beginners is the Arduino, a popular platform for kids and students.
That's a good point.
-
@topspin said in A picture book written in C code:
That's a good point.
You're on the wrong forum. We don't tolerate that kind of language here.
-
@Vault_Dweller said in A picture book written in C code:
We don't tolerate that kind of language here.
You mean C?
But in all honesty. Yeah, I guess I was a little too harsh. As I said, it doesn't really matter what language the book is in. I'm just a bit annoyed at this brain worm of "we need to teach our kids the ways of the 80s on which the rest of the IT world was built upon". I see it all the time and it's not really helpful for making next generations either understand or like programming. However, I understand the reasoning that Arduino etc. are great "gateway drugs" for children to pick up programming, and that they all use C - although I see it as a serious issue that greatly hinders their educational capabilities for no good reason. As in, Arduino would be even better for kids if it also supported a more user-friendly language.
I think I'm going to buy the book for my younger sister either way. I just hope the pictures are nice and code snippets aren't all trivial. I want at least a few jokes of the https://xkcd.com/1188/ kind!
-
@Gąska said in A picture book written in C code:
I'm just a bit annoyed at this brain worm of "we need to teach our kids the ways of the
870s on which the rest of the IT world was built upon".
-
@Gąska The book teaches fundamental programming concepts like for loops, while loops, if/else statements, arrays, structures, functions, etc. The one topic in C programming that it won't include is pointers. Even though C was first introduced in the 70s, it's still widely used today for new applications. It allows you to write high-level code and also allows you to do low-level manipulation of bits in hardware registers. C is efficient- I have read that Python programs generally run an order of magnitude slower than C programs.
-
@Gąska said in A picture book written in C code:
However, I understand the reasoning that Arduino etc. are great "gateway drugs" for children to pick up programming, and that they all use C - although I see it as a serious issue that greatly hinders their educational capabilities for no good reason. As in, Arduino would be even better for kids if it also supported a more user-friendly language.
I think I agree. The biggest feature missing from typical C implementations is a way of having people use the language interactively, i.e., a REPL. Nothing demystifies a computer more thoroughly than being able to see it immediately do what you tell it to. Fitting such a language onto an Arduino might be a bit tricky, but a small Pi is very capable of hosting that sort of thing.
I have seen interactive C implementations. They were… strange…
-
@dkf Each program in the book has a printf() function that outputs text/values to the screen. You can play with the code and change values, so it's interactive and you can see how the logic works.
-
@dkf said in A picture book written in C code:
@Gąska said in A picture book written in C code:
However, I understand the reasoning that Arduino etc. are great "gateway drugs" for children to pick up programming, and that they all use C - although I see it as a serious issue that greatly hinders their educational capabilities for no good reason. As in, Arduino would be even better for kids if it also supported a more user-friendly language.
I think I agree. The biggest feature missing from typical C implementations is a way of having people use the language interactively, i.e., a REPL. Nothing demystifies a computer more thoroughly than being able to see it immediately do what you tell it to. Fitting such a language onto an Arduino might be a bit tricky, but a small Pi is very capable of hosting that sort of thing.
That might be part of the reason why C programmers like print-based debugging so much.
-
@Byte9 said in A picture book written in C code:
I have read that Python programs generally run an order of magnitude slower than C programs.
It's often slower even than that unless you use something like Numpy. (Numpy is very cleverly written, but seriously brain-bending at times and very much not something to start kids on.) The core inefficiencies come from the poor threading implementation (a Python-specific problem), branch misprediction problems (a common issue across all languages implemented using bytecode interpreters), and value boxing. The last one is by far the dominant factor in single threaded code; it can quite easily cause performance degradation in excess of 15-30 times. (Yes, I've measured that. I've got an experimental compiler for a different dynamic language that fixes that, but that's absolutely research grade code at this point. Also, I'm not sure how it would even translate to Python as the type system is critically different.)
-
@PleegWat said in A picture book written in C code:
That might be part of the reason why C programmers like print-based debugging so much.
I like printf-based debugging, but that's often because I'm running code in weird configurations where attaching a standard debugger is difficult or outright impossible.
-
@Gąska To be , Arduinos are programmed in C++.
Although most (all?) of the standard libraries are missing, which makes knowing the memory management stuff quite useful...
-
@frillunflop This is a question on the FAQ of the Arduino site:
"Can I program the Arduino board in C?
In fact, you already are; the Arduino language is merely a set of C/C++ functions that can be called from your code."The libraries are already written. You program the Arduino with C syntax and constructs.
-
@dkf said in A picture book written in C code:
It's often slower even than that unless you use something like Numpy. (Numpy is very cleverly written, but seriously brain-bending at times and very much not something to start kids on.)
I tried to use Numpy once. I failed.
I had a personal project. The project needed a library. The library needed Numpy. For some reason I never figured out, I couldn't simply install Numpy; I had to compile it from source. Compilation failed with errors. I decided I didn't need to do the project.
-
@HardwareGeek said in A picture book written in C code:
@dkf said in A picture book written in C code:
It's often slower even than that unless you use something like Numpy. (Numpy is very cleverly written, but seriously brain-bending at times and very much not something to start kids on.)
I tried to use Numpy once. I failed.
I had a personal project. The project needed a library. The library needed Numpy. For some reason I never figured out, I couldn't simply install Numpy; I had to compile it from source. Compilation failed with errors. I decided I didn't need to do the project.
Using it is really simple and elegant IMO.
Installing it... well, better use the package manager.
-
@topspin said in A picture book written in C code:
@HardwareGeek said in A picture book written in C code:
@dkf said in A picture book written in C code:
It's often slower even than that unless you use something like Numpy. (Numpy is very cleverly written, but seriously brain-bending at times and very much not something to start kids on.)
I tried to use Numpy once. I failed.
I had a personal project. The project needed a library. The library needed Numpy. For some reason I never figured out, I couldn't simply install Numpy; I had to compile it from source. Compilation failed with errors. I decided I didn't need to do the project.
Using it is really simple and elegant IMO.
Installing it... well, better use the package manager.
And hope you have the right math libraries installed. That was the sticking point for me at first--it was real particular about versions of the Intel MKL (I think?) library. That was the piece that wanted to be compiled from scratch.
-
@topspin I'm pretty sure I just used pip, but it failed with some message about building from source. I don't remember; that was a couple of years ago. Someday I'll have to revisit it, because I really do need the utility I was trying to write, eventually.
Edit: @Benjamin-Hall That sounds like it may be what I ran into, too.
-
@HardwareGeek said in A picture book written in C code:
@topspin I'm pretty sure I just used pip, but it failed with some message about building from source. I don't remember; that was a couple of years ago. Someday I'll have to revisit it, because I really do need the utility I was trying to write, eventually.
Edit: @Benjamin-Hall That sounds like it may be what I ran into, too.
It's been years (about 13, in fact) since I've installed numpy. Hopefully they've gotten better about it since then.
-
@Benjamin-Hall I just download anaconda with all of scipy and that works.
-
@Byte9 said in A picture book written in C code:
C is efficient- I have read that Python programs generally run an order of magnitude slower than C programs.
Not to dive into the debate toooooo much, but...
"That doesn't matter when the lowest-spec modern computer is multiple orders of magnitude more powerful than required for most programs"
Also
"Efficiency doesn't matter when a single mistake could crash your PC - or worse, get it pwned"
(also screw Python. C#/.Net though...)
-
@sloosecannon Book looks cool though
-
@HardwareGeek said in A picture book written in C code:
@dkf said in A picture book written in C code:
It's often slower even than that unless you use something like Numpy. (Numpy is very cleverly written, but seriously brain-bending at times and very much not something to start kids on.)
I tried to use Numpy once. I failed.
I had a personal project. The project needed a library. The library needed Numpy. For some reason I never figured out, I couldn't simply install Numpy; I had to compile it from source. Compilation failed with errors. I decided I didn't need to do the project.
Numpy used to be a really big pain to build. It now isn't so much, as there are pre-built versions available for download for all significant platforms and it doesn't actually need to be made a part of your base Python. It's one heck of a lot simpler that way. This was a change a few years ago. (OTOH, matplotlib continues to be annoying on some platforms; the problem is that the underlying GUI libraries are highly finicky in some types of deployment.)
My complaints with numpy usually stem from the way it has all sorts of ways to rearrange and compute with data that all end up being confusing as heck as soon as you Save the file you're working on. It's almost like writing regular expressions in Perl…
-
@HardwareGeek https://www.ashisoft.com/duplicate-photo-finder.htm I've used this before. It doesn't seem to fry my computer with a few gigs of images.
-
@Gąska https://pycom.io/webshop/ might interest you then. Or well, not you... But you can throw a few boards in the general direction of the people you don't want to learn C first.
-
@Carnage for a second I thought you're throwing some fun non-educational programming books at me. Bummer :(
-
@Gąska said in A picture book written in C code:
@Carnage for a second I thought you're throwing some fun non-educational programming books at me. Bummer :(
Yeah, wish I could help you out there.
I might actually have one or two down in storage. I know I used to have something with programming language jokes in it, and other esoteric jokes related to IT. I might still have it, or someone borrowed it a decade ago or so and never returned it.
I might have to go dig through my books for it but
-
@coderpatsy That looks like just what I need. I don't know why I didn't find it a couple of years ago, or maybe I did but decided it's not suitable for some reason I don't remember. In any case, thanks.
-
@HardwareGeek said in A picture book written in C code:
the utility I was trying to write
Did you roll your own perceptual hash algo? I got disappointed with different programs giving false positives vs too many misses, esp. on cropped and mirrored, so I considered putting several sorts of phashes from nuget in one place and weigh their outputs... before the usual factors of Phacochoerus africanus were considered, of course.
-
@Applied-Mediocrity said in A picture book written in C code:
Did you roll your own perceptual hash algo?
Heck, no. I have absolutely no domain knowledge for that. I found what seemed to be a good one, at least from the description, and started to write a wrapper to pass images into it, but ran into the problems described above, and then was attacked by the wild .
Edit: Also, for my purposes, I don't consider false positives a big problem, as long as it reduces the number of images I have to compare visually from a couple of thousand to, say, 3 or 4, or even 10. My main use case is, I grab a stack of photos and scan one. Have I already scanned it? If so, I've already scanned the stack and don't need to scan the rest of them again.
-
@sloosecannon said in A picture book written in C code:
"That doesn't matter when the lowest-spec modern computer is multiple orders of magnitude more powerful than required for most programs"
That's really not true. Wirth's Law applies here.
-
@sloosecannon Python is slow for embedded systems/microcontrollers, and also has higher energy consumption!
-
@Byte9 neither of which is really a concern when learning. And I think "slow" already implies "higher energy consumption", am I wrong? (Honest question.)
Also, I have a question about how you make the book (or will be making, dunno what stage you're at). When making code that matches a picture, do you come up with the code or the picture first? Like, do you already know what the code will contain before you know what the picture will contain, or the other way around, or both?
-
@Byte9 True, you can write pure C, but the libraries are written in C++.
So you cannot really avoid using at least some features of C++:
Serial.print
calls an overloaded method, something that does not exist in pure C.
-
@Byte9 said in A picture book written in C code:
@sloosecannon Python is slow for embedded systems/microcontrollers, and also has higher energy consumption!
Well sure, but that doesn't matter unless you're @dkf
-
@Gąska Here's an interesting study that shows "a faster language is not always the most energy efficient." [https://thenewstack.io/which-programming-languages-use-the-least-electricity](link url). My point was that C programming is still the standard for embedded systems and is useful for beginners programming the Arduino. As for my book on Kickstarter, I've written all the code and I will be completing the illustrations with an artist.