Skip to content

Seven Languages in Seven Weeks

Metadata

  • Author: [[Tate, Bruce A.]]

Highlights

So, everything but nil and false evaluate to true. C and C++ programmers, take note. 0 is true! — location: 602 ^ref-5928


Ruby is strongly typed,[3] meaning you’ll get an error when types collide. — location: 662 ^ref-47635


Ruby does not do type checking until you actually try to execute code. This concept is called dynamic typing. — location: 678 ^ref-7792


Duck typing doesn’t care what the underlying type might be. If it walks like a duck and quacks like a duck, it’s a duck. — location: 698 ^ref-15369


Duck typing is extremely important when it comes to clean object-oriented design. An important tenet of design philosophy is to code to interfaces rather than implementations. If you’re using duck typing, this philosophy is easy to support with very little added ceremony. If an object has push and pop methods, you can treat it like a stack. If it doesn’t, you can’t. — location: 699 ^ref-34699


A symbol is an identifier preceded with a colon, like :symbol. Symbols are great for naming things or ideas. Although two strings with the same value can be different physical strings, identical symbols are the same physical object. — location: 843 ^ref-46926


Notice that you didn’t have to type in the braces. These braces are optional for the last parameter of a function. — location: 880 ^ref-49206


A code block is a function without a name. You can pass it as a parameter to a function or a method. — location: 882 ^ref-49253


The code between braces is called a code block. — location: 889 ^ref-33468


You’ll see Ruby libraries that use blocks to process each line of a file, do work within an HTTP transaction, and do complex operations over collections. Ruby is a block party. — location: 973 ^ref-51012


Fixnum is an instance of the class Class. — location: 1016 ^ref-38389


attr_accessor, defining an instance variable, an accessor, and a setter. — location: 1062 ^ref-58964


Object-oriented languages use inheritance to propagate behavior to similar objects. When the behaviors are not similar, either you can allow inheritance from more than one class (multiple inheritance) or you can look to another solution. Experience has shown that multiple inheritance is complicated and problematic. Java uses interfaces to solve this problem. Ruby uses modules. — location: 1078 ^ref-63429


The interesting thing about all these metaprogramming techniques is that your programs can change based on the state of your application. ActiveRecord uses metaprogramming to dynamically add accessors that are the same name as the columns of the database. — location: 1501 ^ref-47239


Io is a prototype language like Lua or JavaScript, meaning every object is a clone of another. — location: 1587 ^ref-65375


I found that after Io, I had a much stronger understanding of how JavaScript worked. — location: 1593 ^ref-13516


With Io, you won’t worry about both classes and objects. You’ll deal exclusively in objects, cloning them as needed. These clones are called prototypes, and Io is the first and only prototype-based language we’ll look at. In a prototype language, every object is a clone of an existing object rather than a class. — location: 1601 ^ref-3157


Types in Io are just conveniences. Idiomatically, an object that begins with an uppercase name is a type, so Io sets the type slot. — location: 1698 ^ref-61610


In Ruby and Java, classes are templates used to create objects. For example, bruce = Person.new creates a new person object from the Person class. They are different entities entirely, a class and an object. Not so in Io. bruce := Person clone creates a clone called bruce from the prototype called Person. Both bruce and Person are objects. Person is a type because it has a type slot. In most other respects, Person is identical to bruce. Let’s move on to behavior. — location: 1718 ^ref-48474