aboutsummaryrefslogtreecommitdiff
path: root/notes/givemes_normal_classes.txt
blob: 3ad42bd002e465ffd280a756394301d1d6c66daf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122

Can service stuff (like giveme's) be merged into normal classes?
================================================================

Super-simple solution with default values
-----------------------------------------

Perhaps add a keyword for implicit parameters:

    param int x = 0
    int y

    constructor
        int half_y
    code
        this.y = 2 * half_y
    end

This allows (type, name, default-value) to be specified. That would be
enough for many cases, but it feels a bit too limiting.

More powerful syntaxes
----------------------

    # Current syntax:
    # The good part is that it's not possible to "sneak in" some
    # capability somewhere else (but that can be prevented with normal
    # fields also).
    giveme
        int x = param "-x,--x-value" 0
    end

    # This has two types, which can be redundant.
    int x from CliParam "-x,--x-value" 0

    # This syntax is compact, but how intuitive is the distinction
    # between `:` and `=` ?
    # Also, `:` is used in many languages for indicating a type.
    int x : param "-x,--x-value" 0

    # 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