Thursday, May 16, 2013

Learning to Code: Comments Count

I like comments in computer programming source code. I've never been the programmer to claim, "My code doesn't need comments." Maybe it is because I've always worked on so many projects that I need comments to remind me what I was thinking when I entered the source code into the text editor. Most programmers end up in a similar situation. They look at a function and wonder, "Why did I do it this way?"

Tangent: I also like comments in my "human" writing projects. One of the sad consequences of moving to digital media is that we might lose all the little marginalia authors and editors leave on manuscript drafts. That thought, the desire to preserve my notes, is worthy of its own blog post — so watch for a post on writing software and notes.

Here are my rules for comments:

  • Source code files should begin with identifying comments and an update log.
  • Functions, subroutines, and blocks of code should have at least one descriptive comment.
  • Comments should be on their own lines, when possible, so they are easier to spot.
  • Comments should be concise and meaningful.
  • Cryptic comments are worse than uncommented code.

Computer languages have a variety of ways to mark comments. I assume each language's creator thought he or she had the best approach for indicating text was a comment. I like "!" because it "screams" that something is a comment (Fortran), but I also find /* comment */ quick and easy to type. If I were creating a language, I'd probably adopt "#" at the start of comment lines (Perl, PHP, Python, and Ruby).

Because this series of blog posts reports my attempts to learn Objective-C and Cocoa, the C and C++ comment styles are important to know. Before 1999, the only "official" C source code comment format was:
/* comment here */
/***************************************************
* A multi-line comment in C ends when the compiler *
* reaches the asterisk-slash pair. *
***************************************************/

/**
* Multi-line does not require asterisk overload.
* Keep comments short.
*/
I like C-style comments, but that's probably because I learned C in the 1980s and have never bothered to learn C++. When you use a coding convention for 20 years or so, it seems pretty natural. There's really no reason C-style comments are better than the C++ style now used in most C-family languages. The C++ style that is favored by many companies is:
// C++ style one-line comment.

// Special note:
// The C++ style can continue across lines \
with a backslash. Avoid this style.
Returning to my personal comment guidelines, program source code should begin with comments. If we look back to the Xcode template for a C program, it begins with comments similar to those I would add anyway. The Apple Xcode template isn't exactly what I would add, but it beats the lack of comments I've (not) seen too often.

Source code files should begin with identifying comments and an update log.
//
// main.c
// Hello World C
//
// Created by Scott Wyatt on 2013-04-04.
// Copyright (c) 2013 Tameri Publications. All rights reserved.
//
My personal style for the top of a code file is:
/**
* File: main.c
* Program [or Function, etc]: Hello World C
*
* Copyright (c) 2013 Tameri Publications.
*
* 2013-04-04 Created by CSW
* 2013-04-10 Expanded printf() examples
*
* TODO Add other output function examples
*
**/
In every Xcode project, there is a "main.c" or "main.m" source code file. That name doesn't tell a programmer much of anything. Yes, this is the "main()" function, but of what program? I add the program's or function's full name on the next line.

My second rule is:

  • Functions, subroutines, and blocks of code should have at least one descriptive comment.

If you look at the template code, Apple does include one comment at the start of the main() function:
int main(int argc, const char * argv[])
{

// insert code here...
printf("Hello, World!\n");

}
Obviously, replace "insert code here…" with a meaningful comment. I've had programmers argue that they select "self-commenting" names for functions and variables. That's nice, but I never assume a function's name is enough to explain what it does. While Objective-C allows for, and even encourages, verbose coding habits, I would rather maintain my old-school approach to comments.

My other comment guidelines work together:

  • Comments should be on their own lines, when possible, so they are easier to spot.
  • Comments should be concise and meaningful.
  • Cryptic comments are worse than uncommented code.

I don't encourage "over-commenting" code. Instead, comment as much as necessary — and no more.

For more thoughts on comments and coding style, Google has published their internal style guide for code. Google encourages programmers to adopt these guidelines:

http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Comments


[possible tags: Objective-c, Cocoa, Apple, programming, computers, comments, writing, notes, planning]

Thursday, May 9, 2013

Learning to Code III: Hello World

In my earlier posts (I, II, and Intro), I explained that I'll be using Xcode to learn Objective-C and the Cocoa Frameworks to learn about programming OS X and iOS applications. If you look back at those posts, you will find how to create a new command line application in either C or Objective-C.

This blog entry compares "pure C" to the C code I'll be using within an Objective-C file. Because Objective-C is a superset of C, you can use any valid C programming code in an Objective-C file. After this blog post, I'm going to be doing all coding within Objective-C projects, for simplicity among other reasons.

Hello, C Programming

Begin by creating a new "Command Line Tool" project in C. Apple's Xcode handily creates the code to output "Hello World!" to the command line. Run the code and you'll see the results in the "debug area" of the Xcode window. Ah, for the old days when aspiring young coders had to type the "Hello World!" program with one hand while holding a book or magazine flat with the other. (Yes, that's how I learned to program: I typed in the programs that appeared in various magazines.)

Here is the complete C version of "Hello World!" created by Xcode:
//
// main.c
// Hello World C
//
// Created by Scott Wyatt on 2013-04-04.
// Copyright (c) 2013 Tameri Publications. All rights reserved.
//

#include

int main(int argc, const char * argv[])
{

// insert code here...
printf("Hello, World!\n");
return 0;
}

Comments

The first seven lines are comments. They don't do anything, at least not as far as the compiler is concerned. Comments are essential to good programming, though. You include comments in code so other programmers (and you) can later recognize what the code is meant to be doing. Most programmers also use comments to record when a change was made to code and by whom. Single-line comments in C begin with //. The Xcode template could use multi-line comments, which begin with /* and end with */. You'll see multi-line comments in some examples I tryout later in this series.

I'm going to write a single post on comments and code formatting, because documenting your code is an essential skill for programmers.

In the comments above, Xcode has included notes on the name of the source code file (main.c), the program's name, and some copyright information. The comments were generated based on the data entered when creating the new project. The automation saves a little time.

Directives

After the comments is a "compiler directive." The directive in the template example is possibly the most common C compiler directive. It directs the compiler to include the standard input/output library ("header") source code when compiling this application. The "stdio.h" file includes the source code for many important "functions" programs need. Not only will your programs include standard libraries, but also code you write to reuse as a developer.

Don't worry about some of the terminology for now. I'll be explaining functions, libraries, headers, and more as the programs in this series get more complex.

Directives begin with a hashtag (# "pound" symbol) and do not end with a semicolon. That's important because statements in C usually end with semicolons.

The main() Function

I've heard C code described as a web of functions, all leading from and to main(). If you want to program in C, you need to understand the format of functions.

main() is a special function. Every C (and Objective-C, C++, C#, et al) program begins at main() and most also end at main(). I won't argue that its role as the starting point for execution is all that makes main() special, but that is the big difference between main() and all other functions. In terms of syntax and coding, main() is like other functions.

I'm going to detail functions in a dedicated post, too. For now, I want to explain the most basic features of the main() function created by Xcode. Look back to the code above. In plain English, the main() function in the template means the following:
  1. main() is a function that returns an integer value.
  2. If the user executing this program has included "command line arguments" after the application's name, please store those arguments for later processing.
  3. Execute the code within the curly-braces.
  4. Return the integer value "0" via main() when finished.
Most functions return values. Even functions that we seldom assign to variables or test, can and do return values. You need to tell the compiler what type of value or values will be returned by a function. In our example code, int main(…) tells the compiler that when main() is finished, it will return with an integer value.

What if you don't care about a return value? Many simple main() functions are written in the format:
void main(void) {…}
or
int main(void) {…}
I really, really dislike both of these examples — yet they appear in many programming books. I'll explain more in my post on functions, but for now you should know that I believe all functions should return something. I can use return values to let other functions know when there has been a problem. For example, I could use "0" to mean everything went well and return a number to report an unexpected situation. Error codes, once familiar to DOS users, are return codes.

Many command line programs are followed by user input. A reminder, Apple calls these programs "command line tools" in Xcode. User input included on the command line are called arguments, "parameters", or "switches" depending on their purposes.

DOS and Unix/Linux users know the command line format well:
dir c:\*.* /p /w

ls -l
The directory (dir) and list directory (ls) commands are programs. They accept parameters and switches, which tell these utility programs which files and directories to list, and how to format that list. If something goes wrong, the commands return an error code, which leads to an error message. This is how most command line programs work.

How does C know you might (or might not) include parameters and switches?
int main(int argc, const char * argv[])
The parameters arc and argv contain the argument count and an array of character strings with the user input. Of course argc is an integer — you can't enter a fraction of an input argument! Again, many of these concepts will be explored later. The "Hello World!" program doesn't do anything with arguments, anyway. Including the argument variables in main() does prevent an error if the user includes any (meaningless) arguments.

For now, leave the argument variables in main() when entering example programs.

The statements defining a function appear within two curly braces ( { } ). These braces mark the beginning and end of the function. Most programming editors, including Xcode, will let you know if a function is "unbalanced" because you forgot to include a curly brace somewhere.

Displaying Text

In classic old C, the printf() function sends output to the screen. Here we can see that most functions and statements within a C program end with the semicolon. I'm not going to explain printf() in this sample. I bet you can guess how it works. Maybe the "\n" is also easy to guess?
printf("Hello, World!\n");

Ending the Program

The main() function ends with a return {value} statement. I've already mentioned the importance of return values. You can omit the return statement, but I like to include it whenever possible.
return 0;
Technically, the end of main() is the closing curly brace. All function definitions end with their last brace.

Hello, Objective-C

Now, here is the Objective-C version of "Hello World!" offered by Xcode:
//
// main.m
// Hello World Plus
//
// Created by Scott Wyatt on 2013-04-04.
// Copyright (c) 2013 Tameri Publications. All rights reserved.
//

#import

int main(int argc, const char * argv[])
{

@autoreleasepool {

// insert code here...
NSLog(@"Hello, World!");

}
return 0;
}
The Objective-C version of "Hello World!" is familiar to C programmers, but still different enough to reveal ways in which Objective-C is not C. All the following information is technical. It will be useful, later.

import vs. include

In Objective-C, it is a good idea to use the compiler directive import instead of include. You might say that include is rather "brain dead" — it can muck up the works if you accidentally include the same source code more than once. When you import code, the compiler verifies that you have the code only once in your application. For now, that's a little detail. When you are working on large projects, include mistakes are easier to make.

Also, look at what is imported by Xcode. The "Foundation.h" header actually imports several dozen smaller header files. This is the magic of importing: you can reuse code easily.

If you want to be overwhelmed:

http://stackoverflow.com/questions/959007/files-imported-when-importing-foundation-foundation-h-for-cocoa

@autoreleasepool

Don't worry about @autoreleasepool{} for now. It does some memory magic that's beyond what I'm going to address in any pending blog posts. Leave it, and its curly braces, alone.

NSLog() vs. printf()

Again, beginning Cocoa programmers don't need to worry about the details yet, but NSLog() is going to be your friend when you are working on big applications. Sure, there are other ways to debug code, but nothing beats getting some output along the way.

The NSLog() function sends output to the console window or the debug area in Xcode. If you are writing a true command line tool, I would suggest using printf(). If you are only using the output to debug an application, use NSLog().

Much of what you learn about printf() in my upcoming blog posts will apply to NSLog(). Plus, by learning about printf() you are learning generic C code that works with any standard C compiler.

Monday, May 6, 2013

New Test for Computers - Grading Essays at College Level - NYTimes.com

Can computer software evaluate student papers? The debate has waged for about three years in higher education, and lately it has taken on a new urgency. This article from 2012 raises the question.
According to a new study [http://dl.dropbox.com/u/44416236/NCME%202012%20Paper3_29_12.pdf] by the University of Akron, computer grading software is just as effective in grading essays on standardized tests as live human scoring. After testing 16,000 middle school and high school test essays graded by both humans and computers, the study found virtually identical levels of accuracy, with the software in some cases proving to be more reliable than human grading. While the results are a blow to technology naysayers, the software is still controversial among certain education advocates who claim the software is not a cure-all for grading student essays.
http://www.aaeteachers.org/index.php/blog/714-study-robo-readers-more-accurate-in-scoring-essays, April 23, 2012
Now, a recent New York Times article explores the role software will have grading papers in large online courses (and large lecture courses). The simple reality is that no teacher can grade 1000 or more papers. A team of graders is also expensive, and any "cost benefits" of online courses is lost. (However, many of us — myself included — don't see online education as a money-saving tool. Instead, we see it as a way to teach non-traditional students.)

The NYT article begins with a hypothetical:
New Test for Computers: Grading Essays at College Level
http://www.nytimes.com/2013/04/05/science/new-test-for-computers-grading-essays-at-college-level.html
Imagine taking a college exam, and, instead of handing in a blue book and getting a grade from a professor a few weeks later, clicking the "send" button when you are done and receiving a grade back instantly, your essay scored by a software program.

And then, instead of being done with that exam, imagine that the system would immediately let you rewrite the test to try to improve your grade.

EdX, the nonprofit enterprise founded by Harvard and the Massachusetts Institute of Technology to offer courses on the Internet, has just introduced such a system and will make its automated software available free on the Web to any institution that wants to use it. The software uses artificial intelligence to grade student essays and short written answers, freeing professors for other tasks.
We might not call it "grading" or "evaluating," yet our software already helps us with instant feedback. I use spellcheck and grammar check. I use automatic formatting tools for academic citations. Many of us in education do use plagiarism detection software to screen student papers, though those applications are far from perfect.

Instant feedback helps me, as a writer. I'm sure it will help many students. But, I'm not yet ready to rely on a computer to do more than offer suggestions or to highlight potential problems. Often, my word processor's spellcheck is wrong.

I certainly endorse the feedback model:
Anant Agarwal, an electrical engineer who is president of EdX, predicted that the instant-grading software would be a useful pedagogical tool, enabling students to take tests and write essays over and over and improve the quality of their answers. He said the technology would offer distinct advantages over the traditional classroom system, where students often wait days or weeks for grades.

"There is a huge value in learning with instant feedback," Mr. Agarwal said. "Students are telling us they learn much better with instant feedback."
The software used to evaluate writing is an example of artificial intelligence. The software builds a database based on samples. Over time, as human readers double check the feedback, the system "learns" and "refines" its criteria.
The EdX assessment tool requires human teachers, or graders, to first grade 100 essays or essay questions. The system then uses a variety of machine-learning techniques to train itself to be able to grade any number of essay or answers automatically and almost instantaneously.

The software will assign a grade depending on the scoring system created by the teacher, whether it is a letter grade or numerical rank. It will also provide general feedback, like telling a student whether an answer was on topic or not.

Dr. Agarwal said he believed that the software was nearing the capability of human grading.

"This is machine learning and there is a long way to go, but it's good enough and the upside is huge," he said. "We found that the quality of the grading is similar to the variation you find from instructor to instructor."
I do not like the "good enough" notion, nor do I like grading. I like feedback and guidance for students, at least from a computer system.

Still, AI is going to improve. I wonder how much it will improve in the next five years. The potential is there for software to mimic human readers to the point it will be impossible to tell the software-analyzed essay from the human-analyzed work.
Last year the Hewlett Foundation, a grant-making organization set up by one of the Hewlett-Packard founders and his wife, sponsored two $100,000 prizes aimed at improving software that grades essays and short answers. More than 150 teams entered each category. A winner of one of the Hewlett contests, Vik Paruchuri, was hired by EdX to help design its assessment software.

"One of our focuses is to help kids learn how to think critically," said Victor Vuchic, a program officer at the Hewlett Foundation. "It's probably impossible to do that with multiple-choice tests. The challenge is that this requires human graders, and so they cost a lot more and they take a lot more time."

Mark D. Shermis, a professor at the University of Akron in Ohio, supervised the Hewlett Foundation's contest on automated essay scoring and wrote a paper about the experiment. In his view, the technology — though imperfect — has a place in educational settings.

With increasingly large class sizes, it is impossible for most teachers to give students meaningful feedback on writing assignments, he said. Plus, he noted, critics of the technology have tended to come from the nation's best universities, where the level of pedagogy is much better than at most schools.

"Often they come from very prestigious institutions where, in fact, they do a much better job of providing feedback than a machine ever could," Dr. Shermis said. "There seems to be a lack of appreciation of what is actually going on in the real world."
The final two paragraph should worry everyone. The best teachers I know are at community colleges and state universities. This false dichotomy is disheartening.

However (you know that was coming), I know that mediocrity is a problem in higher education. Mediocre schools will struggle to compete in the future. Many of them will be endangered. Online education will not save them — it will probably help kill them. And I fear these are the schools at which administrators will rush to adopt automation, further diluting their institutions' roles in higher education.

Wednesday, May 1, 2013

Learning to Code II: Welcome to Xcode

If you're going to develop iOS or OS X applications, you're going to be using Xcode, Apple's integrated development environment (IDE). The blog post is an extremely simple introduction to Xcode. It's so simple that I'm only going to discuss one command in the IDE: the "Run" application button.

Before starting to program on a computer, I create a folder (directory) for my programming projects. I call the folder "Programming" to keep the contents obvious. You can name your programming projects folder anything, but be sure you can locate it easily.

I like to keep programming projects outside my "Documents" folder, at the top level of my personal user folder. Most of the folders within the home directory for a user are created by the operating system. For example, Apple's OS X creates the following: Desktop, Documents, Library (usually hidden), Movies, Music, Pictures, and Public. The home folder for most users won't have as many folders as I have, which is two dozen. It is common to have about a dozen folders.

I also drag the folder to my "Sidebar" to create a shortcut to my projects. My sidebar is a bit cluttered, but I love the one-click convenience when I am working on many projects. If you don't see a sidebar, you can show or hide the sidebar using Finder's "View" menu. Because I like to know where I am when navigating the computer, I also show the "Path Bar" and "Status Bar" at all times.

Screenshot: My user folder


I've started with an empty "Programming" folder for this example. Create your "Programming" folder, and then create an "Objective-C" or "Cocoa App" folder within your programming projects folder. Normally, my programming folder has sub-folders for several languages and tools. I've created an "ObjC Basics" folder within "Programming" to organize tutorial files during my Cocoa immersion course.

My programming folder, with an Objective-C sub-folder and Xcode projects testing Objective-C lessons:

I'm going to assume you know how to locate Xcode within the "Applications" folder on a Macintosh. Locate the Xcode icon and start the application.

You should see the "Welcome to Xcode" splash screen when you start the IDE. The splash screen indicates the version of Xcode running and includes a handy list of recent projects.

Note: You won't see it if you have already started Xcode in the past and unchecked "Show this window when Xcode launches." Also, we aren't going to explore the options listed on the splash screen in this introduction, but I encourage you to try the "Learn about using Xcode" link.

Screenshot: Welcome to Xcode splash screen

Select "Create a new Xcode project" from the welcome splash screen. You can also use "File, New, Project" menu path (or shift+command+N). After telling Xcode you want to create a new project, you will be asked to select the type of project. Each type of project comes with a simple template to help you get started.

For this tutorial, select "Application" under "OS X" on the lefthand panel of the window. Then, select "Command Line Tool" as the type of application.

Screenshot: Selecting a project template


After you select a project template, click "Next." Xcode then presents a list of options for the project. The first of these options is the application's name. In Apple's universe, applications are called "Products." I'll resist a lengthy complaint about the rhetorical implications of "Product Name" instead of "Application Name" in Xcode.

You can name your application (product) "Hello World" for this tutorial. You then need to include an "Organization Name" and unique "Company Identifier" for the application. These are important, especially later on when you are creating "real" applications. The company identifier should be one word that will help the operating system identify programs by you and your organization. The identifier is used to help store application settings and more. For now, maybe use your last name or initials. In my example, I'm using the name of my own freelance business as the organization name and identifier.

Selecting the "Type" of application is simple: stick to "Foundation" unless you know you need to select something else. The "Foundation" type works fine for C and Objective-C programs. Also, you don't need to worry about the "Use Automatic Reference Counting" option at this time. Automatic reference counting (ARC) is important as you code complex applications, but way beyond what we'll be doing in the early tutorials.

Screenshot: Options for a new project



After you click "Next" on the options window, you will need to select a folder in which Xcode will store the application and any additional files needed. On my MacBook Pro, I navigate to my "ObjC Basic" folder and click "New Folder." I name the new folder "Hello World" and then Xcode automatically creates a bunch of files and folders within the new home for this project.




Screenshot: Hello World folder created




Xcode appears!

It's okay to feel overwhelmed. Xcode is complex. Apple might focus intensely on the user experience when they develop software, but they don't seem concerned with the developer experience. Thankfully, we're going to ease into Xcode. Even experienced developers can find the Xcode IDE overwhelming.

The lefthand pane of Xcode is the "Navigation Area." If you click the folder icon above the navigation area, you will see a map of the files and folders contained within a project. You will use the navigation area constantly, moving from file to file while you edit an application.

The righthand pane of Xcode is the "Utility Area." This area includes code snippets, a tool pallet, and a quick help area.

The middle of the Xcode workspace is the aptly named "Editor Area." This is where you will edit code and project settings.

At the bottom, below the editor area, is a "Debug Area" that displays program output and error messages. The debug window is hidden until you run an application.




Apple's diagram of the Xcode workspace:




Assuming you are following along with this tutorial, you should have a "Hello World" project template loaded. In the navigation area, select the "main.m" file. Clicking this file opens the sample Objective-C code in the editing area. Study the navigation area closely. Each project has a main folder that has the name of your application. That folder will contain most of your code when we work through tutorial projects. Much later in your Objective-C experience, you will reuse code across several projects — that's when you'll need to navigate through dozens of folders with lots of files.

For now, find and open the "main.m" file so you can study the sample code.

Screenshot: Opening main.m in the editor




Every C-based programming language requires a "main()" function. The first code file is "main.m" in the project template, so you can easily locate the required main() function. Basically, main() tells the computer, "This program starts here!" When the end of main() is reached, the program stops.

Note: Experienced computer users and programmers know that file extensions indicate document types. An "m" file contains Objective-C code. Why "m" and not "oc" or something else? I'm sure there's a reason. The "c" extension is for C program code, and "cc" is for C++ program code. You might see some C or C++ files within a project.

In the upper-left corner of Xcode is a "Run" button. Click it to run the "Hello World" sample program. The output from the application appears in the debug area at the bottom of Xcode.

Screenshot: Hello World has finished


You now know how to create a project, navigate the project files, and execute the project.

C Project Template

If you select the "C" project type within the options window, the project template and sample code will be "pure" C code. That's not a problem for learning C, but since Objective-C is a superset of C, there's no reason not to stick to the "Foundation" type for tutorial lessons.

There are some minor differences between the C template and Objective-C template. Compare the two and you'll notice the little things that are different. Hint: compare the #include and #import directives — something I'll explain in the next post.

Screenshot: C project template




You can run a C program the same way you run an Objective-C program from within Xcode. Again, the output appears in the debug area.


Now, you can run C programs in Xcode, too.

Sample Application

The screenshot below is from our next lesson: a simple program that prints output. I have clicked "Run" and the output of the print functions appears in the debug area.




In my next post on Cocoa programming, we'll examine a sample project to review some basic C programing skills essential to learning Objective-C.

Thursday, April 25, 2013

Learning to Code: The Tool(s)

If you want to learn Objective-C, it helps to know C. Learning C — or reviewing it — is a good way to become familiar with Apple's development tools, too.

Learning to program is a cause of mine. I advocate teaching programming to all students, not merely a handful of geeks, hackers, or nerds. When we teach everyone about coding, it demystifies how computers work and it introduces students from a wider variety of backgrounds to what could be an excellent career path.

Years ago, educators would use LOGO or BASIC in elementary school classrooms. Then, along came HyperCard. There are still introductory programming tools based on LOGO, BASIC, and HyperTalk languages. You can learn to program using AppleScript or by writing Microsoft Word macros in Visual Basic for Applications (VBA). Personally, I'm for using whatever tools a teacher might enjoy at the earlier ages (K-6). In high school, though, I am biased towards plain, simple, C as a foundation for future coding skills.

If you learn the basics of C, you can adapt to Java, C++, C#, or Objective-C. The skills you learn coding in C are portable — much like the language itself. C is not a fancy language. It has quirks, too.

I would advocate for Delphi or Free Pascal (both using Object Pascal), and I am a passionate defender of the Pascal family of languages. But, realistically the computing world today is dominated by "curly-braces" and languages influenced by C. (I wish Apple would embrace Pascal again, which was once the language of choice for high school programming courses. Apple helped create the Object Pascal standard. Pascal… well, that's a tangent I'll take in some other post.)

You Need an IDE. You Need Xcode

To start programming on the Mac, you first need to obtain Apple's Xcode integrated development environment (IDE). Even if you wish to use another editor, you'll need Apple's tools eventually. Thankfully, Xcode is a free download from Apple's App Store:

https://developer.apple.com/xcode/

Note: The basics of the next few posts will help anyone, on most any operating system platform. However, since my coding journey is from C to Objective-C on OS X and iOS, these posts will have a decidedly "Apple-centric" focus. You do need to use the Apple tools to create a proper iPhone or iPad application, and I'm convinced that most Apple computer users also want a "native" look-and-feel application, instead of the not-quite-right experience of Java of C++ apps that don't use the Cocoa frameworks.

There are other free IDEs that are ideal for learning C. On the Mac, Windows, and Linux, I often use NetBeans. When you download NetBeans, be sure to obtain the "All" bundle, which enables C, C++, Java, and PHP programming. Download NetBeans from:

https://netbeans.org

Eclipse might be the most popular free IDE for Java and C/C++ development. Eclipse is also available for Windows and Linux. I don't happen to like Eclipse as much as some of my colleagues, but it is only a matter of preference. For the topics I'm going to discuss, be sure to download the "C/C++" bundle of Eclipse. Download Eclipse from:

http://www.eclipse.org

Though I am not discussing the "how-to" of NetBeans or Eclipse, you can code and test any of the C applications I include on the blog. Technically, you can learn Objective-C on a platform other than Apple's OS X, too. For more information on free Objective-C tools for Windows and Linux, visit:

http://www.gnustep.org


Microsoft Freebies!

If you are a Windows user, Microsoft's basic programming tools are also available for free. That's right, you can get something for nothing from Microsoft. I won't be discussing any of those tools in this series of posts, though I might write a bit about them in the distant future. You can download the Microsoft Express tools from:

http://www.microsoft.com/visualstudio/eng/products/visual-studio-express-products

(You can search for "Microsoft Express" if the link above doesn't work.)


Nothing Else Required

After you download and install Xcode, you're ready to program. That's it — nothing else is required on a Mac. You're ready to write a program. Seriously. We're ready to discuss C programming in the next blog post. In the meantime, launch Xcode and feel a bit overwhelmed. You might also rush out and buy a few books. I'm using:

Clair, Robert. Learning Objective-C 2.0: A Hands-on Guide to Objective-C for Mac and iOS Developers. 2nd ed., 2013. 9780321832085 / 0321832086

Monday, April 22, 2013

Software Analyzing Texts?

Can software accurately analyze the writing style of an author to determine if he or she wrote a specific work? Maybe…
Open source app can detect text's authors
http://www.theregister.co.uk/2013/02/22/author_detection_uni_adelaide/
A group of Adelaide researchers has released an open-source tool that helps identify document authorship by comparing texts.

While their own test cases – and therefore the headlines – concentrated on identifying the authors of historical documents, it seems to The Register that any number of modern uses of such a tool might arise.

The two test cases the researchers drew on in developing their software, on Github here, were a series of US essays called The Federalist Papers, and the Letter to the Hebrews in the New Testament.

The Federalist Paper essays were written in the lead-up to the drafting of the US Constitution, by Alexander Hamilton, James Madison and John Jay. Of the 85 essays, the authorship of 12 is disputed and one has generally been attributed to Jay.

Professor Derek Abbott of the University of Adelaide explains the results: "We've shown that one of the disputed texts, Essay 62, is indeed written by James Madison with a high degree of certainty.

"But the other 12 essays cannot be allocated to any of the three authors with a similarly strong likelihood. We believe they are probably the result of a certain degree of collaboration between the authors, which would also explain why there hasn't been scholarly consensus to date."
I love research such as this. One of the problems we will face with online courses (and even traditional courses) is that students might be more tempted to submit the works of others as their own. You can buy almost anything online, including term papers and reports. What if software could flag works as questionable? That would be pretty valuable.

The challenge might be amassing sufficient amounts of verified text to establish a pattern, but we could always ask students to write a few short samples. Their online forum posts would also give us some sense of how a students writes when a grade isn't at stake.

The research and the software are both freely available.

Free software means there is a high likelihood that other scholars will test the software and the conclusions of the researchers. The more testing of the software, the more likely it will be improved. It might be reasonable to expect private industry and public agencies to also test the software.
In the research paper, published in full at PLOSOne, the group notes that author attribution is a question that's stretching beyond academia in the modern era.

http://www.plosone.org/article/info%3Adoi%2F10.1371%2Fjournal.pone.0054998
"Due to an increase in the amount of data in various forms including emails, blogs, messages on the internet and SMS, the problem of author attribution has received more attention. In addition to its traditional application for shedding light on the authorship of disputed texts in the classical literature, new applications have arisen such as plagiarism detection, web searching, spam email detection, and finding the authors of disputed or anonymous documents in forensics against cyber crime," the researchers write.

They note that further research would be needed to test their methodology against modern texts – but with the software offered for free, The Register can easily imagine the software getting a workout by any number of interested parties.
Free software? I know I'm curious enough to experiment with some public domain texts. After all, maybe Chaucer didn't write all those poems!

Wednesday, April 17, 2013

What Computing Can and Could Do…

Computers have changed writing education, but many writing teachers wonder if technology is now turning into a threat. Too many politicians, administrators, and non-profit foundations are rushing to embrace technologies such as MOOCs and adaptive tutoring without skepticism. What is the balance between too little and too much faith in technology?

The question of what computing technology can and cannot do for writing students is something we need to consider — as well as whether or not some of these tasks should be done (by a computer or a human).

1) Formatting. I cannot remember the intricacies of APA or MLA, so I use Bookends with my writing tools. Even Word has improved its basic bibliography formatter to the point I catch few minor errors when I triple check the entries.

Yes, I do tell my students to double and triple check citations and bibliographies, but I also demonstrate Bookends, EndNote, RefWords, and Word's built-in tools. The time saved lets a writer focus on content. We claim ideas matter more than formatting, but we also know editors will reject a paper with sloppy formatting.

2) Grammar, spelling, and mechanics. The quality of automated writing tools has improved dramatically in the last 30 years. I use Grammarian Pro on the Mac and love it. Again, we know the tools are imperfect, but to assume they might never be better than I am would be presumptuous. How often do you receive a document that a basic spelling and grammar check would have improved?

Anyone else use dictation software? The software is getting great at determining "too, to, two" and even using "who" and "whom" properly. My software speaks up and says, "Grammar error." That's either annoying or impressive, but it certainly improves my writing.

3) Fact checking. Yes, there are research projects that demonstrate "fact checks" of papers. Imagine going line-by-line through papers and marking the contents as fact, disputed fact, incorrect fact, or opinion. The technology exists for software to do this very task. Already, law firms use computers to expedite discovery research.
The Truth Teller prototype was built and runs with a combination of several technologies - some new, some very familiar. We've combined video and audio extraction with a speech-to-text technology to search a database of facts and fact checks. The Post also worked with Dan Schultz, creator of Truth Goggles, as he helped consult and shared his knowledge of real-time fact checking. We are effectively taking in video, converting the audio to text, matching that text to our database, and then displaying, in real time, what's true and what's false. The key to the project's success is building an authoritative database - our goal is to identify falsehoods, not create more of them.

<technical_details>

We are transcribing videos using Microsoft Audio Video indexing service (MAVIS) technology. MAVIS is a Windows Azure application which uses Deep Neural Net (DNN) based speech recognition technology to convert audio signals into words. Using this service, we are extracting audio from videos and saving the information in our Lucene search index as a transcript. We are then looking for the facts in the transcription. Finding distinct phrases to match is difficult. Instead, we are focusing on patterns.

We are using approximate string matching, or a fuzzy string searching algorithm. We are implemented a modified version Rabin-Karp using Levenshtein distance algorithm. This will be modified to recognize paraphrasing and negative connotations in the future.
http://www.knightfoundation.org/blogs/knightblog/2013/1/29/debuting-truth-teller-washington-post-real-time-lie-detection-service-your-service-not-quite-yet/
4) Plagiarism detection. Several services already exist that compare submitted papers to a database of existing works. No human could compare every line of a document to other documents. If a paper is factually correct, it can still be a "borrowed" work that doesn't deserve a passing grade.

TurnItIn and other plagiarism detectors are imperfect, but the more data they receive the better they will be at detection. False positives are also a problem, because students stumble with citation formats. Ideally, the plagiarism detectors will improve enough to recognize when a student was trying to cite a source. Honest errors in formatting might also be reduced with formatting tools mentioned earlier.

5) Grading. Okay, robo-grading scares teachers. You can find a lot of articles and essays on this technology. Someday, the technology will work — at least well enough for a first-pass. The reality is, bad writing probably can be detected by software. A human should always verify the results of computer-based grading tools, yet the tools can save time.

I use basic grading tools to recognize common problems. The software is okay, and saves me several hours. As long as we recognize what software can and cannot do as a "robo-grader" we can refine our own processes.

Combine a "truth detector" with plagiarism software and e-grading applications… we start to approach an evaluator of at least acceptable competence.

Technology isn't going to replace the writing teacher, but it certainly will help us a lot.

Friday, April 12, 2013

Learning to Code: Starting Point for Objective-C

As readers of this blog know, the more I delve into programming, the more convinced I am that it should be a standard school subject — not merely an elective sought after by a few enthusiastic students. Programming skills reinforce the value of breaking problems into simpler pieces. In the end, a computer must reduce problems to simple tasks. Good writers, historians, chemists… we all break problems into little, digestible, solvable tasks.

And just as a musician must practice scales, the basics of programming need to be practiced and sometimes revived. It is no secret that my C skills have atrophied, so I am starting from the beginning. My journey towards Cocoa Goodness begins with two books:


In the early pages of Clair's text, he mentions that you need a good understanding of C to work effectively in Objective-C. Turning to my bookcase, I found several C books, but settled on the Absolute Beginner's Guide because it is operating system and compiler agnostic. It is an old and simple book (1994 being the ancient past in computer time), yet it is precisely what I needed for a quick review.

I'm strange, I realize. Not many people like to go back and read basic grammar books, yet I always enjoy recalling the little bits about English I forget. Any time I teach a writing or literature class, I review the materials and feel like I'm discovering something new. Programming has that same feel.

As Clair reminds readers of the basic syntax and common functions in C, I turn to the Perry text and read the short chapters on the same topics. Clair assumes that his readers know C, C++, Java, and similar languages. He also stresses that Objective-C is closer to C than C++ — so you need to unlearn (C++) and relearn (basic C) as you move into Objective-C.

Many, many years ago, when I was an undergraduate, USC had several NeXT computers. The language used to program the NeXT was Objective-C and the operating system was NeXTSTEP (with the silly all-caps but "e" format). As I start writing about Obj-C, you'll be able to recognize this legacy. I graduated from USC in 1990, so a fair number of years (22+) have elapsed since I last used Objective-C. Even as a Mac owner and user, I clung to other tools for as long as possible. Now, I must go back to the future.

Programmers might wonder why I'm not turning to that fabled classic, The C Programming Language by Brian Kernighan and language creator Dennis Ritchie. Or maybe an O'Reilly book, such as C in a Nutshell. The Absolute Beginner's Guide is a better text for me. It's much better than a "Dummies" or "Idiots" text, sparing readers the attempts at humor. Perry keeps chapters focused on one topic. At the end of the book, there is a code listing for a complete blackjack game. I like that the code heads towards a real project, something I can play with and modify.

Going back and forth between a dense technical text (Clair) and a more project-based text (Perry) helps me consider issues from two perspectives. Beginners don't think about pointers and memory, which is an essential aspect of coding. The better you understand computing theory, I believe the better your code. You don't need to understand the finest details, but enough to appreciate what is happening "under the hood" when you create an application.

Young writers can get overwhelmed when we focus too much on grammar and mechanics. Beginning programmers can also be overwhelmed by too much deep theory. Focusing on ideas first, then developing an appreciation for how a language works seems perfectly logical to me. We don't teach children grammar before they speak! We teach them about nouns and verbs, periods and commas, long after a child is speaking.

As a programmer, I like to see how problems are solved, and then I study the code. After I study the code, I enjoy going that extra level or two deeper — which is why I love learning about the magic performed by compilers.

A good enough comparison: When I learned BASIC, I didn't need to understand what the interpreter or compiler was doing. As I learned C, it helped to learn how memory worked. Later on, I learned how to optimize C code, based on what the compiler would do and how a particular CPU worked. Yet, learning BASIC was an ideal introduction to programming: I learned to express simple ideas (BASIC) before learning how to write properly structured programs (Pascal, Fortran, and C). Yes, I know you can do a lot with modern BASIC derivatives — but early BASIC, was called BASIC for a reason. BASIC allowed mere mortals to program.

What have I learned as I revisit C and begin to learn Objective-C? I'm going to bore readers with a bit of C in my next post, since that's what I've been revisiting. I'll also discuss how learning something like C helps me as a creative and academic writer. Yes, coding can be poetic. It is certainly inspiring.

Monday, April 8, 2013

Human Readers for Tests

As readers of my blogs know, I'm never opposed to using technology when it is an effective tool. I am opposed to the blind embrace of the latest trends without critical examination of the potential side effects. Computer-assisted grading, I can endorse to some extent because I use software to help me analyze student papers — and my own writings. But, I cannot and will not endorse any system that gives weight to the computer-based scoring.

If you're a teacher, consider this petition:

http://humanreaders.org/petition/index.php

Now, I also want to add a critical comment on human graders.

If the graders of standardized tests are using rigid scoring rubrics, they are little better than software algorithms. Bad grading is bad grading. Inflexible = bad.

Again, I am not opposed to using a computer for fact checking, some plagiarism verification, and as formatting aids. Computers can and do help many of us write more effectively. But, I don't use computers to grade papers. Sometimes that distinction escapes my students at first, but eventually they recognize that I'm using software to help me highlight potential problems.

Software is better than ever at grammar and spelling, but it isn't perfect. There are also new applications that can fact check documents, a project funded by the Knight Foundation to fact check political speeches and papers. But, computers cannot yet grade anything that cannot be flowcharted and categorized.

Can I grade a multiple choice test with a computer? Certainly. Can I grade a spelling test automatically? Sure. But, the computer might not recognize any patterns in the errors a student makes. In time, maybe a computer will be able to grade a test and offer suggestions for future study. But, computer technology is years, maybe decades, from being able to "grade" an essay, poem, or creative work.

Even when computers do reach that capability, I want a human to have the final say on grading students. We already are reducing too much education to an isolated process, focused on high-stakes test results. We need some humanity, for lack of a better word, in our classes.

Friday, April 5, 2013

MOOCs by Discipline: Are there Differences?

I have been contemplating if online learning differs by discipline, especially after reading a few studies on the topic. One of the studies (Xu & Jaggars, 2013), found:
The subject areas in which the negative coefficients for online learning were weaker than average in terms of both course persistence and course grades (indicating that students were relatively better able to adapt to online learning in these subjects) were computer science, the applied professions, and natural science.
Are the STEM fields that different, in terms of pedagogy and goals, from the humanities? Of course, we could certainly argue that the sciences are often taught divorced from ethics and humanistic concerns, but the teaching methods, objects, and outcomes assessments are my primary concern when reading such studies.

Do Massive Online Open Courses (MOOCs) work better in the STEM fields than in the humanities?

The coding course I'm currently working through is offered by a Russian institution. The blog and notes are in both Russian and English (http://wikistan.ru/blog/macosdev/) and the podcast/iTunes U content is in English. So, this is not an example of a U.S. corporation or university — there are computer courses from universities in China, India, South Africa, and a really great course series from Brazil.

Recently, I've been discussing writing instruction versus other topics with colleagues. I find they view the STEM fields, and some other topics, as simple matters of rote memorization. Assessment, they imagine, can be performed adequately with multiple choice exercises or simple fill-in-the-blank tests.

When I talk to colleagues, some of them mistakenly state that there is "one right answer" when programming, but that is not the case. There are "best practices" and "standards" but you can solve one problem in countless ways — some better than others. Consider a most simple assignment: average two numbers. I could write an absurd amount of code with variables, pointers, and custom functions, or I could write one line of code with the values and format embedded (roughly, printf("'%.1f'",(5+9)/2); ).

To me, this is much like academic writing. Some students meander and struggle with organization. They over-think, trying too hard. We have to help them understand the norms of the genre, while helping them think about problems more systematically. Teaching programming, you have to guide students towards clarity and proper exception handling. A multiple choice test cannot help judge how effectively a student solves a programming problem, a higher-level skill than memorizing keywords (nouns and verbs) or syntax (grammar) of coding.

My question, then, is what are the differences I am overlooking?

STEM courses are not taught effectively, based on some of the comments of my writing colleagues. Typically, half of engineering, programming, and science second-year students do not complete their degrees. That means half "drop out" of their majors. These students often leave the STEM fields entirely, not merely switching speciality or interest area within the STEM umbrella.

STEM courses are notorious for large lectures, intense labs, and lots of competition. The professors brag about high failure rates and low exam scores — those are points of pride.

Personally, I prefer the MOOC and online course models because they lack the intensity of STEM lecture halls. I don't feel like I am going to be insulted for the half-dozen failed attempts at a programming problem. Then, once I solve the problem, a lab leader (a grad student) isn't going to berate me for using the "wrong" approach to a problem. Online, I'm finding people politely write that I should reconsider my solution and think about why a pointer might be better than a passed variable. There are discussions, the same feeling I used to have when using the USENET to seek help with programming issues.

If programming courses are better online than on-campus, either the STEM fields are approaching online education more effectively… or their traditional courses are particularly horrible. Twice a month, a join local "Cocoaheads" (http://cocoaheads.org) to discuss software development. A few weeks ago, members were discussing how mediocre their university programming courses had been — there seemed to be a consensus that professors didn't understand "real world" programming. The MOOCs, it was suggested, seem to be addressing the problems developers encounter as practitioners. When I asked about other courses, the programmers talked about the joys of traditional courses in music, history, and literature. They preferred online coding courses and face-to-face humanities courses.

Maybe writing instructors do embrace more effective pedagogies than STEM fields. We certainly serve more students (every student, at many campuses) and we must do so without failing half our classes — or we would be considered failures, too.

For STEM fields, the "distance" offered by virtual settings seems to help students. In writing courses, that same distance is a detriment to our dominant pedagogies. Are current STEM pedagogies simply that bad?

Again, I am merely brainstorming on these issues because I still prefer teaching writing in a classroom, while I prefer learning new programming content online. There must be an explanation, especially since I am not alone in these biases. And I do teach online and hybrid writing courses… but they seem less engaging than face-to-face writing courses, no matter how many extras I enable — forums, chats, video, podcasts, and so forth.