const challenge

Steven Schveighoffer schveiguy at yahoo.com
Thu Jan 31 10:58:28 PST 2008


"Jason House" wrote
> Steven Schveighoffer Wrote:
>
>> However, I'm not sure how you use it, or if you need to have multiple
>> instances of x.
>
> I made up the scenario based on what I remember from the const debates.  I 
> don't have the original post or remember who posted it.  I was really 
> hoping for those who regularly use const-based design patterns in other 
> languages to jump in with examples that exist in their code.
>
> I hoped that me providing an example might inspire others to add more 
> examples.  I unfortunately don't have sufficient appreciation for the 
> original poster's feeling to do it justice.  I also recall some argument 
> about handling widget draw routines.  If they're a constant object but 
> need to draw themselves on something.  I haven't done any detailed GUI 
> programming outside of java beans or GTK, so I tried to stay away from it 
> and hope someone else would post it.  I've at least done some logging and 
> can appreciate problems with multi-threading.

I remember this example, and when I saw it, I agreed with the poster, that 
transitive const makes this type of thing more convenient.

However, I've proven that transitive const is a subet of const, and 
therefore, not necessary.  If something is transitive const, it means that 
it is partially const, meaning it's not const.

I believe that there is always a way to redesign your thinking to have const 
work.  If you have a const widget and need to have it draw itself, pass in 
the non-const values needed to do the drawing.  Or if you absolutely have to 
have a structure with a draw routine that doesn't take the argument of the 
thing to draw it on, then create a wrapper structure that isn't const but 
contains the const widget.  Or change your widget so the data you want to 
remain const is declared const.  It's hard to speculate without seeing the 
actual code, but I believe it's possible to solve.

>
> Mostly, I feel like the const debate has really died down (probably a good 
> thing), but now we need to open the door once more to ensure potential 
> users are happy with the const design.  I have to imagine there's still 
> people out there that think transitive const is a bad thing and still 
> others that think transitive const is the best thing since sliced bread. 
> I'd really love to see them jump into this thread and provide some real 
> examples.

I think the transitive const debate has died down.  I still believe the 
head-const debate is very much alive, and I'm prepared to argue my side if 
anyone should challenge that validity.  Last I checked, nobody had refuted 
my points that head-const for a class was possible and useful :)

-Steve 





More information about the Digitalmars-d mailing list