Day 62: Reading Books on Coding Helps

I started reading up a bit more on the C programming language to help me implement my pretty print function for tree data structures. I know, a mouthful… Anyways it has been really cool. The book I started reading has been on my reading list for a while and although I am speed reading it I am still slowing down and picking up a lot when I see something relevant. The one thing I am realizing about technical books is that there are highs and lows in each of them. Reading at the same pace I read fiction would take me ten times longer than needed. Plus repetition is key in my opinion. It’s better to get the exposure first and than fill in the gaps as you go. Although, that approach is kind of what got me in this predicament in the first place.

TLDR;

Okay, so here are the highlights of what I did:

  • Continued to work on the “Technical Questions” section of the book “Cracking the Coding Interview” by Gayle Laakmann McDowell. Within that, I continued my work on Tree data structures. Started trying to replicate the example pretty print functions provided in the article I am reading through. I had to pause working on my Horizontal Pretty Print project to better understand string/character manipulation in the C programming language. It is a bit of a detour but I imagine it will pay itself off in the long run. Starting reading the C programming book called “The C Programming Language” by Brian W. Kernighan and Dennis M. Ritchie. I read through chapter 1 and only picked up some cool formatting points for the printf function from the standard library. I expect tomorrow to be a more productive day.
  • I read through the rest of chapter 5 of the book “Eloquent JavaScript” by Marjin Haverbeke. I am starting to read the book to help cover some insecurities I have about my knowledge of the language. I learned JavaScript on the fly through projects and YouTube videos. There are some core questions about the language that I don’t think I can answer, so hopefully this will help. The example code was really interesting. The layering was at the level of some projects I have worked on and it took me a few reads to breakdown. I definitely think I should come back to some of the exercises in Chapter 5. I made a section in my notes so that I can write out my solutions in an organized manner that I can come back to.

printf() Function notes

This function is from the standard library that comes available with C and allows us to print out strings (character arrays) to the console. It also allows us to format that data and substitute variable values instead of hard coding all elements of the output. Here are some of the special codes used to represent substitutions for certain data types:

  • %c = substitute a character value.
  • %s = substitute a string (a.k.a. char array) value.
  • %d = substitute a signed integer value.
  • %f = substitute a float value.
  • %e or %E = substitute a scientific notation of a float value.
  • %g or %G = substitute a scientific notation of a float value.
  • %hi = substitute a signed integer value (short).
  • %hu = substitute a unsigned integer value (short).
  • %i = substitute a unsigned integer value.
  • %u = substitute a unsigned integer value.
  • %l or %ld or %li = substitute a long value.
  • %lf = substitute a double value.
  • %Lf = substitute a Long double value.
  • %lu = substitute a unsigned int or unsigned long value.
  • %llu = substitute a unsigned unsigned long long value.
  • %lli or %lld = substitute a long long value.
  • %o = substitute a octal representation value.
  • %x or X = substitute a Hexadecimal representation value.
  • %p = substitute a pointer value.
  • %n = substitute a prints nothing value.
  • %% = substitute a ‘%’ character.

We can also add spacing formatting by including a number after the % and before the desired character code. For example %3d will produce right aligned numbers who occupy 3 character spaces and %3.0 will produce right aligned floating point numbers who occupy 3 character spaces and have zero digits after the decimal place.

printf("%3d %6d\n", fahrenheit, celsius);
// ->   0    -17
// ->  20     -7
// -> 100     37

printf("%3.0f %6.1f\n", fahrenheit, celsius);
// ->   0  -17.8
// ->  20   -6.7
// -> 100    4.4

Width and precision may be controlled with printf syntax:

  • %6f = at least 6 character wide floating point number and no restriction on digits after the decimal place
  • %.2f = Any number of characters wide floating point number but only 2 digits after the decimal place.

Conclusion

That’s all for today. This is my sixth round of the “#100daysofcode” challenge. I will be continuing my work from round five into round six. I am currently working through the book “Cracking the Coding Interview” by Gayle Laakmann McDowell. My goal is to become more familiar with algorithms and data structures. This goal was derived from my goal to better understand operating systems and key programs that I use in the terminal regularly e.g. Git. This goal was in term derived from my desire to better understand the fundamental tools used for coding outside of popular GUIs. This in turn was derived from my desire to be a better back-end developer.

I have no idea if my path is correct but I am walking down this road anyways. Worst case scenario I learn a whole bunch of stuff that will help me out on my own personal projects.