-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 i have some (10 years) experience with difference statically typed languages and a bit with dynamic ones. i encountered a few typesafe solutions that don't introduce a lot of overhead - for example the types of scala. in addition to interfaces and classes, scala has types. a type can be an arbitrary set of field and method definitions, for example: type foo = { def x:String val y:Int }
every instance that has a method x which returns a string and a field which is an int are compatible to foo. in java, you would say it is a "delayed interface". the code behaves as if someone magically attached "implements foo" to any class which would still compile. so your "(not (nil? (:first-name record)))" would work in scala if there was a type like type bar = { val firstName:String } it's implemented via reflection, but the types are checked at compile time. Am 24.10.2011 15:28, schrieb Timothy Baldridge: > After watching Rich's talk the other day about "Making Simple > Easy", I started thinking about how to incorporate parts of this > talk into the software we're writing at work. During this thought > process, I have begun to wonder, are simple and statically typed > languages mutually exclusive? > > Let me explain by a simple example. In the following text, I will > be using C# as my example "static" language, and Clojure as my > example dynamic language. > > For instance, let's say we have two structures, Contact and Staff. > The two are completely unrelated, except for the fact that they > both have a first name, and they both are required fields: > > Clojure: > > {:first-name "Billy" :age 42 :record-type "Contact"} {:first-name > "Joe" :position "manager" :record-type "Staff"} > > Now in Clojure, writing a validation check for this is as simple > as: > > (not (nil? (:first-name record))) > > But how would we do this in C#? > > new Person() {firstName="Billy", age=42 }; new Contact() {firstName > "Joe", Position="manager"}; > > Person and Contact are unrelated, so I'm left with duplicating my > validation routines (once for each object), or going and making > both implement IFirstName. This gets even more fun when you start > taking into account generics: In C# a List<IFirstName> cannot be > casted to a List<Person> because they are considered two completely > different objects. > > In the Clojure source code, Rich gets around most of the above > issues by simply referring to everything as a object and then > casting to get the type at runtime. This works fine for code that > will be run in a dynamic language anyways, but makes for some ugly > code when you're actually writing the static language parts: > > if (lst[0] is IFirstName) runFirstNameChecks(lst[0]); if (lst[0] is > Person) runPersonChecks(lst[0]); > > However, this then requires tons of type checks and casting > throughout the entire system. > > So yes, I understand that this is all a bit off-topic for a > Clojure mailing list, but I thought it was applicable to Rich's > talk. Are we getting half way to simple, simply by using Clojure in > the first place? Is it possible to write simple code in a language > that shuns the use of simple containers (List, Dictionary, etc.) as > the primary transport system for data? > > If anyone has some thoughts, they are more than welcome to ponder > them "out-loud" with me on this thread.... > > Timothy > - -- -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.14 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQIcBAEBAgAGBQJOpZetAAoJENRtux+h35aGhTsP+wUYHLD0i8t4DI7P/d2A13Ca 29hIhICsxJ2IE3svctaobozaT1byzzpYq6NFfqcfdwfOJCAJBCxmrHTiTCQ09EPM jSZpxiXQSXHtYDpn2AiYA5c5Ut+TXjbWeahKjyRGrUVKjORtPHvaWGccj0b5vzYT m7QpMy7R0tzEj/w2FCIkWkjqvJeCQ3cYNC78GZ2gIHC9DQwAjeD2uKSX3RfwaD3S apEJELCYeDS08NIS26uB0ZHbo228rLlr02WaXh/+rx/MlMlEE/MEIq0aqJV59J7J A6EFqoC43LxpftJRfAJ3MHRoliC0mnGN9SoWKeRiE0i8p1g8pv1e74DpLzI/I/Pq GeR9TL688wyhnehl8VZW9AEKQVfKOujPIkKdpr4eF98eKdxHdu4xwkKi/ZgL6zCf h7/eO6QRrKsOLfztMNQsaYqpCP/pFGA2J3p4Q/oVkB2Uqa6xa0auNcY5mBSPNuZp zKcOg6/gi39eOZxFslVOvnY6ZOcILjRJYoA1VcO834NMd0A+D6lP0UM0ReBb28kg MLjhDstZC1xVShp9PVJAdMlMeNjRDOPcASQG6uCisTSGfQ7qVXBNYd/SqXyRUODn YFTSYtncEu+Pq0nRIjl1ItBmP/9saEqqJwiOpW01IAT+mFVv10tqKCxWFJKwNcLQ iolsrCZa8Yn9Tvt2hFEL =UbSd -----END PGP SIGNATURE----- -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en