📜  Ruby和C++之间的异同

📅  最后修改于: 2021-05-30 17:14:30             🧑  作者: Mango

C++和Ruby之间有很多相似之处,其中一些是:

就像C++一样,在Ruby中…

  • 与C++中一样,公共,私有和受保护的作品在Ruby中也类似。
  • 继承语法仍然只是一个字符,但在Ruby中,它是<而不是:。
  • 在C++中使用“命名空间”的方式类似,我们可以将代码放入ruby的“模块”中。
  • 与C++中一样,在Ruby中也有许多类似的运算符。
  • 尽管已更改了关键字名称以保护无辜者,但异常的工作方式与此类似。

    Ruby和C++之间的区别。

    Ruby C++
    In Ruby, every variable is just an automatically dereferenced name for some object which means that there is no explicit references in Ruby. Unlike Ruby there is explicit references in C++.
    Objects are strongly but dynamically typed in Ruby. Objects are not strongly typed as that in Ruby.
    The “constructor” is called initialize instead of the class name. This is not the case in C++.
    Array and Hash are only two container types. There are many container types in C++.
    There’s no need of C++ templates. No casting either required. C++ templates are necessary here. Casting is there.
    It’s self instead of this. It is this instead of self.
    Iteration is done a bit differently. In Ruby, you don’t use a separate iterator object. Instead you use an iterator method of the container object that takes a block of code to which it passes successive elements. Vectors are required and used in C++ which makes the coding easy.
    lib, a unit testing, comes standard with Ruby. This is not available with C++.
    There’s no type conversions in Ruby. Type conversion is necessary in C++.
    There are some enforced case-conventions. No such case conventions are present in C++ which makes it easy.
    You can re-open a class anytime and also you can add more methods in Ruby. We cannot do this in C++.
    Some methods end in a ’?’ or a ’!’ in Ruby. It’s actually part of the method name. No such symbols are required at the end of methods in C++.
    All methods are always virtual in Ruby. Methods are not virtual in C++.
    Multithreading is built-in, but as of Ruby 1.8 they are “green threads” as opposed to native threads. Multithreading is not built-in in case of C++.
    Parentheses used for calling of method are usually optional in Ruby. Parentheses are required in C++ and it is necessary.
    You don’t directly access member variables—all access to public member variables is via methods. Member variables in C++ can be access directly.
    要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程”