今天在园子里面晃悠,看到了Spaghetti code——意大利面代码这个,很有意思的编程类术语,在Wikipedia中关于Spaghetti code描述的页面还发现了一个Ravioli code——小方饺代码、Lasagna code——千层面代码和Spaghetti with meatballs——意式肉丸意粉代码等这几个有意思的属于名词,以下是它们的描述:
Spaghetti code
Spaghetti code is a pejorative term for source code that has a complex and tangled control structure, especially one using many GOTOs, exceptions, threads, or other "unstructured" branching constructs. It is named such because program flow tends to look like a bowl of spaghetti, i.e. twisted and tangled. Spaghetti code can be caused by several factors, including inexperienced programmers and a complex program which has been continuously modified over a long life cycle. Structured programming greatly decreased the incidence of spaghetti code.
Ravioli code
Ravioli code is a type of computer program structure, characterized by an excessive number of very small and (ideally) loosely coupled software components. The term stems from the analogy of ravioli (small pasta pouches containing cheese, meat, or vegetables) to modules (which ideally are encapsulated, consisting of both code and data). While generally desirable from a coupling and cohesion perspective, overzealous separation and encapsulation of code can bloat call stacks and make navigation through the code for maintenance purposes more difficult.
Lasagna code
Main articles: Architectural layer and Layer (object-oriented design)
Lasagna code has many layered components, much like the filling and pasta of its namesake.
Lasagna code is a type of program structure, characterized by several well-defined and separable layers, where each layer of code accesses services in the layers below through well-defined interfaces. The analogy stems from the layered structure of a plate of lasagna, where different ingredients (meat, sauce, vegetables, or cheese) are each separated by strips of pasta.
One common instance of lasagna code occurs at the interface between different subsystems, such as between web application code,business logic, and a relational database. Another common programming technique, alternate hard and soft layers (use of different programming languages at different levels of the program architecture), tends to produce lasagna code. In general,client–server applications are frequently lasagna code, with well-defined interfaces between client and server.
Lasagna code generally enforces encapsulation between the different "layers", as the subsystems in question may have no means of communication other than through a well-defined mechanism, such as Structured Query Language, a foreign function interface, or Remote Procedure Call. However, individual layers in the system may be highly unstructured or disorganized.
The term was coined by database guru Joe Celko in 1982.
A similar layering may be seen in communication stacks, where a protocol (such as the OSI model) is divided into layers (in this case 7), with each layer performing a limited and well defined function and communicating with other layers using specific and standardized methods. Such a design eases the evolutionary improvement of the entire stack through layer-specific improvements.
Again, while loosely coupled layering is generally desirable in a program's architecture because it makes objects at each layer more interchangeable with existing or possible future implementations, other types of changes to the code will actually increase in complexity as more layers are added and so an extensively layered architecture can be seen as an anti-pattern as well. Adding a new field to a UI view, for example, requires changing every object at every layer in the architecture that is required to have knowledge about this new field (generally the view itself, any underlying controller/presenter class, data transfer objects, SOA layers, data access objects or mappings, and the database schema itself). A quote usually attributed either to David Wheeler or Butler Lampson reads, "There is no problem in computer science that cannot be solved by adding another layer of indirection, except having too many layers of indirection".
Spaghetti with meatballs
The term "spaghetti with meatballs" is a pejorative term used in computer science to describe loosely constructed object-oriented programming (OOP) that remains dependent on procedural code. It may be the result of a system whose development has included a long life cycle, language constraints, micro-optimization theatre, or a lack of coherent coding standards.
In some languages, OOP features are available only in later specifications. Notable examples of this include Visual Basic, and PHP. Other languages, like C, rely on function pointers to simulate OOP — still requiring the underlying procedural code to which they point.
Using OOP does not necessarily prevent a class's code from becoming spaghetti-like. In this parlance, "spaghetti" describes twisted, tangled and unstructured code, while "meatballs" denotes the use of class structures (i.e. objects).
本文中以上编程术语的描述来自于WIKIPEDIA,原文链接为:http://en.wikipedia.org/wiki/Lasagna_code#Lasagna_code。
本文中Spaghetti code——意大利面代码,Ravioli code——小方饺代码,Lasagna code——千层面代码和Spaghetti with meatballs——意式肉丸意粉代码的翻译来自爱词霸。
本来想自己翻译成中文,供大家分享的,可是尝试了一段之后,发现本人英文水平实在是上不了台面,所以只好贴出英文原文,大家看的时候就当顺便也学习一下英语了!