Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

A picture book written in C code

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Everyone!

I'm in the process of writing an educational/fun coding book in the form of a picture book. The code (simple full C programs) represents situations in the story and the illustrations next to the code show the situations. It's called *A Day in Code* and I'm planning to launch it on Kickstarter.
This is my landing page: https://www.dayincode.com
I also have a Kickstarter pre-launch page: https://www.kickstarter.com/projects/914595512/a-day-in-code

Would you be interested in this book? I'd be happy to hear any feedback. Thank you!
 
Marshal
Posts: 69035
275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch I shall add your post to our C forum

That is a novel idea Unfortunately the page you showed includes code constructs I warn against frequently, == open. I think (not sure) that such use of the == operator is worse in C than in Java┬«.
 
S Esken
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for the delayed response, I missed the notification. Thank you for the comment! What do you see as wrong with " == open " ? I've never heard that before...
 
Campbell Ritchie
Marshal
Posts: 69035
275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is unnecessary; you can simply write if (cupcakeBox) ...
It is error‑prone if you write if (cupcakeBox = open) ...
In fact some people recommend to reverse the order of the operands if (open == cupcakeBox) ... That reads awkwardly, but is not error‑prone.
Your code there also lack any action for closing the box:-Of course, think how nicely the code would read if you renamed the variables to boxIsOpen or similar
 
S Esken
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wanted to make the code more readable for beginners, as well as teaching the #define directive. I understand your point about making the code optimal and I know if(cupcakeBox) is the same as if(cupcakeBox == 1), but the latter option, in this case, if(cupcakeBox == open), translates into English better Thanks for pointing it out.

I just understood your other point...this code is a representation of a situation at a single point in time, so the seagulls aren't eating forever...
 
Campbell Ritchie
Marshal
Posts: 69035
275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unfortunately here it seems that showing the #define construct and robust code conflict with each other. Just as seagulls are a conflict. Not far from here, you can see notices prohibiting people from feeding gulls otherwise they become habituated to human food (as opposed to the slimy invertebrates or stunned fish they naturally eat) and become positively aggressive towards people.
 
S Esken
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So it also teaches an important life lesson- don't leave your food unattended at the beach.
 
Campbell Ritchie
Marshal
Posts: 69035
275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, this shows what can happen.
 
Rancher
Posts: 276
VI Editor C++ Debian
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I realize I am responding two weeks after your original post.

First of all, kudos on the concept!  Is this original?  For sure, I have not come across an earlier attempt to come up with a picture book for a programming language.  Brilliant concept.

I have some comments on the code:

  • Do NOT define true or false!  Absolute No-No.
  • Prefer C to preprocessor.  open and close could be variables of type const int (in C they are not strictly equivalent to their #define counterparts, but in this case, those differences do not matter).
  • Avoid global variables.  These could just as well be moved within main()
  • String literal input to printf should have a newline


  • best,
     
    S Esken
    Greenhorn
    Posts: 5
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thank you, yes it is an original concept! I know there's many different ways the program can be written...some decisions were made for the sake of clarity. There's no newline in the printf function because there's no subsequent printed text in this program. I wanted to teach the define directive and show that true and false are defined as binary values. I'll also be teaching global and local variables.
     
    Campbell Ritchie
    Marshal
    Posts: 69035
    275
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I hope you will be teaching how error‑prone global variables can be.
     
      Bookmark Topic Watch Topic
    • New Topic