{"id":1370,"date":"2019-08-01T00:31:44","date_gmt":"2019-08-01T00:31:44","guid":{"rendered":"http:\/\/sdi.thoughtstorms.info\/?p=1370"},"modified":"2019-08-01T00:31:44","modified_gmt":"2019-08-01T00:31:44","slug":"how-would-you-design-the-perfect-programming-language","status":"publish","type":"post","link":"https:\/\/sdi.thoughtstorms.info\/?p=1370","title":{"rendered":"How would you design the perfect programming language?"},"content":{"rendered":"<p>Another Quora answer I should be moving here : <em><a href=\"https:\/\/www.quora.com\/How-would-you-design-the-perfect-programming-language\/answer\/Phil-Jones\">Phil Jones&#8217;s answer to How would you design the perfect programming language?<\/a><\/em><br \/>\n&nbsp;<br \/>\nWell, the obvious way you\u2019d approach it, is start with a reasonable knowledge of using other languages to get a sense for their strengths and weaknesses.<br \/>\nAnd start with some good role models.<br \/>\nAnd then see where you can go by taking a good language and incorporating ideas from elsewhere.<br \/>\nIt\u2019s no secret that I think that Clojure is the nicest language I\u2019ve ever used.<br \/>\nClojure\u2019s virtue is that<br \/>\na) it\u2019s built on very firm, 50 year old foundations, namely Lisp.<br \/>\nAND<br \/>\nb) it <i>was <\/i>willing to do a clean slate reinvention, throwing out the cruft that had built up in other Lisps and Schemes. And bringing in good ideas from elsewhere.<br \/>\nI think that\u2019s <i>how<\/i> you make a great language. Start with an already good one. And improve it with housekeeping and tasteful borrowings from elsewhere. (Note the \u201ctasteful\u201d \u2026 C++ took a good idea \u201cobject orientation\u201d and kludged it into a good language, C. And somehow came up with a worse language. (<a href=\"https:\/\/www.quora.com\/Why-is-C++-considered-a-bad-language\/answer\/Phil-Jones\">Phil Jones&#8217;s answer to Why is C++ considered a bad language?<\/a> )<br \/>\nThat selectivity. Being willing to throw out bits that either got crufty or just didn\u2019t fit the vision (eg. reader macros in Clojure) is as crucial a part of making a nice language as choosing good features to add.<br \/>\nSo how would a great language seem to me today?<br \/>\nAs I said <a href=\"https:\/\/www.quora.com\/If-Clojure-is-one-of-the-most-expressive-languages-of-today-and-has-similar-expressive-power-as-Common-Lisp-which-goes-back-to-early-80s-can-we-say-that-the-field-of-programming-languages-hasnt-progressed-much-in\/answer\/Phil-Jones\">here<\/a>, languages need to express<\/p>\n<ul>\n<li>a) computation (ie. functions and compositions of functions)<\/li>\n<li>b) constraints<\/li>\n<li>c) data-structures<\/li>\n<li>d) \u201carchitecture\u201d<\/li>\n<\/ul>\n<p>From a language design point of view, I think \u201ccomputation\u201d is a solved problem. I think it\u2019s great to do computation with function application and composition. I\u2019m pretty happy with the way Lisp represents that. But I understand people who might prefer a different syntactic sugar for expressing functions like the ML \/ Haskell families. Or even if you want to start with Smalltalk\u2019s objects passing messages, the \u201cconcatenative\u201d approach of Forth, Erlang\u2019s actors, or Prolog\u2019s relations, then you might get somewhere interesting.<br \/>\nI\u2019ll skip constraints (largely types and contracts) for the moment. And focus more on c) and d). A good language must have good ways of expressing complex data structures. This starts with a good way to express literals. Eg. strings, arrays, dictionaries etc. But moves on to expressing more complex data-schema. Perhaps grammatically.<br \/>\nI like Clojure\u2019s EDN, which is like JSON, but having it really built into the language is very powerful. But you can go further with grammatical descriptions of data. Things like Clojure\u2019s Spec. Or Shan\u2019s \u201csequence calculus\u201d. Or Haskell\u2019s algebraic data-types etc.<br \/>\nIronically, \u201cobject oriented\u201d languages have been rather poor at expressing complex data. The most egregious ugliness of the C++ \/ Java type OO is due to just how painful it is to construct complexes of objects. You end up having to procedurally call <i>operations<\/i> on classes and objects saying \u201ccreate a new instance of an X, now attach a new instance of a Y to it. Now attach to the Y, a reference back the Z from this scope\u201d<br \/>\nIt\u2019s that mismatch between a program that thinks of itself as a network of interacting objects, and a language that has no explicit concept of \u201ca network of interacting objects\u201d and no convenient way to express it, that makes Java and friends such hard work. Somewhere deep in the heart of the UML is a good intuition, struggling to find a viable implementation.<br \/>\nThat\u2019s what I call \u201carchitecture\u201d. The structure of the program itself. But architecture is also the shape of the UI. And the bindings between events and handlers. Or the representation of the overall network of different actors \u2026 the client, the server, the database etc.<br \/>\nA language which is good at defining data-structures could be good for defining all these architectural elements if you just added a few more bells and whistles to it. (See <a href=\"https:\/\/www.quora.com\/Which-is-the-best-programming-language-for-developing-a-GUI-application\/answer\/Phil-Jones\">Phil Jones&#8217;s answer to Which is the best programming language for developing a GUI application?<\/a> )<br \/>\nI\u2019m fascinated by Jonathan Edwards\u2019 concept of \u201csocial data-types\u201d, ie. data-structures with built in declarative rules for how they should be synced and distributed and accessed across a networked application. This seems to me to be exactly the kind of thing we need in new languages : the number of useful algorithms to define how data is moved and synced and controlled around a network is probably small. They are fiddly to implement, but 99.999% of applications just need to state <i>which <\/i>they use.<br \/>\nFor example, it should be possible to say stuff like <i>\u201cthis is a thing called a Profile page. It has these fields. Each Profile page belongs to one SystemUser. And each SystemUser will have one ProfilePage. Only the SystemUser who owns the ProfilePage should be able to edit it. But all SystemUsers should be able to see \/ read it. Changes on the owners client will be automatically synced to the server, and changes on the server will be automatically synced to any non-owner\u2019s client which is looking at the page\u201d.<\/i><br \/>\nDon\u2019t get hung up in the English. I\u2019m not asking or interested in this being natural or \u201cEnglish-like\u201d language. I\u2019m saying it ought to be possible to declare these facts simply within the declaration of the data schema, and have the language\u2019s own \u201csynchronization engine\u201d automatically do it.)<br \/>\nNow, of course, languages as diverse as HTML, SQL and Prolog are declarations of stuff with some engines behind the scenes to do the work (inference engines in Prolog, query engines in SQL, layout engines in Prolog)<br \/>\nBut each individual engine is limited. Ideally we want to be able to have multiple engines for multiple purposes.<br \/>\nWhat I\u2019m feeling towards, then, is<\/p>\n<ul>\n<li>a language which is great for defining data-structures and architecture (both general schemas and particulars)<\/li>\n<li>a language which is good for defining \u201cengines\u201d. I\u2019m not sure I mean \u201cimplementing\u201d engines. Perhaps they need to be implemented in some lower level language. But it should be possible in our high level language to say <i>\u201chere are some rules for something called \u201csynchronization\u201d which will be represented in this way within the program, will be handled by that engine, with these constraints or pre\/post conditions\u201d<\/i><\/li>\n<\/ul>\n<p>The nice thing about rules is that they are easy to compose and have what <a href=\"https:\/\/www.quora.com\/profile\/Quildreen-Motta\">Quildreen Motta<\/a> seems to be calling \u201cextensibility\u201d. You can add or remove rules without worrying about how to slot them into the order of execution. You expect the engine to worry about that, and how to compose these types of rules together meaningfully.<br \/>\nA final point.<br \/>\nYes, a good interactive mode of development inside a good IDE \/ REPL is crucial.<br \/>\nBut I\u2019ve been thinking for a while if it\u2019s possible to go further.<br \/>\nProgramming is still very bottom up. Even if we have a top-down view of our system, when we know it consists of modules X, Y and Z and they have to interact in this way. our development tools don\u2019t really capture this information until we program it at the lowest level.<br \/>\nWe have a bunch of tools that help us work with and reason about the higher level. We can write interfaces and type information and protocols etc. But until we instantiate them the language doesn\u2019t really want to know.<br \/>\nWe have unit tests. Which we ought to write first in TDD. In something like Clojure Spec, though, we can actually generate unit-test examples from our Spec.<br \/>\nThat\u2019s quite good but it\u2019s a side trick.<br \/>\nWhat I think is one of the big pains of programming is that the computer demands we address problems in an order which suits it.<br \/>\nBut imagine if we broke that restriction. Imagine if we could sit down with the IDE and have a \u201cconversation\u201d (remember I\u2019m still not talking about English \/ natural language, just the ordering) like this :<\/p>\n<blockquote><p>Me : I\u2019m going to build a system called \u201cMyAPP\u201d with a client and a server.<br \/>\nComputer : I got that, I know roughly what a client and a server are. And I\u2019m storing our work under the name MyApp.<br \/>\nMe : Actually the client needs to run in both browser and on mobiles.<br \/>\nComputer : sure<br \/>\nMe : here\u2019s the data-structure for the User and the UserProfile. And there\u2019s a one-to-one relationship between them.<br \/>\nComputer : OK. Gotcha<br \/>\nMe : and the API basically consists of these commands. Oh, and to get started, here\u2019s a state-machine I\u2019m declaring for one of the interactions.<br \/>\nComputer : Understood. I\u2019ve stubbed out the API and that protocol for you. Navigate here in your browser and try (with the default forms) some interactions based on that state-machine.<br \/>\nMe : thanks. Now I look at them, those forms are good, but I need to use a larger text box for the user description. And the classification_code is one of [:member, :editor, :administrator]<br \/>\nComputer : sure, I\u2019m guessing that\u2019s a drop-down in the UI, but how are you representing it in the UserRecord?<br \/>\nMe : On larger (browser pages) I prefer Radio Buttons, but on smaller pages and the mobile apps, yes a drop-down. In the data model I\u2019ll go with it having to be one of these symbols, you can add that information to the schema of the UserRecord<br \/>\nComputer : already done.<br \/>\nMe : So now, this bit of the API defines the Admin controls. These should be limited to users who have the :admin classification_code.<br \/>\nComputer : Yep.<br \/>\nMe : Now, on that Dashboard page, I want you to add a chart that subscribes to a value called AllUserStats.flurpsPerMonth. It\u2019s going to be on the form of integers against months.<br \/>\nComputer : OK. So I\u2019m showing you some graphs with some random numbers against month data I just made up. Does that look OK? And how do you really really want to calculate <i>flurps<\/i>?<br \/>\nMe : it looks fine for the moment. So <i>flurps<\/i> are calculated from <i>woobles. <\/i>I know you don\u2019t know anything about <i>woobles <\/i>yet, But <i>woobles <\/i>are floating point numbers between -2 and +2, and <i>flurps <\/i>come out of left-folding all the <i>wooble <\/i>information for each User\u2019s month like this.<br \/>\nComputer : OK. I did that. You now have a flurp_calc transducer that\u2019s hooked on to a stream that subscribes to User.woobleData (I don\u2019t know what that is yet.) And the Flurps Per Month Graph on the admin page is now subscribed to that. I\u2019m still making random shit up in User.woobleData, but at least those numbers are between -2 and +2. If flurp_calc is still wrong, that\u2019s your fault.<br \/>\nMe : No probs. You\u2019re doing good work computer. I gotta rush, but I\u2019ll back tomorrow to pick up where we left off.<\/p><\/blockquote>\n<p>Now \u2026 just to re-iterate. This is NOT about natural language or Artificial Intelligence that means we can just talk to the computers.<br \/>\nI expect the above dialogue to happen in completely formal unambiguous statements using a sensible and efficient syntax.<br \/>\nWhat it\u2019s about though, is a development environment that lets me, the programmer, add the decisions \/ constraints that define the system <i>in the order that\u2019s convenient for me<\/i>. Behind the scenes there\u2019s a model of the application. And that model is always kept in a state which can be run and tested, as a prototype \/ wireframe \/ stubbed or mocked up. It may break because I\u2019ve put a bug into it. But if there is no bug then it\u2019s never not doing <i>something<\/i> because I haven\u2019t got around to doing something else yet. I\u2019m jumping backwards and forwards between Model, View and Controller. Giving advice on fundamental algorithms, on architecture, on UI tweaks. I don\u2019t need to build my application from the bottom up. I have a working application from the start, albeit one that does nothing. And I just keep adding extra information to refine and incrementally extend that application. In whatever order the ideas come to me.<br \/>\nFinally, I want to emphasize, this is not meant to be a description of a \u201cweb-app builder\u201d tool. Knowledge of clients, servers, mobile-devices, web-applications etc. are in the pluggable engines. All the language knows about is :<\/p>\n<ul>\n<li>declaring data-structures and architecture<\/li>\n<li>declaring rules (how they look, and how they interface with an engine)<\/li>\n<li>describing the small amount of extra computation my system needs to do, probably in the form of functions<\/li>\n<\/ul>\n<p>Beyond that, the development environment needs to know how to add new data-structures \/ functions and rules in the form of a dialogue, while keeping an up-to-date, coherent model of a system which is automatically generating a working prototype of that system.<br \/>\nPlug the Social Apps Framework (including engine) into the language \/ IDE at that point, and you now have the ability to grow your system via a \u201cconversation\u201d like the one above.<br \/>\nOK. Final repetition. The \u201cperfect language\u201d (or at least next leap forward) language I\u2019m dreaming of is :<\/p>\n<ul>\n<li>a language with great expressivity for defining data-structures and rules<\/li>\n<li>a language where we expect to find most of the application (or \u201cbusiness\u201d) logic written in the form of declarations of data-structures and rules which are handled by pluggable engines.<\/li>\n<li>a language where it\u2019s easy to add and remove engines. Ideally perhaps the language can help us write the engines too.<\/li>\n<li>a language whose development environment affords a \u201cconversational\u201d way of building up a program by adding extra rules \/ constraints to an always live system<\/li>\n<li>I personally would start with Clojure \u2026 which already has a good Lispish syntax for functions and macros, and, in EDN, the beginnings of an OK data-structure language. But if you prefer to start from Smalltalk or Forth or Haskell or Prolog and do the Rich Hickey trick of a clean-slate refresh, keeping the good ideas, tastefully borrowing other good ideas, and removing the cruft, then that\u2019s good too.<\/li>\n<\/ul>\n<p><b>Related :<\/b><\/p>\n<ul>\n<li><a href=\"https:\/\/www.quora.com\/Where-do-you-see-computer-programming-languages-heading-in-the-future-particularly-in-the-next-5-to-20-years\/answer\/Phil-Jones\">Phil Jones&#8217;s answer to Where do you see computer programming languages heading in the future, particularly in the next 5 to 20 years?<\/a><\/li>\n<li><a href=\"https:\/\/www.quora.com\/Why-is-logic-programming-overlooked-Can-we-use-it-for-developing-any-kind-of-software\/answer\/Phil-Jones\">Phil Jones&#8217;s answer to Why is logic programming overlooked? Can we use it for developing any kind of software?<\/a><\/li>\n<li>See the discussions on <a href=\"https:\/\/www.quora.com\/What-is-the-programming-language-you-are-looking-for-and-why\/answer\/Phil-Jones\">Phil Jones&#8217;s answer to What is the programming language you are looking for and why?<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Another Quora answer I should be moving here : Phil Jones&#8217;s answer to How would you design the perfect programming language? &nbsp; Well, the obvious way you\u2019d approach it, is start with a reasonable knowledge of using other languages to get a sense for their strengths and weaknesses. And start with some good role models. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[67,356,360,372],"class_list":["post-1370","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-clojurescript","tag-programming-languages","tag-prolog","tag-quora"],"_links":{"self":[{"href":"https:\/\/sdi.thoughtstorms.info\/index.php?rest_route=\/wp\/v2\/posts\/1370","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sdi.thoughtstorms.info\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sdi.thoughtstorms.info\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sdi.thoughtstorms.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sdi.thoughtstorms.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1370"}],"version-history":[{"count":0,"href":"https:\/\/sdi.thoughtstorms.info\/index.php?rest_route=\/wp\/v2\/posts\/1370\/revisions"}],"wp:attachment":[{"href":"https:\/\/sdi.thoughtstorms.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1370"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sdi.thoughtstorms.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1370"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sdi.thoughtstorms.info\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1370"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}