| Part 1 | Syntax |
|---|---|
| Part 2 | How to Install |
| Part 3 | Playground |
| Part 4 | Pros & Cons |
Roadmap
Ruby is a dynamic, open source programming language with a focus on simplicity and productivity. It has an elegant syntax that is natural to read and easy to write.
1. Ruby
1.1 Syntax
1.1.1 Functions
def hello()
puts("Hello, World!")
end
def returns()
return 2
end
>>> hello()
Hello, World!
>>> puts(returns())
2
1.1.2 Strings
def hello_with_name(name)
puts("Hello, #{name}!")
end
>>> hello_with_name("Netsoc")
Hello, Netsoc!
1.1.3 Loops
def three_little_pigs()
3.times do
puts("Little Pig")
end
end
def list_print()
[1, 2, 3].each do | number |
puts(number)
end
end
>>> three_little_pigs
Little Pig
Little Pig
Little Pig
>>> list_print
1
2
3
1.1.4 Classes
class NetsocCommittee
@members = []
@@society = "Netsoc"
def initialize(members)
@members = members
end
end
>>> class String
... def hello()
... puts("Hello, World!")
... end
... end
>>> "hi".hello()
Hello, World!
1.1.5 ?!
>>> l = [3, 2, 1]
>>> l.sort()
[1, 2, 3]
>>> puts(l)
[3, 2, 1]
>>> l.sort!()
>>> puts(l)
[1, 2, 3]
>>> puts(l.empty?())
false
1.1.6 Sugar
# Extra cool operators
x = 2
unless x == 1 # if x != 1
puts "X is not equal to 1"
end
# Optional return statement
def optional_returns()
2
end
>>> puts(optional_returns())
2
# Optional parentheses
def hello_without_parens(name)
"Hello, #{name}"
end
>>> puts hello_without_parens "Netsoc"
Hello, Netsoc!
1.2 How to Install
# Ubuntu / Debian
$ sudo apt install ruby-full
# CentOS / Fedora / RHEL
$ sudo yum install ruby
# Gentoo
$ sudo emerge dev-lang/ruby
# Arch
$ sudo pacman -S ruby
# MacOS
$ brew install ruby
1.3 Playground
| Nice looking syntax with minimal punctuation |
| Extension of existing classes |
| Everything is an object and has methods |
1.4.1 Pros
| Sometimes there are too many ways to do things |
| Relatively slow (which leads me to my next point) |
1.4.2 Cons
Fast as C, slick as Ruby
2. Crystal
2.1 Syntax
2.1.1 Type Definitions
def get_two : Int32
return 2
end
x = get_two
y : (Int32 | Nil) = nil
2.1.2 Macros
macro make_method(name, message)
def {{name}}
puts {{message}}
end
end
make_method netsoc_crystal, "Crystal is cool!"
# def netsoc_crystal
# puts "Crystal is cool!"
# end
>>> netsoc_crystal
Crystal is cool!
2.2 How to Install
# Ubuntu / Debian
$ curl -sSL https://dist.crystal-lang.org/apt/setup.sh | sudo bash
# CentOS / Fedora / RHEL
$ curl https://dist.crystal-lang.org/rpm/setup.sh | sudo bash
# Gentoo
$ sudo emerge -a dev-lang/crystal
# Arch
$ sudo pacman -S crystal shards
# MacOS
$ brew install crystal
| All Ruby pros |
| Static typing and compile time type checking |
| Faster than Ruby (and a good few others) (beware) |
2.4.1 Pros
| Not fully released yet, regular breaking changes |
| Multiprocessing isn't fully working yet |
| No Windows support |
2.4.2 Cons
your_questions = [] of Questions
your_questions.each do |question|
self.answer question
end
freyamade.netsoc.co/techtalks/languages
github.com/freyamade/netsoc-languages-talk