# Ruby Quick Start (2) -- Objects in Ruby

《Ruby语言入门教程v1.0》笔记（2）

## 第四章 Ruby面向对象初探

### 1. 封装

initialize 是初始化方法，相当于构造函数。

# Ruby Quick Start (1) -- A Glimpse of Syntax

(1) 我为什么要学习Ruby？

(2) 为什么选择Ruby，而不是Python，PHP？

• 假如你想帮他尽快找个活儿， 赚到钱， 推荐 PHP
• 假如你想让他成为一个高效工程师， 推荐 Python
• 假如你想让他爱上他的工作， 推荐 Ruby

# 《编写高质量代码：改善C++程序的150个建议》读书笔记(2)

《编写高质量代码——改善C++程序的150个建议》读书笔记(1)

## 第二部分 编码习惯和规范篇

### 建议82：积极使用const为函数保驾护航

const的真正威力体现在几个方面：

1. 修饰函数形式的参数：const只能修饰输入参数，对于内置数据类型的输入参数，不要将“值传递”的方式改为“const 引用传递”；
2. 修饰函数返回值；
3. 修饰成员函数：用const修饰成员函数的目的是提高程序的健壮性。const成员函数不允许对数据成员进行任何修改。

1. const对象只能访问const成员函数，而非const对象可以访问任意的成员函数；
2. const对象的成员是不可修改的，然而const对象通过指针维护的对象却是可以修改的；
3. const成员函数不可以修改对象的数据，不管对象是否具有const性质。

# 《编写高质量代码：改善C++程序的150个建议》读书笔记(1)

## 第一部分 语法篇

### 建议1：区分0的4种面孔

1. 整型0，32位（4个字节）；
2. 空指针NULL，指针与int类型所占空间是一样的，都是32位；
3. 字符串结束标志’\0’，8位，一个字节，与’0’有区别；
4. 逻辑FALSE/falseFALSE/TRUEint类型，而false/truebool类型。

### 建议5：不要忘记指针变量的初始化

1. 可以将其初始化为空指针0(NULL)；
2. 对于全局变量来说，在声明的同时，编译器会悄悄完成对变量的初始化。

### 建议6：明晰逗号分隔表达式的奇怪之处

1. 在使用逗号分隔表达式时，C++会确保每个表达式都被执行，而整个表达式的值则是最右边表达式的结果
2. 在C++中，逗号分隔表达式既可以用作左值，也可以用作右值

# Notes of Scala course on Coursera -- Week 2 (3)

Here are my notes for the week 2’s lecture of Functional Programming Principles in Scala on Coursera.

## 1. Functions and Data

### 1.1 Classes

In Scala, a class ia defined like this:

This definition introduces two entities:

• A new type, named Rational .
• A constructor Rational to create elements of this type.

# Notes of Scala course on Coursera -- Week 2 (2)

Here are my notes for the week 2’s lecture of Functional Programming Principles in Scala on Coursera.

## 4. Example: Finding Fixed Points

### 4.1 Finding a fixed point of a function

A number x is called a fixed point of a function f if

$f(x)=x$

For some functions f we can locate the fixed points by starting with an initial estimate and then by applying f in a repetitive way.

$x,f(x),f(f(x)),f(f(f(x))),...$

until the value does not vary anymore (or the change is sufficiently small).

# Notes of Scala course on Coursera -- Week 2 (1)

Here are my notes for the week 2’s lecture of Functional Programming Principles in Scala on Coursera.

## 1. Recursion and Tail Recursion

### 1.1 Examples of Recursion

gcd(14, 21) is evaluated as follows:

Another example:

factorial(4) is evaluated as follows:

### 1.2 Tail Recursion

Implementation Consideration:

If a function calls itself as its last action, the function’s stack frame can be reused. This is called tail recursion.

Tail recursive functions are iterative processes.

In general, if the last action of a function consists of calling a function (which may be the same), one stack frame would be sufficient for both functions. Such calls are called tail-calls.

# Notes of Scala course on Coursera -- Week 1

Here are my notes for the week 1’s lecture of Functional Programming Principles in Scala on Coursera.

### Evaluation of Programming

Every non-trivial programming language provides:

• primitive expressions representing the simplest elements
• ways to combine expressions
• ways to abstract expressions, which introduces a name for an expression by which it can be referred to

A non-primitive expression is evaluated as follows:

1. Take the leftmost operator
2. Evaluate its operands (left before right)
3. Apply the operator to the operands

A name is evaluated by replacing it with the right hand side of its definition.

Example:

Definition can have parameters:

Parameter and Return Types:

Evaluation of Function Applications

1. Evaluate all function arguments, from left to right.
2. Replace the function application by the function’s right-hand side, and, at the same time,
3. Replace the formal parameters of the function by the actual arguments.

Example:

### The substitution model

The scheme of expression evaluation is called the substitution model.

The idea is that all evaluation dose is reduce an expression to a value.

It can be applied to all expressions, as long as they have no side effects.

The substitution model is formalized in the λ-calculus, which gives a
foundation for functional programming.

# Start Learning Scala

Wikipedia上指出：

• imperative programming(命令式编程)
• functional programming(函数式编程)
• logic programming(逻辑式编程)
• object-oriented programming(面向对象编程)