Mutators bad... inspectors ok?

Started by
16 comments, last by freeworld 12 years, 8 months ago
I think I just threw up a little in my mouth.


Of course, some people are going to see this and say, "hey, C++ is so great! It lets you do stuff like this to express rich semantics!"

My reaction, though, is "hey, C++ is disgusting! It requires you to do stuff like this to express rich semantics!"

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

Advertisement
My reaction, though, is "hey, C++ is disgusting! It requires you to do stuff like this to express rich semantics!"

Have you ever considered using a purely functional programming language like Haskell (http://haskell.org)? One of my professors at the university (mathematics) was very fond of this language, and as far as I know it uses a very clean and "mathematically correct" syntax.
hey, C++ is so great! It lets you do stuff like this to express rich semantics!
I know, right!

You can even make your own keywords![source lang=cpp]#define hidden( type, name, access_rights ) \
class { type v; [color="#808080"][font="Consolas,"] [/font]\
type& operator=( const type& o ) { v = o; return v; } \
operator type&() { return v; } [color="#477280"][font="Consolas,"] [/font]\
operator const type&() const { return v; } \
type& operator=( const type& o ) { v = o } \
access_rights } name
#define visible(type) friend type;

class BigStuff
{
hidden( int, Foo, visible(BigStuff) visible(FooBarAccess) );
hidden( std::string, Bar, visible(BigStuff) visible(FooBarAccess) );
hidden( float, Baz, visible(BigStuff) visible(BazQuuxAccess) );
hidden( bool, Quux, visible(BigStuff) visible(BazQuuxAccess) );
};[/source]

[quote name='ApochPiQ' timestamp='1311730336' post='4840905']My reaction, though, is "hey, C++ is disgusting! It requires you to do stuff like this to express rich semantics!"

Have you ever considered using a purely functional programming language like Haskell (http://haskell.org)? One of my professors at the university (mathematics) was very fond of this language, and as far as I know it uses a very clean and "mathematically correct" syntax.
[/quote]

Have you ever used Haskell? It's module design is probably the only thing vaguely related to access levels, and that isn't really super full featured (compared to say... it's type system).

And really, why consider disgusting things to express semantics when you can use a language that requires disgusting things to express such straightforward concepts as state, or IO? (kidding!)

[quote name='ApochPiQ' timestamp='1311730336' post='4840905']My reaction, though, is "hey, C++ is disgusting! It requires you to do stuff like this to express rich semantics!"

Have you ever considered using a purely functional programming language like Haskell (http://haskell.org)? One of my professors at the university (mathematics) was very fond of this language, and as far as I know it uses a very clean and "mathematically correct" syntax.
[/quote]



Using other people's broken languages is for weenies. tongue.gif

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

Using other people's broken languages is for weenies. tongue.gif

I can't say I have ever heard of the Epoch language before; I take it you are somehow involved in this project?

True genius is not being able to create a perfect language, but being able to create perfect software with a broken one =P

True genius is not being able to create a perfect language, but being able to create perfect software with a broken one =P

True genius is sitting on a beach somewhere warm while someone does both of those for you 8-)

@freeworld - if you've got a class with a lot of accessors and/or mutators, it's often a sign that the class doesn't have a very solid responsibility.
Often in those cases, I'd just make it a struct with no member functions at all. Then perhaps a useful class can be built around that struct.
e.g. your variables could go into an [font="Courier New"]EngineInfo[/font] struct, which many different parts of code can operate on. e.g. a car can own one as a member and perform a simulation on it, a dyno can recieve a const-reference to one to update it's graph, etc... Doing this also breaks the dependency between [font="Courier New"]Car[/font] and [font="Courier New"]Dyno[/font], as instead, the both have a dependency on [font="Courier New"]EngineInfo[/font].


This is actually the approach I'm tinkering with right now. Instead of using a chain of inheritance to contain the widgets within a root widget. I'm thinking of using a sorta' factory class "Menu" that manages widgets, instead of the widgets managing themselves.
[ dev journal ]
[ current projects' videos ]
[ Zolo Project ]
I'm not mean, I just like to get to the point.

This topic is closed to new replies.

Advertisement