Pokazywanie postów oznaczonych etykietą book. Pokaż wszystkie posty
Pokazywanie postów oznaczonych etykietą book. Pokaż wszystkie posty

niedziela, 19 czerwca 2011

Kod, który zawsze działa!

Remember, a great way to avoid broken code is to have less of it. The code that you never write will work forever.
- Russ Olsen, "Eloquent Ruby" (Addison-Wesley Professional, 2011)

piątek, 17 czerwca 2011

Pisz "elokwentnie" w Rubym

Nie trudno nauczyć się nowego języka programowania. W końcu wszędzie mamy te same if-y, pętle, klasy, funkcje. Trochę czasu zajmuje oczywiście poznanie biblioteki standardowej i pewnych konstrukcji typowych dla danego języka.

Sztuką jednak poznać jest styl danego języka. Wiedzieć kiedy użyć danej konstrukcji, znać idiomy, zasady którymi rządzi się język.
 W innym wypadku jest duża szansa, że nie piszesz w Rubym, ale jakimś innym języku, który znałeś wcześniej. Wtedy trzeba sobie zadać pytanie: to po co udawać, że się pisze w Rubym?

Tutaj z pomocą przychodzi nam świetna książka - "Eloquent Ruby" autorstwa Russa Olsena 
It’s easy to write correct Ruby code, but to gain the fluency needed to write great Ruby code, you must go beyond syntax and absorb the “Ruby way” of thinking and problem solving. In Eloquent Ruby, Russ Olsen helps you write Ruby like true Rubyists do–so you can leverage its immense, surprising power.
Olsen draws on years of experience internalizing the Ruby culture and teaching Ruby to other programmers. He guides you to the “Ah Ha!” moments when it suddenly becomes clear why Ruby works the way it does, and how you can take advantage of this language’s elegance and expressiveness.
Eloquent Ruby starts small, answering tactical questions focused on a single statement, method, test, or bug. You’ll learn how to write code that actually looks like Ruby (not Java or C#); why Ruby has so many control structures; how to use strings, expressions, and symbols; and what dynamic typing is really good for.
Next, the book addresses bigger questions related to building methods and classes. You’ll discover why Ruby classes contain so many tiny methods, when to use operator overloading, and when to avoid it. Olsen explains how to write Ruby code that writes its own code–and why you’ll want to. He concludes with powerful project-level features and techniques ranging from gems to Domain Specific Languages.
A part of the renowned Addison-Wesley Professional Ruby Series, Eloquent Ruby will help you “put on your Ruby-colored glasses” and get results that make you a true believer.
Nie jest to książka, która wyjaśni nam podstawy programowania (co to jest zmienna, pętla czy obiekty). Autor zakłada, że znamy już trochę Ruby'ego na tyle żeby pisać poprawne (działające) programy. Jednak nie na tyle dobrze żeby pisać je poprawnie (zgodne z duchem Ruby'ego).

W sumie dopiero w trakcie lektury Ruby mnie zafascynował. Do tej pory był tylko "pośrednikiem" pomiędzy mną a Railsami, a sam w sobie mnie nie porywał.


niedziela, 27 marca 2011

Kick-ass language

Haskell was made by some really smart guys (with PhDs) (...) when a committee of researchers got together to design a kick-ass language.
- Miran Lipovaca "Learn You a Haskell for Great Good!: A Beginner's Guide" (No Starch Press, 2011)

niedziela, 20 marca 2011

Za granicą nie wiedzą co to ułamki zwykłe?

Książka Programming in Scala, rozdział Functional Objects, paragraf A specification of class Rational. Czytamy:


A rational number is a number that can be expressed as a ratio n/d , where `n` and `d` are integers, except that `d` cannot be zero. `n` is called the numerator and `d` the denominator. Examples of rational numbers are 1/2 , 2/3 , 112/239 , and 2/1 . Compared to floating-point numbers, rational numbers have the advantage that fractions are represented exactly, without rounding or approximation. 

The class we’ll design in this chapter must model the behavior of rational numbers, including allowing them to be added, subtracted, multiplied, and divided. To add two rationals, you must first obtain a common denominator, then add the two numerators. For example, to add 1/2 + 2/3 , you multiply both parts of the left operand by 3 and both parts of the right operand by 2, which gives you 3/6 + 4/6 . Adding the two numerators yields the result, 7/6 . To multiply two rational numbers, you can simply multiply their numerators and multiply their denominators. Thus, 1/2 ∗ 2/5 gives 2/10 , which can be represented more compactly in its "normalized" form as 1/5 . You divide by swapping the numerator and denominator of the right operand and then multiplying. For instance 1/2 / 3/5 is the same as 1/2 ∗ 5/3 , or 5/6 .

Właśnie, dzięki uprzejmości Panów Ordersky, Spoon, Venners dowiedzieliśmy się czym są ułamki zwykłe, jak je dodawać, mnożyć, dzielić i (uwaga!) skracać. Naprawdę żałuję, że zabrakło miejsca żeby nauczyć nas jak je odejmować.

Zawsze wydawało mi się, że programiści to w miarę inteligentne osoby. Przy okazji raczej uzdolnione matematycznie i w ogóle. Czyżby w Szwajcarii (skąd pochodzi Martin Odersky) ułamki zwykłe były wiedzą tajemną znaną garstce wybrańców (czytaj studentów  École Polytechnique Fédérale de Lausanne, na której M. Ordersky wykłada)?


Mówiąc szczerze bardzo rozbawił mnie ten fragment :)