Saturday, November 19, 2011

Exercise 22: What Do You Know So Far?: Learn Ruby the Hard Way: Practicum

This is kinda' funny. Just as I finished up the Extra Credit project for yesterday, I was thinking to myself "self, you should go through and make a program, a somewhat longer one, that actually uses everything you've learned up until now, and perhaps you should use this program as a longer term "memory repository" so that you can work with it, refactor it, toy some more with it each day so taht it ultimately becomes a sum of the knowledge of your Ruby experience". OK, seems like a simple enough thing to do... why it is considered funny?

Because it seems Zed is of a similar mind, and at this very same point, too (BTW, I am deliberately doing these exercises in order, and I am wherever possible "not reading ahead". This way, I can aproach the exercise fresh, without pre-conceived ideas, and you, dear reader, get to be the beneficiary of my Guinea piggery :) ).

In this Exercise (and the next one), there's no code to learn or pratice with. Instead, we'l be taking a look back at the things we've aleady learned (and it's actully quite a bit, if I do say so myself).

First, go back through every exercise you have done so far and write down every word and symbol (another name for ‘character’) that you have used. Make sure your list of symbols is complete.


[Whoa! Now that's a tall order (LOL!)... let's see how well I did:


# (octothorpe) - used as a "comment" character; anything that follows is not seem by the interpreter
#{$0} - from the command line, the name of the script you are running
#{variable} - used for string interpolation, substitiutes the vaue for variable in a statement 
$ - prepends a variable from the command line ($0 is the actual name of the script run)
% - percent (modulus in math, string variables in puts & print statements)
%d - represents a digit in a text string
%s - represents a string of text in a test string
( ) - used to encapsulate arguments to functions
* - asterisk used for multiplication
+ - plus used for additionand string concatenation
- - minus used for subtraction 
/ - slash used for division
< - less-than 
< < TEXT (ignore the spaces, they are there so this will print) - start code for a block of text. TEXT on its own line ends it.
<= - less-than-equal 
> - greater-than 
>= - greater-than-equal
ARGV - the argument value (constant), holds arguments entered on the command line
File - used to define and enact file options
File.close() - close a file
File.exists? - check to se if a file already exists or not
File.open() - opens a file for use
File.open(filename, 'w') - specifically opens a file for writing
File.read() - reads the contents of a file
File.readline() - reads a specific numbered line in a file
File.seek() - locate a particular spot in the file
File.truncate() - used to remove the contents of a file
File.write() - write line or characters to a file
STDIN - used with methods when ARGV is used as well, to differentiate between the two
[ ] - used to seprate arguments from puts and print statements
\\ - escapes a backslash
\n - newline character
\t - inserts a tab
chomp - used typically with gets. Removes the newline character froma line of text
do - reflects the start of a block of code to be run together
end - closes a block section of code
gets - get a string from standard input (usually the keyboard)
open - open a file or URL
print - takes text and displays it on the screen, no new line applied.
puts - used to "put" a "string" of characters on the screen along with a newline
variable - a variable value, useful for identity purposes
]

Next to each word or symbol, write its name and what it does. If you can’t find a name for a symbol in this book, then look for it online. If you do not know what a word or symbol does, then go read about it again and try using it in some code.

Once you have your list, spend a few days rewriting the list and double checking that it’s correct. This may get boring but push through and really nail it down.

Once you have memorized the list and what they do, then you should step it up by writing out tables of symbols, their names, and what they do from memory. When you hit some you can’t recall from memory, go back and memorize them again.

What You are Learning

It’s important when you are doing a boring mindless memorization exercise like this to know why. It helps you focus on a goal and know the purpose of all your efforts. In this exercise you are learning the names of symbols so that you can read source code more easily. It’s similar to learning the alphabet and basic words of English, except that Ruby’s alphabet has extra symbols you might not know.

[I can see the value of doing this. Just going through and looking at these options it helped me really think "OK, so *that's* why that is being used there". Honestly, I've never done this with a language before. It's tedious, but I can say I think it'll be worth it. Loks like I'll be doing this for quite some time ;) ]

2 comments:

Droz said...

Looks like you missed "def" in your list!

Nice, concise definitions, however!

Droz said...

... *and* you left out "require"