Author Topic: Misc Programming  (Read 3254 times)

0 Members and 1 Guest are viewing this topic.

adarqui

  • Administrator
  • Hero Member
  • *****
  • Posts: 24327
  • im da bess mayne.
  • Respect: +4370
    • View Profile
    • Email
Misc Programming
« on: July 08, 2014, 10:35:42 pm »
0
Very nice explanation of 'functional vs imperative':
Quote
The conventional languages are based on the imperative programming
paradigm (which I’ll abbreviate to IMP). This means that the program
progresses by applying commands to a store containing the program
variables. The commands cause updates to the contents of the store. As the
program executes the store goes through a sequence of states.

In functional programming (which I’ll abbreviate to FP) there is no store
that is updated. The program progresses by computing new values from
existing values. There is nothing in pure FP that requires the existence of a
distinct store let alone an updatable one.

Referential transparency/side-effect free:
Quote
Functions that always compute the same results for the same inputs are
called pure or referentially transparent. Functions that have no other effect
than to produce their output value are called side-effect free. These properties
are closely connected.

variable, functional context
Quote
• The meaning of the word variable in FP is different. It is a name bound to
a value, not to a box holding a value. So the value associated with the
variable is steady

Pure FP and the plumbing problem
Quote
Having to pass values as arguments to every function
Passing state to every function
If no monads, need to roll your own 'version'

unit
Quote
. The type unit plays the same role as void in C

OCaml: Two types of module models: paramaterized (extensible procedures), object (extensible data)

is-a, has-a
Quote
There are two definitions we should make in order not to confuse you about inheritance. There might be two kind of relations between objects. First, an object might have been derived from another object. This is called is-a relation. For example, Car is a Vehicle. Second, an object can consist of other objects. This is called has-a relation. For example, Vehicle has a Body. The inheritance concept is related with is-a relation and not has-a relation.

oo polymorphism, oo overriding
Quote
Polymorphism
In a world full of different kinds of objects, some objects may response the same message although they are different kind of objects, meaning they are instances of different classes. That's why some programming languages allow us to define methods with same selector in different classes. Or they allow a subclass to change a selector's behavior which it inherited from its superclass. This is called polymorphism.
Note: The special case where a subclass changes the behavior of a method it inherited from its superclass is named as overriding.

oo classes
Quote
First, we should talk about what classes are made of. Classes are the blue prints of objects so they definitely should describe all the things that objects have. For example, they have instance variables to define the properties of an object. They should have method definitions to make objects responsive to some certain messages. But they have more. There are class variables. Class variables hold the information about the state of the class. There are also class methods which only classes can execute and not the instances of them.

Code: [Select]
SuperclassName subclass: SubclassName [
| instanceVariable1 instanceVariable2 |
classVariable1 := anObject.
classVariable2 := anotherObject.
<comment: 'Comment to describe our class'>
SubclassName class >> aClassMethod: aParameter [
"Comment to describe this class method"
<category: 'Category of this class method'>
| localVariable1 localVariable2 |
...
^objectToReturn
]
anInstanceMethod [
"Comment to describe this instance method"
<category: 'Category of this instance method'>
| localVariable1 localVariable2 |
...
^objectToReturn
]
]