diff options
Diffstat (limited to 'notes/givemes_normal_classes.txt')
-rw-r--r-- | notes/givemes_normal_classes.txt | 82 |
1 files changed, 81 insertions, 1 deletions
diff --git a/notes/givemes_normal_classes.txt b/notes/givemes_normal_classes.txt index ab62c5e..3ad42bd 100644 --- a/notes/givemes_normal_classes.txt +++ b/notes/givemes_normal_classes.txt @@ -1,4 +1,4 @@ -Can service stuff (like giveme`s) be merged into normal classes? +Can service stuff (like giveme's) be merged into normal classes? ================================================================ Super-simple solution with default values @@ -40,3 +40,83 @@ More powerful syntaxes # Better than the above? Somewhat intuitive also. int x from param "-x,--x-value" 0 HttpRequest req from default + +Replace constructors with giveme's? +----------------------------------- + +For example: + + # Definition of `SomeType` + giveme + File f + end + + data + long filepos + end + + entry initialize + code + filepos = 0 + end + + + # Usage + entry main + code + File f = new + f.open "test.txt" + SomeType st = new + st.f = f + st.init + end + + # Usage, with implicit(!) creation on first use: + entry main + code + File f + f.open "test.txt" + SomeType st + st.f = f + st.init + end + + +Or even replace both with typestates: + + # Definition of `SomeType` + data + File f + when initialized + long filepos + end + + entry initialize + transition + initialized + code + filepos = 0 + end + + + # Usage + entry main + code + SomeType st + end + +Or, even more general: + + data + after created + File f + after initialized + long filepos + end + + func initialize + transition + created to initialized + code + filepos = 0 + end |