« CFP: Memphis Law Review: (How Much) Should We Pay Them? | Main | Does lawyering matter? »

Sunday, September 04, 2022

An Old Law Prof Learns to Code - Part 1 - Introduction

image from youtu.beI'm stretching for the segue, but references to Markie seem to be popular.  (I  took the video at the left to prove to my skeptical wife that he did in fact come when I called.) 

The horse segue is this: I had never gotten on a horse, except for maybe a pony ride when I five, until 2009, when I was 55.  A friend here in Michigan had a horse, there was a gorgeous riding facility nearby, and it looked cool.  I knew vaguely that there was a difference between English and Western riding but that was it.  I knew nothing about dressage versus hunter-jumper versus eventing versus equitation versus Western Pleasure versus barrel racing.  So I asked somebody "what discipline I should learn?"  The response was to learn English because it was easier to go to Western if one didn't like it than the other way round.

If you know anything about computer coding, I apologize for the ensuing naïveté. You are entitled to react "duh, of course that is how it works."  But, as with riding, I knew there was C++ and Python and Java (which I didn't know had no relation to JavaScript) but I had no idea what that meant.  As I mentioned before, my ventures in the guts of coding (since a couple days of BASIC in high school) were pretty much limited to inserting a hyperlink into a blog comment for the purpose of shameless self-promotion of articles I had posted on SSRN.  I certainly had no experience with anything that looked like this (see below the break for some more on this):

//Fahrenheit Celsius Conversion//
#include <stdio.h>
int main(void)
{
int Fahrenheit, Celsius;
printf("Enter a Fahrenheit temperature as an integer:");
scanf("%d", &Fahrenheit); Celsius = (Fahrenheit - 32)/1.8;
printf("\n %d Fahrenheit equals %d Celsius. \n\n", Fahrenheit, Celsius);
return 0;
}

When I started the exercise in June, I just wanted to see what coding involved, but I also wanted a goal. I came up with the idea of encoding the exercise I use in Business Entity Fundamentals to teach income statements and balance sheets to law students and then somehow to deliver it to them.  It's not pretty, but I created something you can see here.

More importantly, I had a number of "aha" moments about similarities both in (1) the logic of coding and lawyering, something I've written about extensively, and (2) the practice of each skill.  But I don't want to bury that lede, so wait for "Part 2 - Aha Moments."

If you are curious and are on a MacBook, try the following.  Good luck.

1. Copy this from the first // to the last } :

//Fahrenheit Celsius Conversion//
#include <stdio.h>

int main(void)
{
int Fahrenheit, Celsius;
printf("Enter a Fahrenheit temperature as an integer:");
scanf("%d", &Fahrenheit); Celsius = (Fahrenheit - 32)/1.8; //note the silent conversion
printf("\n %d Fahrenheit equals %d Celsius. \n\n", Fahrenheit, Celsius);
return 0;
}

2.  Open Word or Pages on your computer and paste it.  Save the document on your Desktop but as a .txt (Plain Text) file.  Call it something like "demo" (don't use the quotation marks).

3. It will show up on your Desktop as an icon.  Click on the name "demo" and change it to "demo.c" (without the quotation marks).  The computer will ask if you really want to do that.  Say yes, "use .c".

4.  Go up to the top right of the menu bar and open the search function (the magnifying glass).

5.  Where it says "Spotlight Search", type in: terminal  ... then hit "return".  A window will open up with a line that looks like this: ~>

6.  Type in:  cd desktop  ... then hit "return."  It should return a line like this: ~/desktop>

7.  You now are in your Desktop directory.   At the prompt, type in:  gcc -o demo demo.c   then hit "return." You have now asked the computer to translate that language you saved as demo.c into a new file called "demo" that consists of binary code of zeroes and ones.  If all went well, it will return a line like this: ~/desktop>   If you did anything wrong, it will spit out error messages.*

8.  If you type in ./ and then the program name at the prompt, the computer will execute the program.  So, at the ~/desktop> prompt, type in: ./demo

9.  You have written and executed a program that converts Fahrenheit temperatures to Celsius.  The computer will ask you to enter a Fahrenheit temperature as an integer.  If you do and hit return, it will give you the answer.

* My colleague and law and coding guru David Colarusso observes that computers are like the most anal and obnoxious cite-checking law review editor you've ever encountered.  Even posting this exercise, I made several mistakes along the way, like forgetting to include > after "stdio.h" (which, by the way, tells the program to include the standard input-output code from the C language).

Posted by Jeff Lipshaw on September 4, 2022 at 08:57 AM in Lipshaw, Teaching Law, Web/Tech | Permalink

Comments

I read it up to the point where you stop talking about horses😎

Posted by: Lynn Friendly | Sep 4, 2022 4:51:25 PM

Post a comment