langdes.txt 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. May 2001
  2. (These are some notes I made
  3. for a panel discussion on programming language design
  4. at MIT on May 10, 2001.)1. Programming Languages Are for People.Programming languages
  5. are how people talk to computers. The computer would be just as
  6. happy speaking any language that was unambiguous. The reason we
  7. have high level languages is because people can't deal with
  8. machine language. The point of programming
  9. languages is to prevent our poor frail human brains from being
  10. overwhelmed by a mass of detail.Architects know that some kinds of design problems are more personal
  11. than others. One of the cleanest, most abstract design problems
  12. is designing bridges. There your job is largely a matter of spanning
  13. a given distance with the least material. The other end of the
  14. spectrum is designing chairs. Chair designers have to spend their
  15. time thinking about human butts.Software varies in the same way. Designing algorithms for routing
  16. data through a network is a nice, abstract problem, like designing
  17. bridges. Whereas designing programming languages is like designing
  18. chairs: it's all about dealing with human weaknesses.Most of us hate to acknowledge this. Designing systems of great
  19. mathematical elegance sounds a lot more appealing to most of us
  20. than pandering to human weaknesses. And there is a role for mathematical
  21. elegance: some kinds of elegance make programs easier to understand.
  22. But elegance is not an end in itself.And when I say languages have to be designed to suit human weaknesses,
  23. I don't mean that languages have to be designed for bad programmers.
  24. In fact I think you ought to design for the
  25. best programmers, but
  26. even the best programmers have limitations. I don't think anyone
  27. would like programming in a language where all the variables were
  28. the letter x with integer subscripts.2. Design for Yourself and Your Friends.If you look at the history of programming languages, a lot of the best
  29. ones were languages designed for their own authors to use, and a
  30. lot of the worst ones were designed for other people to use.When languages are designed for other people, it's always a specific
  31. group of other people: people not as smart as the language designer.
  32. So you get a language that talks down to you. Cobol is the most
  33. extreme case, but a lot of languages are pervaded by this spirit.It has nothing to do with how abstract the language is. C is pretty
  34. low-level, but it was designed for its authors to use, and that's
  35. why hackers like it.The argument for designing languages for bad programmers is that
  36. there are more bad programmers than good programmers. That may be
  37. so. But those few good programmers write a disproportionately
  38. large percentage of the software.I'm interested in the question, how do you design a language that
  39. the very best hackers will like? I happen to think this is
  40. identical to the question, how do you design a good programming
  41. language?, but even if it isn't, it is at least an interesting
  42. question.3. Give the Programmer as Much Control as Possible.Many languages
  43. (especially the ones designed for other people) have the attitude
  44. of a governess: they try to prevent you from
  45. doing things that they think aren't good for you. I like the
  46. opposite approach: give the programmer as much
  47. control as you can.When I first learned Lisp, what I liked most about it was
  48. that it considered me an equal partner. In the other languages
  49. I had learned up till then, there was the language and there was my
  50. program, written in the language, and the two were very separate.
  51. But in Lisp the functions and macros I wrote were just like those
  52. that made up the language itself. I could rewrite the language
  53. if I wanted. It had the same appeal as open-source software.4. Aim for Brevity.Brevity is underestimated and even scorned.
  54. But if you look into the hearts of hackers, you'll see that they
  55. really love it. How many times have you heard hackers speak fondly
  56. of how in, say, APL, they could do amazing things with just a couple
  57. lines of code? I think anything that really smart people really
  58. love is worth paying attention to.I think almost anything
  59. you can do to make programs shorter is good. There should be lots
  60. of library functions; anything that can be implicit should be;
  61. the syntax should be terse to a fault; even the names of things
  62. should be short.And it's not only programs that should be short. The manual should
  63. be thin as well. A good part of manuals is taken up with clarifications
  64. and reservations and warnings and special cases. If you force
  65. yourself to shorten the manual, in the best case you do it by fixing
  66. the things in the language that required so much explanation.5. Admit What Hacking Is.A lot of people wish that hacking was
  67. mathematics, or at least something like a natural science. I think
  68. hacking is more like architecture. Architecture is
  69. related to physics, in the sense that architects have to design
  70. buildings that don't fall down, but the actual goal of architects
  71. is to make great buildings, not to make discoveries about statics.What hackers like to do is make great programs.
  72. And I think, at least in our own minds, we have to remember that it's
  73. an admirable thing to write great programs, even when this work
  74. doesn't translate easily into the conventional intellectual
  75. currency of research papers. Intellectually, it is just as
  76. worthwhile to design a language programmers will love as it is to design a
  77. horrible one that embodies some idea you can publish a paper
  78. about.1. How to Organize Big Libraries?Libraries are becoming an
  79. increasingly important component of programming languages. They're
  80. also getting bigger, and this can be dangerous. If it takes longer
  81. to find the library function that will do what you want than it
  82. would take to write it yourself, then all that code is doing nothing
  83. but make your manual thick. (The Symbolics manuals were a case in
  84. point.) So I think we will have to work on ways to organize
  85. libraries. The ideal would be to design them so that the programmer
  86. could guess what library call would do the right thing.2. Are People Really Scared of Prefix Syntax?This is an open
  87. problem in the sense that I have wondered about it for years and
  88. still don't know the answer. Prefix syntax seems perfectly natural
  89. to me, except possibly for math. But it could be that a lot of
  90. Lisp's unpopularity is simply due to having an unfamiliar syntax.
  91. Whether to do anything about it, if it is true, is another question.
  92. 3. What Do You Need for Server-Based Software?
  93. I think a lot of the most exciting new applications that get written
  94. in the next twenty years will be Web-based applications, meaning
  95. programs that sit on the server and talk to you through a Web
  96. browser. And to write these kinds of programs we may need some
  97. new things.One thing we'll need is support for the new way that server-based
  98. apps get released. Instead of having one or two big releases a
  99. year, like desktop software, server-based apps get released as a
  100. series of small changes. You may have as many as five or ten
  101. releases a day. And as a rule everyone will always use the latest
  102. version.You know how you can design programs to be debuggable?
  103. Well, server-based software likewise has to be designed to be
  104. changeable. You have to be able to change it easily, or at least
  105. to know what is a small change and what is a momentous one.Another thing that might turn out to be useful for server based
  106. software, surprisingly, is continuations. In Web-based software
  107. you can use something like continuation-passing style to get the
  108. effect of subroutines in the inherently
  109. stateless world of a Web
  110. session. Maybe it would be worthwhile having actual continuations,
  111. if it was not too expensive.4. What New Abstractions Are Left to Discover?I'm not sure how
  112. reasonable a hope this is, but one thing I would really love to
  113. do, personally, is discover a new abstraction-- something that would
  114. make as much of a difference as having first class functions or
  115. recursion or even keyword parameters. This may be an impossible
  116. dream. These things don't get discovered that often. But I am always
  117. looking.1. You Can Use Whatever Language You Want.Writing application
  118. programs used to mean writing desktop software. And in desktop
  119. software there is a big bias toward writing the application in the
  120. same language as the operating system. And so ten years ago,
  121. writing software pretty much meant writing software in C.
  122. Eventually a tradition evolved:
  123. application programs must not be written in unusual languages.
  124. And this tradition had so long to develop that nontechnical people
  125. like managers and venture capitalists also learned it.Server-based software blows away this whole model. With server-based
  126. software you can use any language you want. Almost nobody understands
  127. this yet (especially not managers and venture capitalists).
  128. A few hackers understand it, and that's why we even hear
  129. about new, indy languages like Perl and Python. We're not hearing
  130. about Perl and Python because people are using them to write Windows
  131. apps.What this means for us, as people interested in designing programming
  132. languages, is that there is now potentially an actual audience for
  133. our work.2. Speed Comes from Profilers.Language designers, or at least
  134. language implementors, like to write compilers that generate fast
  135. code. But I don't think this is what makes languages fast for users.
  136. Knuth pointed out long ago that speed only matters in a few critical
  137. bottlenecks. And anyone who's tried it knows that you can't guess
  138. where these bottlenecks are. Profilers are the answer.Language designers are solving the wrong problem. Users don't need
  139. benchmarks to run fast. What they need is a language that can show
  140. them what parts of their own programs need to be rewritten. That's
  141. where speed comes from in practice. So maybe it would be a net
  142. win if language implementors took half the time they would
  143. have spent doing compiler optimizations and spent it writing a
  144. good profiler instead.3. You Need an Application to Drive the Design of a Language.This may not be an absolute rule, but it seems like the best languages
  145. all evolved together with some application they were being used to
  146. write. C was written by people who needed it for systems programming.
  147. Lisp was developed partly to do symbolic differentiation, and
  148. McCarthy was so eager to get started that he was writing differentiation
  149. programs even in the first paper on Lisp, in 1960.It's especially good if your application solves some new problem.
  150. That will tend to drive your language to have new features that
  151. programmers need. I personally am interested in writing
  152. a language that will be good for writing server-based applications.[During the panel, Guy Steele also made this point, with the
  153. additional suggestion that the application should not consist of
  154. writing the compiler for your language, unless your language
  155. happens to be intended for writing compilers.]4. A Language Has to Be Good for Writing Throwaway Programs.You know what a throwaway program is: something you write quickly for
  156. some limited task. I think if you looked around you'd find that
  157. a lot of big, serious programs started as throwaway programs. I
  158. would not be surprised if most programs started as throwaway
  159. programs. And so if you want to make a language that's good for
  160. writing software in general, it has to be good for writing throwaway
  161. programs, because that is the larval stage of most software.5. Syntax Is Connected to Semantics.It's traditional to think of
  162. syntax and semantics as being completely separate. This will
  163. sound shocking, but it may be that they aren't.
  164. I think that what you want in your language may be related
  165. to how you express it.I was talking recently to Robert Morris, and he pointed out that
  166. operator overloading is a bigger win in languages with infix
  167. syntax. In a language with prefix syntax, any function you define
  168. is effectively an operator. If you want to define a plus for a
  169. new type of number you've made up, you can just define a new function
  170. to add them. If you do that in a language with infix syntax,
  171. there's a big difference in appearance between the use of an
  172. overloaded operator and a function call.1. New Programming Languages.Back in the 1970s
  173. it was fashionable to design new programming languages. Recently
  174. it hasn't been. But I think server-based software will make new
  175. languages fashionable again. With server-based software, you can
  176. use any language you want, so if someone does design a language that
  177. actually seems better than others that are available, there will be
  178. people who take a risk and use it.2. Time-Sharing.Richard Kelsey gave this as an idea whose time
  179. has come again in the last panel, and I completely agree with him.
  180. My guess (and Microsoft's guess, it seems) is that much computing
  181. will move from the desktop onto remote servers. In other words,
  182. time-sharing is back. And I think there will need to be support
  183. for it at the language level. For example, I know that Richard
  184. and Jonathan Rees have done a lot of work implementing process
  185. scheduling within Scheme 48.3. Efficiency.Recently it was starting to seem that computers
  186. were finally fast enough. More and more we were starting to hear
  187. about byte code, which implies to me at least that we feel we have
  188. cycles to spare. But I don't think we will, with server-based
  189. software. Someone is going to have to pay for the servers that
  190. the software runs on, and the number of users they can support per
  191. machine will be the divisor of their capital cost.So I think efficiency will matter, at least in computational
  192. bottlenecks. It will be especially important to do i/o fast,
  193. because server-based applications do a lot of i/o.It may turn out that byte code is not a win, in the end. Sun and
  194. Microsoft seem to be facing off in a kind of a battle of the byte
  195. codes at the moment. But they're doing it because byte code is a
  196. convenient place to insert themselves into the process, not because
  197. byte code is in itself a good idea. It may turn out that this
  198. whole battleground gets bypassed. That would be kind of amusing.1. Clients.This is just a guess, but my guess is that
  199. the winning model for most applications will be purely server-based.
  200. Designing software that works on the assumption that everyone will
  201. have your client is like designing a society on the assumption that
  202. everyone will just be honest. It would certainly be convenient, but
  203. you have to assume it will never happen.I think there will be a proliferation of devices that have some
  204. kind of Web access, and all you'll be able to assume about them is
  205. that they can support simple html and forms. Will you have a
  206. browser on your cell phone? Will there be a phone in your palm
  207. pilot? Will your blackberry get a bigger screen? Will you be able
  208. to browse the Web on your gameboy? Your watch? I don't know.
  209. And I don't have to know if I bet on
  210. everything just being on the server. It's
  211. just so much more robust to have all the
  212. brains on the server.2. Object-Oriented Programming.I realize this is a
  213. controversial one, but I don't think object-oriented programming
  214. is such a big deal. I think it is a fine model for certain kinds
  215. of applications that need that specific kind of data structure,
  216. like window systems, simulations, and cad programs. But I don't
  217. see why it ought to be the model for all programming.I think part of the reason people in big companies like object-oriented
  218. programming is because it yields a lot of what looks like work.
  219. Something that might naturally be represented as, say, a list of
  220. integers, can now be represented as a class with all kinds of
  221. scaffolding and hustle and bustle.Another attraction of
  222. object-oriented programming is that methods give you some of the
  223. effect of first class functions. But this is old news to Lisp
  224. programmers. When you have actual first class functions, you can
  225. just use them in whatever way is appropriate to the task at hand,
  226. instead of forcing everything into a mold of classes and methods.What this means for language design, I think, is that you shouldn't
  227. build object-oriented programming in too deeply. Maybe the
  228. answer is to offer more general, underlying stuff, and let people design
  229. whatever object systems they want as libraries.3. Design by Committee.Having your language designed by a committee is a big pitfall,
  230. and not just for the reasons everyone knows about. Everyone
  231. knows that committees tend to yield lumpy, inconsistent designs.
  232. But I think a greater danger is that they won't take risks.
  233. When one person is in charge he can take risks
  234. that a committee would never agree on.Is it necessary to take risks to design a good language though?
  235. Many people might suspect
  236. that language design is something where you should stick fairly
  237. close to the conventional wisdom. I bet this isn't true.
  238. In everything else people do, reward is proportionate to risk.
  239. Why should language design be any different?