What purpose to const besides functional programming?
superdan
super at dan.org
Tue Jul 22 19:21:27 PDT 2008
Walter Bright Wrote:
> Jason House wrote:
> > Walter Bright Wrote:
> >> It is one of the points of the const system. But the idea is not to
> >> just declare things invariant and magically they will work in
> >> functional style. The idea is that if you want to make something
> >> functional, the language will provide support for it if only in the
> >> form of telling you when something will not work in functional
> >> style. That appears to be the case with bar() - it cannot work in
> >> functional style.
> >
> > Can you answer this more thoroughly? It's really important to this
> > dialog. What *other* purposes does the const system serve besides
> > opening the door to functional programming? I understand that the
> > const system must remain simple to be usable.
>
> 1. It makes function APIs self-documenting.
> 2. Invariance allows one to pass large data structures around by
> reference yet treat them as if one passed them by value. Strings are the
> canonical example of that.
> 3. Const allows one function to service both mutable and invariant
> arguments.
> 4. Invariant data can be placed in hardware protected readonly memory,
> such as ROM.
> 5. Invariant data does not have to be synchronized to be multithread
> accessible.
> 6. Invariant data improves the ability of automated tools to make
> inferences about what is happening. Optimization is an example of such.
yeah. tell brad or andrei or whoever came up with that stuff that i'll buy them a beer for point 2, i'll wash their feet for 3, and i'll buy them dinner at ritz for 5. fuckin' a.
More information about the Digitalmars-d
mailing list