Martin Shanghai Speech Record 3: Counting Ruby Language Excellent Disadvantages

xiaoxiao2021-03-31  207

Counting Ruby language advantages and disadvantages

Explain these these things are doing something more than a bit. But I hope to pass, use ruby ​​to experience this language. Although you can't try it yourself, you can see this series through the screen. Now I want to show another example. I hope that you can see the content you can see. If you haven't tried any scripting language before you haven't tried it, then I encourage you to learn Ruby. I think Ruby is very worth learning. Because it is easy to learn and use, just take a few minutes to learn. Another feature of the scripting language is that you can write some code, then go directly to its run results. Ruby is a very good scripting language. However, I think that Ruby's significance is not only that it is a good scripting language. I will discuss this problem in the next few minutes.

First, I hope to discuss this topic through the characteristics of Ruby. At this point, you may have experienced it from just in the example. Ruby is very simple syntax, so you don't need to write a lot of code, you can get very powerful features. From the examples just now, you can see that when you write the parameters, you don't need to write parentheses, of course, you can also have no parameters at all. This feature allows you to write code quickly, but more importantly, you can read the code quickly. We can compare the language of Java, C series, when you try to read the code, your line of sight will always be scattered, and it is not easy to figure out what is doing. A loose type check can help us quickly understand the code. Strict type checks can result in worse readability. Ruby did a good balance between this. The readability of the code is very important for Ruby, or for developers using Ruby. I think the code written by Ruby is very readable. This doesn't mean that ruby ​​is a small language, just like SmallTalk. Ruby is a very complex language. It has a lot of complex syntax characteristics, such as implementing multiple tasks in the same row code. If you have used other scripting languages, (will find) Perl and python's characteristics are taken to Ruby. These have added difficulty in learning to Ruby. This is another new balance. Expressing things in a simple language is complicated, such as SmallTalk, however, in Ruby, it is very convenient, especially in controlling Collection. In Ruby, the grammar of the List is very convenient. I didn't show the use of HashTable in Ruby, but their usage is simple.

One thing is very concerned, unlike the language of these mainstream static types like Java, C #, you don't need to define variable types in Ruby. It is a strict type. I remember that the examples we have just raised in the experiments just now, and the string type will be submitted to be prompted. But you will only be told when you run, not when compiling. So Ruby has a strict type. But its type is dynamic. So you can only find errors at runtime. This has caused the following results, many people worry that it is difficult to find type errors when writing Ruby's code, which is not as expected in Java and C #. However, I found that there is no such problem in most developers using Ruby, and they solve this problem by testing, especially unit testing. I am a support for the test, I will use a lot of tests, not in the current small demo, but in the previously slightly large project. If you use unit tests, you find that the speed of those types will be as fast as the error is found in compilation. I really like this feature, especially when using SmallTalk to build a large system at first. Only if there are few cases, the test cannot find type errors. But there is a shortcomings in such a language. When reading the code, you don't easily understand what the program has completed, because when you control this variable, you can't know which type he is. This means that Ruby has some powerful debugging tools as SMALLTalk, which can be used in the debugging environment to see the type of variable. Overall, I like this flexibility in the dynamic language. Objects can be replaced, can be used as various types in many places. But on the other hand, it improves the readability of the code. When you try to read the code, it is easier to understand. This needs to see personal preferences, and some people like to use static languages, and some people like to use dynamic languages. So, you need to pick a more favorite language. Many people think that the species is very important, I think this is not decisive.

I think that another feature of Ruby is that it has a strong object-oriented property. Perl is not an object-oriented language, although some object-oriented mechanisms have been added later. Python is not fully objective. But Ruby is an object-oriented. Here I can show another code. (Write a code). So, even NIL is also a class even in Ruby, Nothing is also an object. This is like smalltalk. The difference between an object and a substantive building type (Primitive Build Type) is that the object is all in Ruby. Although you see some of my code, you didn't see the initialized code. Ruby is set up. There is another very good example here. (Write a code). We see that we have got some big integers here. Can you use this simple statement in Java? Can't, because you need to consider that when your value increases to a certain level, how should you deal with it. It is necessary to consider things like increasing the number of bits. Interesting is that ruby ​​has done in the background, but we can't see it. Now to output its type and see what will happen. (Write code) This can make your output home. Here we see that the type of these numbers is "fixnum", which is a small integer class. When he grows to a big enough, it needs to be like a relatively large type Bignum as in Java. Therefore, the specific implementation class can be displayed. This is the advantage of the dynamic language, and it can be done better with SmallTalk, which can convert the digital type conversion score, floating point type, etc. according to your needs. So, Ruby has a very nice object-oriented background. In such a script environment, your program can have a better structure. You can have a better speed, a good mechanism, a better structure, making you better structural procedures. This is the result of continuous combination. However, all things in Ruby are good, it has its shortcomings. One of the more important issues is that it still has no very good development tool, especially after you are skilled in using its editor, it is not able to develop a environment like Java, such as Eclipse. And my favorite Intelligent J Provide a smart prompt to boot the programmer to write code. These have not existed in the community of Ruby. I have currently recommended Emacs. This is definitely a shortcoming for people. These depends on how much resources are invested. Another problem arising from this is that we cannot reconstruct it as in Java and C #. Reconstructing is more difficult in dynamic type language. This is not absolute, the first development of reconstruction functions is SmallTalk. But it is not perfect.

Another problem with Ruby is that Ruby is not fast on the block. In the standard of the scripting language, it is a slower language. But this is not a very serious problem. In our developed program, Ruby is used to call the database. Ruby has a better performance than some of the functions of the database connection and hardware. But in other aspects of Ruby is not the best. It is a common situation that people build Ruby's API to C Library, which is also the case like Perl and Python.

Another shortcomings of Ruby are dealing with Unicode. Ruby processes Unicode is very bad. The program I just actually use the ACSII type string. You can't use Unicode as a lot of people. It is not as easy as it is used. This issue will be resolved in the next release, but at least it seems that Ruby cannot support Unicode as Java and Python.

Tools and DSL to create Ruby's most interesting and most interesting places lies in its library (Framework), a framework for web development. In some projects we participate, Ruby On Rails is a web development framework that can bring high productivity. An important issue when developing enterprise applications is that the code of the database and other code are combined together. You must control these codes to make the database's request is valid. This has become a very important issue when the database is managed by different departments of the company. If you have certain controls for the database, then you can become confusing in your environment. Rails is designed specifically for certain types of applications, not to solve all problems. For example, there is a special advantage for Internet applications. Another attractive library in Ruby, this is also that I personally think it is very useful, it can manage each build version. There is a very famous in the UNIX environment, which is a program that can build a C language. Rails can help us describe a build. I will show this feature in a small window, which will be very interesting. Here is the building script on the website. Here I define tasks and dependencies. The Default task relies on all. All tasks depend on all these tasks. Here is the logic code of the task, which will perform this code. Let's look down, here there is a function of Help, here there is a Clean task. People who are familiar with Ruby codes will be familiar with these. The TASK here is the definition of the method. In Default, you can see an arrow pointing to all, you can find the corresponding in a HashTable. Here, Closure is used (Note: It is the anonymous method mentioned earlier). So special Build languages ​​are special use. Build files have their own special properties. You want to list all Task branch structure, and dependencies. Anyone wants to get the dependency between the tasks, so the Tag marker that task must be executed. I define these tasks in Ruby's code. Build these tasks in memory, then the necessary tasks will be executed. Build my website means constructing 700 files. But I can know which file is modified, which one needs to be rebuilt, then do the minimize build, get the result I want. We found this very interesting, it can record very little historical information. The relatively early language of this is MAKE language, usually used under UNIX systems. Make is a special file format used to describe how to build code, it is a special Domain language that can be used to build applications. It has its own format and syntax, describing how to build a C language program. Make has a problem, which is that it is not easy to learn. You are also difficult to understand those automatically generated makefile. But many programs have the ability to automatically generate the Make file, because if it is written by yourself, it is not easy to master. Java starts with no build tool. So James Duncan Davidson wrote an ANT for Java build. The author of Ant does not want to build a problem involving grammar, they use XML as a buffet. I am not complaining about this issue, and XML is a good choice at that time. There are two problems with XML grammar. Because the syntax is very strict, you need to spend a lot of energy to pay attention to the grammar, so it becomes difficult to read it. Another problem is that when the system is getting bigger, the build file contains many logic, which has caused difficulties to establish an ANT file. So when the system becomes large, establish an ANT file to build a system is very difficult. We need to find a way that releases from XML to build these classes.

Ruby is such a powerful language that verifies the syntax of Ruby with a certain grammar limit. Ruby did not introduce too many new syntax. This looks not bad, because you need a new language to achieve this function. But you still have a limitations, that is, you can't use it outside of Ruby. But another benefit is that when you need to do very complicated things, you can use ruby. So, you have more powerful capabilities to do this. This exterior language allows you to use its grammar so that you have gradually become more capable. Because it is more and more complicated, it can help you compile. This ability is easy to get. Its syntax is very straightforward, you can learn easily. It is a very traditional idea that serves such a language as a host (Host) language. But this is very useful. Sometimes, making Ruby attracts users is not an easy task. I have been a fans of Ruby for a few years. I am committed to promoting it in our work. I tell others that I like ruby ​​and encourage others to use it. But it is not very important to use or not in one product. I don't recommend all the projects. But in many projects in the last half of the project, we all used ruby. We found that Ruby may not be suitable in some projects, but use Ruby in other projects. This core is that those successful cases have proved that projects are Ruby truly suitable. Although Rails provides a large frame, it is almost impossible to succeed if you don't have Ruby. This is also one of the reasons for the success of the project.

A project that my colleague is doing is a large number of operational databases. Take the data from the database, perform calculations in memory, and then put the data back to the database is not necessary. You want these operations with SPL. It is certainly limited to use SQL. It is very powerful, but it is not easy to use. One of SQL is that it is completely domain based on Domain. It can do well on the table format, but there is no abstraction of the table. So if you want to operate the table, this is very good. But if you want to make another action, it is very troublesome. A typical example is: a database with a hierarchical structure is complicated, and it is also complex and difficult to operate with SQL. In this project, use the Ruby language, allowing Enter of Domain Specific Language, which can generate SQL code to operate on the database. Such special languages ​​are very easy to use. Experts from the field can be separated, read and understand these code, do not consider grammar and how to generate these. You can put your energy in other places. The characteristics of Domain Specific Language such as Ruby makes it very attractive.

Ruby community is exciting

Now let's take a few photos to summarize this speech. Ruby is an interesting system. I can't say it is suitable for any place, but it is really suitable for many places. DSL is its core. Some specific types of websites, especially those who need to use the database, and use the Rails framework. Almost all Administrating Work and Scripting Work are suitable for Ruby. You can start using Ruby because he is a very powerful tool. Ruby is the best scripting language I have ever seen, and you will have the same experience. In terms of construction, Rake (Note: Ruby Build Tool) is a very good build tool. About six months ago, I changed all my websites into files that use it to build and maintain these buildings. I think you will not regret it because these build files are constructed and maintained.

I still have the last thing before I finished this speech. When I talk about software development, I have been emphasizing, no matter what kind of tool you use, what kind of practice, such as the pair programming, test driver, the most important factor on the success of software development project is working in the project People and how these people work together. In the agile Software Declaration, the primary values ​​are more important and more valuable for individuals and interactive ratios and tools. Ruby is worthy of concern is not that its characteristics are not its framework, nor it does not increase the productivity in Rails, but the work of the Ruby community. Dave Thomas (Note: << Pragmatic Programmers >> The author of the book "Author) mention this, this is formal, it attracts me. I have been very interested in the last 233. The Ruby community attracts more and more masters to make it its own progress. Another advantage is that Ruby's open source work can be installed directly through the network. If you want to use, you can easily install it through Rubygem. (Note: It seems like debain Unix package management ). Ruby's community is growing rapidly, because there is a continuous number of members to join this team, working in this environment, which makes this team very much attention. This is also the most important reason I have been paying attention to ruby, because many people worthy of attention work in this community. This is my first speech about Ruby. I hope it is not a speechless speech.

转载请注明原文地址:https://www.9cbs.com/read-130920.html

New Post(0)