ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
Fundamentals
of coding
Yeah, It's really true!
We will use Ruby in our examples.
Because...
10.times { puts "Hello world!" }
class HelloWorldApp {
public static void main(String[] args) {
for(int i = 0; i < 10; i++) {
System.out.println("Hello World");
}
}
}
Important question.
Why is coding so difficult?
Important question.
Why is coding so difficult?
In fact, it's not!
The start of a new day.
The start of a new day, in Ruby.
if alarm.is_ringing? # Asking alarm if it is ringing
self.wake_up() # Waking up
self.do_gymnastics(1.minute)
if self.need_to_go? # Asking yourself.
car.start_engine()
if self.saw(stopSign) # One more conditional
self.stop_car()
end
end
end
Nouns vs Verbs.
Nouns are objects.
Nouns can do things.
The verb is called a method or function.
The verb actually do things.
God creating human beings.
God creating human beings.
Now using blueprints (classes).
Classes.
class Human
def initialize(name, intelligence)
@name = name
@intelligence = intelligence
end
end
adam = Human.new( "Adam", 10 )
eve = Human.new( "Eve", 9 )
3000000000.times do | i |
Human.new( "Eve #" + i.to_s, rand(100) )
end
Inheritance.
Inheritance.
class Woman < Human
attr_accessor :surname
def gossip()
@intelligence = @intelligence + 1
end
end
class Man < Human
def gossip()
@intelligence = @intelligence - 10
end
end
Encapsulation.
Encapsulation.
class Woman < Human
attr_accessor :surname
def gossip()
@intelligence = @intelligence + 1
end
end
class Man < Human
def gossip()
@intelligence = @intelligence - 10
end
end
Polymorphism.
Polymorphism.
class Woman < Human
attr_accessor :surname
def gossip()
@intelligence = @intelligence + 1
end
end
class Man < Human
def gossip()
@intelligence = @intelligence - 10
end
end
Object Oriented Programming at a
glance.
Together:
¡ñ Encapsulation
¡ñ Inheritance
¡ñ Polymorphism
make up the fundament of OOP.
End.
Thank you.

More Related Content

Fundamentals of coding