tag:blogger.com,1999:blog-2964436963552702620.post4984026484336872674..comments2023-12-01T08:12:59.345+00:00Comments on Michael Snell: Microtyping in Java revisitedMichael Snellhttp://www.blogger.com/profile/02964712142212222175noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-2964436963552702620.post-10292839066427962322015-03-31T18:36:16.888+01:002015-03-31T18:36:16.888+01:00While we're doing micro types, how about let&#...While we're doing micro types, how about let's have some in-between types. For example. Instead of the incredibly general purpose String, let's have some new types like: HtmlSafeString, SqlSafeString, UnsafeString. Obviously incoming strings from the browser could be Unsafe strings. A function could turn an UnsafeString into an SqlSafeString or an HtmlSafeString. You could store SqlSafeStrings into the database. Upon retrieval convert them into HtmlSafeStrings before including them in an outgoing web page.<br /><br />Then a micro type like First Name could come in various flavors: FirstNameHtmlSafe, LastNameHtmlSafe, etc.<br /><br />Of course, now we're talking about an explosion of types.<br /><br />If web frameworks and database drivers would use the new safe / unsafe types, then you've just used type checking to eliminate entire classes of error. Sort of reminds you of using type checking to prevent accidental assignment between integers, strings and booleans.DannyBnoreply@blogger.comtag:blogger.com,1999:blog-2964436963552702620.post-69464362765489098282015-03-31T10:11:32.231+01:002015-03-31T10:11:32.231+01:00I'm calling it "microtyping" since t...I'm calling it "microtyping" since that seems to be the prevalent term in the Java community. Microtyping applies to cases where otherwise just a simple primitive would have been used, so it does potentially form part of proper domain modelling.<br /><br />As I mentioned in the post, I think micro types can be seen as a special case of value types, but they are not the same thing.Michael Snellhttps://www.blogger.com/profile/02964712142212222175noreply@blogger.comtag:blogger.com,1999:blog-2964436963552702620.post-84039734693261831472015-03-31T09:46:14.267+01:002015-03-31T09:46:14.267+01:00See also further comments on RedditSee also further comments on <a href="http://redd.it/30tlv8" rel="nofollow">Reddit</a>Michael Snellhttps://www.blogger.com/profile/02964712142212222175noreply@blogger.comtag:blogger.com,1999:blog-2964436963552702620.post-43450679805809011282015-03-30T22:39:24.677+01:002015-03-30T22:39:24.677+01:00I'm not sure why you call it Microtyping.
To ...I'm not sure why you call it Microtyping. <br />To me it's simply proper domain modeling.<br />For many of the types you used in your example a more complex internal representation than just a sequence of characters is indicated.<br />NakedObjects aka Apache Isis followed that methodology years ago and Java 9 might introduce value types (although, again, things like EmailAdresses are potentially proper objects with identity).<br />bedershttps://www.blogger.com/profile/12176097238930394619noreply@blogger.com