Friday, November 22, 2013

K&R C SE Lesson 1: Introducing K & R C Programming SE

(Post Under Construction)
 Kernighan and Ritchie "The C Programming Language" Second Edition is an classic interpretation of the C language in the same way as Strunk and White "Elements of Style" is a classic interpretation of the English language or Wolfgang Pauli's lecture on "Wave Mechanics" is a classic representation of the math of physics. This does not mean that all of the programming in K&R C is useful today or even the best representation of the use of C (1, 2).  A paraphrased statement of Pauli's famous belief about untestable physics applies to engineering software as well: If your code can't be proven wrong by someone, you have probably not produced anything of much value. 

Software engineering languages have variability, flexibility and polymorphism  by design  There are always multiple solutions to any given problem. Without honoring this fundamental nature of exploratory science; the power and endurance of any one language is limited. There are a number of  K&R solution sets provided on the web. Below is a selection of solutions to  the Fahrenheit-Celsius converter code discussed in Chapter 1 of  "The C Programming Language" as provided by Richard Heathfield.   A C language reference is available from the GNU Project. It is particularly important to read the while and do statement sections. A number of third party GNU C tutorials are also available. Use the google search term: 'filetype:PDF gnu c programming tutorial'. Learning GNU C is one such.

This post is primarily about understanding the logic and control structures of C. The implementation of C library functions (e.g. printf) are left for another discussion. -RMF

Thursday, November 21, 2013

K&R C SE Lesson 2: Introducing printf, the 'for loop', and gdb

(Post Under Construction)
This post uses an example from the first chapter of  K&R C Programming Second Edition. After discussing the use of the printf function, K&R C SE demonstrates alternate code for printing a Fahrenheit-Celsius conversion table. The specific and compact use of printf arguments allows for the appropriate formatting of the results returned by a compact conversion routine inside of a for loop. This code is more compact and more accurate than the first example in Lesson 1 using the while loop:

#include <stdio.h>
/* print Fahrenheit-Celsius table */
int fahr;
for (fahr = 0; fahr <= 300; fahr = fahr + 20)
        printf("%3d %6.1f\n", fahr, (5.0/9.0) * (fahr-32));

Tuesday, November 12, 2013

XCode, Text Editors, Peanut Butter

I want to wish a big thank you for the guest lecture from software engineer and WWU statistics instructor Brian Morgans who taught a fascinating class on program instruction debugging; all with a loaf of bread, some peanut butter and a knife! I think the students had a great time!  In conclusion, Brian talked about sorting algorithms which are an excellent introduction to developing algorithms in programming.  I recommend the Wikipedia article and links on sorting algorithms. For a fun (but noisy) visualization of sorting algorithms, see here.

We will meet again in the first two weeks of December. I have installed Xcode 3.0 on many of the MACs in the lab and will soon install the entire lab. This allows you to use the gcc and g++ commands from your bash prompt. There will be a graphical interface to XCode 3.0. More on that later. In using the Xcode installation, there may be path issues for libraries you need to address. Read The Fine Manual and e-mail me any questions. The GNU gcc and g++ manuals are here.

Tuesday, October 15, 2013

Resources and Text for the Class

Although there are no mandatory assignments for this course, learning to programming is no different than any other skill. The more research and practice the student puts into the subject, the more he will learn. Programming requires practices and research to master as a skill. My lectures are simply not enough.

I have stored texts that could be useful  to this class on my google drive and shared them publicly.  I will add to the folders as the course continues: C_Programming C++ Shell Programming UNIX_Administration

For C Programming, we will be using the  Kernighan and Ritchie classic "C Programming" Second Edition. The ISO C Standard has been updated to C11. A previous draft of that standard ('n1570')  is available for free. Both documents are available as PDFs  in the C_Programming folder. For UNIX Administration, I found a PDF copy of the classic Evi Nemeth work "UNIX Administration".  It can be found in the UNIX_Administration folder .  Other PDFs on Shell Programming are available. I recommend reading all three of these works for this class. Evi Nemeth's work is particularly good background.

Additional reference manuals on C Programming can be found in the C_Programming  folder. The GNU C reference manual is particularly appropriate when you simply need to look up a reference on how a keyword or operator is used . Two wikibooks on C are also helpful:

Friday, October 11, 2013

Starting x11 and the BASH shell

"Any sufficiently advanced technology is indistinguishable from magic."
 William C. Clarke 
This blog post provides further information about the use of the xll terminal as demonstrated through Cygwin's Xll emulation program running on Windows 7 for SPA Computer club students. The second half of the post provides information generic to BASH shell first use.  These instructions are brief and are designed for 5th - 10th graders first using x11.  The use of a full featured UNIX shell is intimidating to everyone new to that shell. Use reason and patience and take a break if you find yourself confused. The good news is that learning a shell programming language is the gateway to understanding all computer management and development interfaces. You can email me or google chat me if you need help. Come as early to class to as possible next week if you feel stumped.

Wednesday, October 9, 2013

Class 1: October 8th 2013 : Introduction and Introduction to UNIX Administration

Class dates planned:
  • Oct 8, 15 (both Tuesdays)
  • Nov 5, 12 (both Tuesdays)
  • Dec 3, 10 (both Tuesdays)
  •  Jan 7 (Tues)
  • Jan 28 , Feb 4 (both Tues)
  • Feb 25 , Mar4 (both Tues)
  • Mar 25, (Tues)
  • Apr 22, 29 (both Tues)
  • May 20, 27 (bothTues)

Friday, May 17, 2013

Network Administration for JavaScript Programmers (Part I)


There is no easy path to understanding TCP/IP network communication.  Experienced system programmers spend hours each year tuning and improving the basic communication protocols that connect the internet. IT administrators spend thousands of hours configuring hosts, servers, switches, routers, and optimizing network architecture to  maximize network throughput. Many of us who simply use applications and programming languages don't dig to deeply into these areas.  However, TCP/IP communication makes everything work. Without imbibing some understanding and network troubleshooting techniques, your career as a JavaScript programmer will suffer frustration. As a programmer or IT administrator, you really can't get TCP/IP network administration without using administrative commands from the shell. Graphical suites that help troubleshoot network connectivity are not always available and sometimes they provide more information than needed. The official internet STDs and RFCs represent an authoritative starting point for greater understanding of TCP/IP; but the internet is awash in tutorials on these subjects. I recommend finding something authoritative.

JavaScript  provides functionality to web clients. This makes some network administration and process management skillsets important.  The instructions in this post will be abbreviated. The reader is recommended to additional sources of information for more detail.  My examples use either OpenBSD 5.2. or Cygwin running on Windows 7. OpenBSD is a free UNIX that is secure and easy to install. Cygwin is a free UNIX emulation terminal that includes many but not all UNIX network commands.  As you read this, think about how the commands below might help you test and deploy your JavaScript. In addition, as JavaScript functionality is essentially hosted  on web servers, a study of  network administration is the appropriate introduction for administrating Apache and other web servers and understanding how your JavaScript code will run or test under web load testing.  I will include, as appropriate, as many Windows network administration analogs as possible. However, the reader is warned that additional Windows command line network administration tools such as Powershell and Netsh are covered in summary fashion here.

Commands and arguments will be in bold. Screen examples and output will print in blue.  Choices will be [enclosed in brackets delineated by commas].  To complete this exercise, start an Xll Terminal on your MAC, UNIX, or Cygwin emulation. For Windows cmds, please start an administrative cmd sessions. If possible, it may be helpful to open multiple terminals or Xterms; one in which to practice the commands, the other in which to run man or info commands to further understand specific arguments.  UNIX is at all times cap sensitive.

UNIX commands run under an Operating System shell whose opening prompt will be delineated by a character(s) like #, $, or bash-.  The presence of such a prompt means your are in that particular shell.  Normally, you will recognize your shell type by the prompt. You can use the command echo $SHELL to return the shell type. The bash command will take you to a bash shell which is the most popular and powerful of administrative UNIX shells. Issuing exit will leave your shell. To run the commands as a particular user, change to appropriate directory (e.g. cd /home/rferrisx ), issue an su username command and provide a password. The whoami command  will tell you what user you are logged in as.  Some commands may require a login with administrative or root privileges to run successfully.

Some examples:

cd /home/rferrisx
su rferrisx

The command clear will erase your screen. Your previously typed commands can be found by using the up or down arrows. The keystroke combination CTRL-C will terminate most commands. Start an X11 Terminal. Lowercase q will terminate pagination. Space and Enter advance pagination on a command by one screen or one line respectively. With all UNIX commands, the less and more commands can be appended and used to page through output.  PageUp, PageDown, Enter,Space provide keystroke control pagination for long output. The size of the X11 font can usually be adjusted by holding down the CTRL key and right-clicking your mouse. The properties menu of the application control panel of a cmd or Powershell console provides for similar configuration.

Wednesday, May 1, 2013

Functions, Arrays, Objects in JavaScript: Part I

These are examples of creating a function, array, and object in JavaScript. The function below calls an expression invocation (Math.PI). An expression invocation is JavaScript equivalent to a built-in function.  A for loop sends 11 consecutive numeric arguments to the new function:

Saturday, April 20, 2013

Using Nook PC and Firebug togther

Below is a screenshot of using Nook Reader for PC and Mozilla's Firebug together to learn JavaScript. I think it makes for a powerful combination. I am reading Java Script Pocket Reference by David Flanagan:

Friday, April 19, 2013

Browser Javascript consoles

Below are screenshots of five Javascript consoles for
  • Chrome (Javascript Console)
  • Safari (Web Inspector)
  • Opera (Dragonfly)
  • Firefox (Firebug plugin)
  • IE (F12 developer tools)
I prefer Chrome because of the drop down function auto-complete menu. But each browser console has benefits. Safari needs you to enable the 'Develop' menu from the advanced part of preferences. Firefox needs  the Firebug plugin installation. Ctrl-Shift-I should get the Dragonfly and Develop Tools from Opera and Chrome respectively. IE has a similar console accessed by F12 keystroke . Please see the second screenshot below.

If you are on Windows, Notepad++  has source formatting for Javascript and the ability to run your html based code in open browser windows. There are some JS add-ins available. More full featured IDE ("Integrated Development Environments") include Eclipse and Aptana Studio; but I will save that discussion for another post. Click to enlarge these images.