Language and Library API Design for Usability of Ruby Usability Over Simplicity

Language and Library API Design for Usability of Ruby Usability Over Simplicity

Language and Library API Design for Usability of Ruby Usability over Simplicity Akira Tanaka National Institute of Advanced Industrial Science and Technology (AIST) [email protected] Abstract • obj.meth + var The Ruby programming language is designed for easy use. • obj.meth +var The usability is an important feature since the productivity of programmers depends on it. This paper describes that the The difference of this example is a space between + design method obtained through the experiences of devel- and var. The former has a space, the latter not. In the oping Ruby. The design method can be used to make other former, meth is a method call without an argument and + is languages and libraries easy to use. a binary operator: obj.meth() + var. In the later, meth is a method call with an argument and + is a unary operator: Categories and Subject Descriptors D.3.2 [Programming obj.meth(+var). The space resolves such an ambiguity Languages]: Object-oriented languages caused by the fact that the parentheses of a method call is not mandatory. General Terms Programming Language, Library, Usabil- Here, the semantics depends on white spaces. Such a ity design is curious form a view point of computer scientists. It is not simple but complex, against tradition, and hard to Keywords Syntax, Library, API, Usability, Simplicity, understand. But such a curious behavior does realize the usability. By 1. Introduction understanding the reason why Ruby adopts it, we can get an There is no formal way to establish easy-to-use program- insight into the usability of programming languages. ming languages and library APIs. But the easiness is an im- This paper constructed as follows to explain a design portant factor for programmers’ productivity. method for programming languages and library APIs to be Ruby is the object oriented programming language cre- good usability. It is obtained from experiences of Ruby de- ated by Yukihiro Matsumoto. It is intended to be easy to use. veloper (committer). I, Akira Tanaka, feels it has good usability. However it is not • Although Ruby is designed to be easy to use, the design simple. It has complex behavior. It is difficult to explain why method is not explained concretely (Section 2). The ex- it is easy. planation will have following benefits. Basically, the design of Ruby puts importance on good properties of programming languages: succinctness, good We can make libraries and other languages easy to use naming convention, etc[2]. However, some of Ruby’s behav- as Ruby. iors violate such good properties to improve the usability. We can avoid usability regression when modifying The concrete design method for such behaviors is not well Ruby. explained. • The design of Ruby focus usability (Section 3). We don’t For example, these two expressions has the different mind complexity of the design if it realize usability. In meaning. general, simplicity is good property but it is not the pri- mary goal of Ruby. • We design Ruby incrementally to improve usability (Sec- tion 4). We find flaws of Ruby and fix them. Several is- sues should be considered for usability: How many frequency of the flaw occur? What the appropriate design according to the fre- [Copyright notice will appear here once ’preprint’ option is removed.] quency? Language and Library API Design for Usability of Ruby 1 2009/10/9 Does the fix prevents other fixes in future? For example, continuation (call/cc) on dynamic typed If the fix has an incompatibility, how it should be dealt languages endorse consistency between arguments and re- with? turn value because it pass former to later. This mismatch, multiple values of arguments v.s. single value of return • We describes future work ((Section 5). We will explain value, can be solved by that function call can have multi- various techniques for usability used in Ruby as design ple return values as Scheme. However continuation is rarely patterns (pattern language). Since the techniques are em- used in Ruby, the consistency is not important. pirical and sometimes conflict, design patterns should be The design of Ruby is not intended to simplify the be- good format for the explanation. They will accelerate havior. Actually the whole behavior including rare usage is Ruby design process. We also describes possible tech- complex. Some of the complexity is intentional for usability. nology to support incremental design. In general, simplicity is a good property. It derives many things from few principles. So programmers don’t need to 2. Usability of Ruby memorize many things except the principles. Another benefit Ruby is designed to be easy to use programming language. is that simplicity ease programming language research. But The design policy, such as succinctness, is described briefly Ruby prefer direct usability over such benefits. in [2, 3] for language itself and [4] for libraries. But the In this section, we describe several examples of Ruby’s description is not enough to put it into practice. Especially complex design for usability. the practice is difficult when usual good properties conflicts usability. 3.1 Succinctness over Simplicity The difficulty causes several problems: In this section, we explain the example shown in the section 1. The example shows us Ruby depends on a space in a • When we want to realize the usability similar to Ruby in method call. If we want to choose a simple behavior, the other languages and libraries, it is difficult to determine following can be considered. what behavior should be imitate. We want to ignore the behavior which doesn’t contribute to the usability. But it • make the parenthesis of method call mandatory. is clear to determine. • • even if the parenthesis is optional, define the behavior When we want to modify Ruby, it is difficult to consider regardless of the space. the modification will degrade the usability or not. These problems can be solved by understanding how the If the parenthesis is mandatory, the ambiguity of + opera- usability of Ruby is implemented. tor doesn’t occur. The + of obj.meth()+var is a binary op- The examples follows are explained in following sec- erator. The + of obj.meth(+var) is a unary operator. Also, tions. the syntax rules can be reduced because we don’t need rules for the parenthesis omitted. • optional parenthesis for succinctness and DSL Even if the parenthesis is optional, the behavior regard- • blocks for common usages of higher order functions less of the space simplify the information notification be- tween the tokenizer and the parser. • shorter names for frequently used methods for succinct- We didn’t choose the simple behavior for Ruby. The ness reason behind it is succinctness. There are many situations which don’t cause ambiguities 3. Unusual Design even without the parenthesis. The method call is not ambigu- In this section, we describe the design of Ruby which intend ous if no arguments are given, only one argument is given to be easy to use and violates usual language design. and it is a variable, etc. If we require the parenthesis, Ruby In usual language design, there are several good prop- loses succinctness for such situations. erty: consistency, simplicity, orthogonality, flexibility, suc- cinctness, intuitiveness, DRY (Don’t Repeat Yourself), good 3.2 Intuitiveness over Simplicity name, generalness, naturalness, meets programmers’ com- The example in the section 1 also show Ruby’s design pol- mon sense, etc. In the design policy of Ruby, they are also icy which prefer intuitiveness over simplicity. The intuitive- good properties. ness is for average programmers. Although programmers However, sometimes Ruby overrides the properties by us- vary, they have many shared knowledge. For example, there ability. I.e. the design of Ruby prefer usability over the prop- are common textbooks and the programmers can understand erties when they conflict. Ruby don’t need consistency in- pseudo code in the textbooks. Programmers who know ap- cluding rare usage. Ruby don’t need succinctness including plication domain can understand the notation used by the do- rare usage. Ruby don’t need orthogonality including rare us- main. So programmers have common intuition in a degree. age. Ruby don’t need simplicity including rare usage. The detailed reason are follows. Language and Library API Design for Usability of Ruby 2 2009/10/9 • DSL 3.3 Usage Frequency The frequency of usage can also be a reason to override DSL, Domain Specific Language, is a language which simplicity. correspond to a target domain. It can represent logic in For example, a method name should match the following the domain intuitively. DSLs are classified as external regular expression: DSLs and internal DSLs. An external DSL is an indepen- [A-Za-z_][0-9A-Za-z_]*[!?]? dent programming language. An internal DSL is a library in some programming language. The library provides vo- I.e. it start with an letter or an underscore, followed by zero cabulary for the domain. or more digits, letters and underscores, optionally followed The parenthesis of method call have an impression of by ! or ?. function call. The impression hides the impression of the This syntax is not simple because the last ! or ?. If we domain. So the syntax with optional parenthesis appro- choose simple syntax, we can consider a syntax without the priate for DSL. It expose the impression of the domain. last character like C or a syntax with various character in any So programmers easily sense the logic in the domain. position like Scheme. This complex syntax is chosen to use the naming practice For example, Ruby has a DSL to manipulate Ruby run- of Scheme in Ruby. Scheme uses function names which ends time. The DSL is constructed by methods to load a li- with ? for predicates and ! for destructive functions.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    6 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us