Skip to content

Commit 7431e5d

Browse files
committed
cleanup
1 parent ad5a1f4 commit 7431e5d

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

readme.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,11 @@ Source: [http://www.artima.com/intv/rubyP.html](http://www.artima.com/intv/rubyP
8585

8686
With more freedom and less syntactical rules, many Rubyists believe that Ruby is a much more elegant language - and it is. Also, while Python focuses on simplicity, Ruby focuses on making the programmer happy, while this tends to be true and people can make truly beautiful programs, you can also often see messy code (especially from beginners) that can be difficult for other developers to read( or even themselves in a not so distant future). For example, you can put multiple statements on one line. This can look good and be readable, depending on how it's coded - or it can be a mess.
8787

88-
###The principle of least astonishment
88+
### The principle of least astonishment
8989

90-
One princpiple very present in the design of Ruby is the principle of least astonishment, it's basically about the language working the way you think it should, thinks like using a function with a strange name will leave you astonished, and will make you look in the documentation.
91-
In order to behave like this Ruby tends to do things like having the same functions with different names,however some people would argue this is confusing for beginners. Also, Python , although not having this principle in mind when making the language, also behaves quite like this by make pretty much everything work in a standard way, however one could say this only benefits advanced Python users.
90+
One principle very present in the design of Ruby is the [principle of least astonishment](https://en.wikipedia.org/wiki/Principle_of_least_astonishment) - the language working the way you think it should.
91+
92+
In order to behave like this Ruby tends to do things like having the same functions with different names, which can be confusing for beginners. Although Python does not have this principle in mind when making the language, it also behaves quite like this by make pretty much everything work in a standard way. One could argue that this only benefits advanced Python users, though.
9293

9394

9495
Let's compare some code. The following snippets of code are for solving the Fibonacci sequence:
@@ -97,8 +98,8 @@ Let's compare some code. The following snippets of code are for solving the Fibo
9798

9899
```ruby
99100
def fib(n)
100-
return n if n < 2
101-
fib(n-1) + fib(n-2)
101+
return n if n < 2
102+
fib(n-1) + fib(n-2)
102103
end
103104
alias :fibonacci :fib
104105
```
@@ -113,7 +114,11 @@ def fib(n):
113114
return fib(n-1) + fib(n-2)
114115
```
115116

116-
Although you can write this code in many ways, both of these methods are *true* to the language, Ruby code demonstrates the practice of having multiple names for the same function (fib and fibonacci are the same). In other words, the Ruby example is very Ruby-ish while the Python example is very Pythonic. Can you read the Ruby code? It may be more elegant but it's a bit harder to read. Meanwhile, it's easy to follow the Python code, right? You of course can write code anyway you want. It's advisable to write Ruby code, when beginning, in a more Pythonic way - which simply means making it more readable:
117+
Although you can write this code in many ways, both of these methods are *true* to the language.
118+
119+
> The Ruby code demonstrates the practice of having multiple names for the same function (`fib` and `fibonacci` are the same).
120+
121+
In other words, the Ruby example is very Ruby-ish while the Python example is very Pythonic. Can you read the Ruby code? It may be more elegant but it's a bit harder to read. Meanwhile, it's easy to follow the Python code, right? You of course can write code anyway you want. It's advisable to write Ruby code, when beginning, in a more Pythonic way - which simply means making it more readable:
117122

118123
```ruby
119124
def fib(n)
@@ -174,7 +179,7 @@ In the first example (Python), we are importing the `Twitter()` class from the `
174179

175180
#### Programming Paradigms
176181

177-
Again, you can use the same paradigms in both languages (procedural, functional, object oriented ...). When it comes to object oriented programming, Ruby used to have the upper hand, as it was built specifically for object orientation. That said, Python has moved more towards being a true object orientated language over the last few years. However, Ruby has one advantage, Ruby can add methods to existing classes, Python by default can't do this (although it's possible with the use of a external library)
182+
Again, you can use the same paradigms in both languages (procedural, functional, object oriented ...). When it comes to object oriented programming, Ruby used to have the upper hand, as it was built specifically for object orientation. That said, Python has moved more towards being a true object orientated language over the last few years. However, Ruby has one advantage, Ruby can add methods to existing classes, Python by default can't do this (although it's possible with the use of external libraries).
178183

179184
#### Performance
180185

0 commit comments

Comments
 (0)