Loops, Curly Brackets and the Power of Repeating Code

In week 2, Nick explained “for loops” and how they allow simple commands of code to do much larger things. Part of the learning process included recognizing two major grammatical clues or code syntax, the curly brace, { , and the double forward slash, //.

If you have ever looked at a page of code and wondered what all these dangling wiggly lines are for then you are not alone. This curly bracket, or brace, begins a code function called a loop. In particular we were introduced to a “for loop” which repeats a given piece of code over and over for a defined set of items until it sees a right brace, }. In our case, it was for all the pixels in a digital image. Last week, we learned how to manipulate the color of one pixel at a time and the “for loop” enabled us to do this for all the pixels modifying the whole image.

The full example would look something like this:

image = new SimpleImage(“51020-banana.png”);
for (pixel: image) {
// your code here
pixel.setRed(pixel.getRed() * 20);
pixel.setGreen(pixel.getGreen() * 5);
pixel.setBlue(pixel.getBlue() * 10);
}

print(image);

I now understand that the brackets contain code that is meant to modify the Red, Green, and Blue values for one pixel and repeat it until all the pixels are changed in the image.

Also important to know is that the two forward slashes  //  signify a comment that is purely for human eyes and will be ignored by computers until the next line.

Understanding these two “grammar” points of computer code have helped me to make more sense of what I see when I look at code.

Advertisements
Posted in Programming, Syntax | Tagged | Leave a comment

Software Tip of the Code Iceberg

The week 1 introduction was already very helpful because it opened up the basic rules and syntax to how computer code works and made some of the functions of software I use, like Photoshop and CONTENTdm, more clear. The examples were demonstrations of how Javascript works (because it only needs a browser to work) with simple commands like “print”.

One example code snippet looked like this: print (1,2).

The computer will then spit out this: 1 2

R G B GraphicPhotoshop and Digital Images

Some concepts I already had a good grasp of like the RGB model of how color is produced on a computer where each of the three color channels; Red, Green, and Blue, have a value from 0 to 255. I hadn’t seen the RGB Color Explorer tool that he used that is similar to RGB Explorer from the Wolfram Demonstrations Project by Jon Perry

The programming piece that Nick Parlante explained so clearly was how a program can target individual pixels in an image and change their color or size and it gave me better insight into how Photoshop works on a much larger scale.

Green XSyntax and Error Messages and Algebra, Oh My

The explanation that was given about the ways that computers understand lines of code and how the error messages don’t always seem to make sense really clicked for me. When working with lots of metadata and trying to load it into CONTENTdm with a tab-delimited text file one can get very frustrated with the error messages and their lack of helpful information. I have more understanding of why it is difficult to give clear feedback on what went wrong and how diligent you have to be with details like punctuation that can make or break a line of code. I also see how the concept of variables and the way that learning algebra allows you to do more advanced functions in computer code, so I do have to dredge it up from its deep junior high grave in my brain. X = [whatever you want it to be] allows you to do lots of functions and change many things efficiently if you’ve coded correctly.

Computer Coding is People!

I appreciated the perspective that the professor gave on how computers are powerful in a certain way, such as their ability to quickly complete a massive amount of commands, but they are dumb in that they simply carry out mechanical commands and need specific syntax in their code to be able to function correctly. It takes human creativity to see a specific problem or function and figure out how to tell a computer to do it in computer language. As a librarian, I have many problems that I want to solve or cool features that I would like to provide to people but I need to learn to speak better computer to do it.

Posted in Programming, Software | Tagged | Leave a comment

Free Professional Development from Stanford University

Those of us in higher education and librarianship are hyper-aware that things are changing rapidly. The practice of librarianship is increasingly dependent upon computers and higher education is increasingly feeling the pressure of economic and technological cultural shifts demonstrated in the emergence of digital humanities, mobile technologies, and efforts towards more effective and engaged assessment. David Lankes’ Atlas of New Librarianship is one of several model discussions engaging the changing environment for librarians and, among other issues, calls for more competency in Computer Science.

One way to engage is to dive right in. New models of free access to higher education are emerging in the form of Khan Academy, Academic Earth, or Coursera, of which the latter  was introduced in an NPR article on April 18.   Coursera is a partnership between Stanford University, University of Michigan, University of Pennsylvania, and Princeton University to provide some of their courses to anyone who is interested for free.

CompuComputer Science 101 Stanford Universityter Science skills, like programming and database administration, are increasingly necessary as a core skill for librarians and what better way to learn new skills and engage some of the new models of education than taking a free class? This is what motivated me to enroll in Stanford University’s Computer Science 101 taught by Nick Parlante. I hope to be able to better engage my colleagues in IT and to be a better Digital Librarian after this experience. Week 1 is not over until May 1st, will you join me?

Posted in Higher Education, Open Education | Tagged | Leave a comment