Document directory
- About Style
- About Dynamics
- Structure
- Others
- Usage
/*************************************** *
Call by name
Everything is an object and never closes
Hook everywhere
Yield/block/proc/Lambda, first-class citizen
Symbol and hash
Modules, classes, and instances can be assembled at will.
****************************************/
About Style
There is no distinction between primitive type and class type.
Classes and objects are never closed. You can add methods to existing classes at any time to make them more expressive and readable.(3. Hours instead of time. Hours (3 ))
Symbol, perfect logo
Create a word and plane in a hash table to simulate naming parameters.
Simple but not simple, arrays and hash are almost everything.
Parameter List, parentheses can be omitted
Block parameter, local extension, no need to inherit or define a separate function.(Eliminates the need for anonymous internal classes in Java)
Proc is a first-level citizen, perfect combination of object and Function
About Dynamics
Call by name, duck typing, rather than by type: the two dynamic languages I use are like this: Python and Ruby. inheritance is completely an optional means of code reuse in such languages, rather than the core object-oriented mechanism. the essential feature of object orientation is actually a polymorphism.
Call by name, that is, the runtime generic.(From the perspective of C ++ programmers)
Classes and objects are never closed. You can add behaviors that are not supported by them at any time.
Hooks during execution. You can hook your code in key steps. The most widely used method_missing.
Almost all statements are called functions and are interpreted at runtime.
Interpreter-level primitives, such as send (: method_name), response_to? (: Method_name), block_given? Frozen? And so on
Interpreter-level knowledge, or metadata, all information about objects
Any existing function can be redefined, including operators.(We recommend that you do not redefine the core class methods for global impact)
Structure
Class and object are never closed
Use modules to model concepts, capabilities, and behaviors, and use modules to assemble classes.
The module is actually a generic algorithm.(From the perspective of C ++ programmers)
Duck typing is the concept in the template. It requires parameters in terms of "Capability" rather than "type" (from the perspective of C ++ programmers)
Container/iterator/block, similar to STL container/iterator/functor, is only language-level support, one is class library-level support, and the other is inherent, one is the invention of the day after tomorrow, which has a huge impact on users. It can only be said that STL is too late.
In a dynamic language, the type only organizes the code logic during design. It is a modeling method for the problem, and it does not matter during runtime. traditional interfaces, one of the core object-oriented concepts, become dispensable. the original interface inheritance and implementation inheritance only play a role, while Mixin is equivalent to multiple implementation inheritance.
Inheritance plays a role in the exception system because sometimes only the entire rescue level is required.(Is there no other method to replace inheritance for exception handling ?)
Others
. Freeze, const, fully automated unmodifiedlist, unmodifiedmap...
Method (: method_name), instance_method (: method_name), get the function pointer, and then bind it to different objects.
Protected and private are controlled to objects.
Proc and lambda. In the current version, both proc and Lambda are closures, but the return in Proc, like the return in macro in C/C ++, will jump out of the caller's function body.
Parallel value assignment a, B = B,
The default parameter can reference the previous parameter.
Range, which was previously included in <Analysis Mode>. It is estimated that it has been implemented countless times, and Ruby has finally built in support.
Yield: Used to implement iterator, template method
Block, Proc, lambda: can be used as the carrier of command and Strategy
The value of the value assignment statement is always the value of the parameter, rather than the return value of the method.
Does not automatically add the self. prefix to the attribute assignment function, but uses it as a local variable.
Usage
Use the hash with the symbol as the key to simulate the keyword argument
Self is preferred in the class, without the class name
The query method must contain? , The modification method must include!