From 11d92df5992fb36108dfd6028d1af272f570eb10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20HULARD?= Date: Sat, 17 Jun 2017 23:48:48 +0200 Subject: [PATCH] Add a new article about naming convention. This article explain what was discussed in the RFC : https://github.com/hoaproject/Central/issues/54 --- .../07-Introduce-data-conversion-naming.xyl | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 Source/Posts/2017/07-Introduce-data-conversion-naming.xyl diff --git a/Source/Posts/2017/07-Introduce-data-conversion-naming.xyl b/Source/Posts/2017/07-Introduce-data-conversion-naming.xyl new file mode 100644 index 0000000..fa2454a --- /dev/null +++ b/Source/Posts/2017/07-Introduce-data-conversion-naming.xyl @@ -0,0 +1,92 @@ + + + + + + +
+

+ For 2017, we defined + a roadmap composed of Request For Comments (RFC) that are discussed + and implemented. One if these RFC is about + naming convention + and simplification. +

+

+ So far, we use this formalism: getFoo() to name a method + that returns the value foo. This can be a direct attribute, or a + computation. To get this data within another form, i.e. to convert this + data into another type, we don't have any formalism yet. For instance, + if foo is an array, and we would like to get it as a string, + we will probably name a method like getFooAsString() but this + is not deterministic. +

+

+ Conversions can be expensive so the method prefix must be clear enough to + know operation cost directly inside the code. +

+

+ We decided to introduce 3 method prefixes: +

+ + + + + + + + + + + + + + + + + + + + + + + + + +
PrefixCostConsumes convertee
asFreeNo
toExpensiveNo
intoVariableProbably
+

+ Example: +

+
    +
  • + Let's $x be a float. asInteger() will be + (almost) free. +
  • +
  • + Let's $x be an array. toString() will be + expensive because we have to iterate over the array, to allocate a + string, and to convert every pairs in the array as a string (like a + serializer). +
  • +
  • + Let's $x be an object. intoArray() will not be + that expensive, it might reference all attributes into an array, so + that's just one allocation. +
  • +
+

+ Conversions prefixed as and into typically + decrease abstraction, either exposing a view into the underlying + representation (as) or deconstructing data into its + underlying representation (into). Conversions prefixed + to, on the other hand, typically stay at the same level of + abstraction but do some work to change one representation into another. +

+

+ This is not something we will use often, but it is important to have a + strict naming here. Based on this naming, the user will be able to choose + if the resulting data must be cached or not (for instance, all to + conversions are likely to be cached because they might be expensive). +

+
+