- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Admin
Admin
Admin
they invented a bycicle. Mayn modern languages, for example Delphi, do have "properties" in their objects, and property's getter and setter can be either member-variable or member-method, or just null to disallow getting or setting a value. That does not have binary compatibility (if you change binary library setter or getter from one type to another - you need to recompile whatever is using the library), but in object code and source it looks the same and just need to be quickly recompiled. Thus you can avoid breaching the security, not to waste CPU calls if it is important, and introduce a subroutine as getter or setter as soon as you need it.
or you can use seom virtual machine (JavaVM, MS CLR, etc) which i hope are smart enough to JIT-compile primitive getter/setter stubs to direct access to the corresponding member-variable.
Admin
i worked on what you might call a big project, where couple of departments in the firm had to cooperate. first the interfaces were drawn (public methods) and they were made fixed, so there was no way you could re-work all the stuff dependent on it. i was not even there when the entire thing was designed i just got the documentation of the interfaces and proceeded to write private methods that implemented the behaviour. if i needed to change any of the public methods (including the modifiers) i had to fill a form in triplicate and sacrifice seven ounces of my blood to the god of application design and wait until a joint commission of the departments involved had a meeting and gave their blessing.
i somehow managed never to do such a thing.
Admin
If something fundamental like the fact that you're not supposed to write to a field can only be learned from the documentation or comments, it's simply a badly designed API. If it were written in the name (i.e. prepending them with "readonly_") it might be acceptable, but then why not go the full distance and make it a keyword enforced by the compiler?
Admin
If the third-party header file you are trying to hack includes a standard header, then you're violating this rule anyway. And, no, you cannot redefine #include. ;-)
Admin
What really sucks about most comments here is that everyone keeps repeating how that C++ private/protected/public crap is actually any good. I mean header files that define private variables that you can see the names of but not use, that's just stupid. Why not use a proper OOP language with seperate interface/source files, like Ada or Modula-3? Then you won't need to have any of this private variable stuff, if they're not in the interface file, you won't even know they exist, let alone read/write to them.
Btw, Oberon (another Pascal descendant) has read only fields.
Admin
Right on... I only use public byte arrays for speed reason of course
Admin
Nothing wrong with scripting languages. But, if you're a big ol' optimisation sucker, and you don't care about correctness, then you almost certainly lose out both ways.
Admin
A few queries on definitions here:
(a) What exactly is a "proper OOP language?" (For once in your pitiful little life, Do Not give examples.) (b) How important is it, in the general sense, that you can see the name of a variable? Can you see the name of God? Are you bathed in the blood of the Lamb?
Oops, sorry, got distracted there. 'Nother topic. (c) Do you know how to spell "separate?" If not, can you look it up?
BTW, and it's not worth much, C++ has read-only fields too. They're called "const" or "mutable", depending upon whether the object/class can write over them or not. Tiny and pointless language semantic difference, there. And, language flames aside, I believe that Java, .NET flavours, etc, have exactly the same basic ideas.
Oberon? You're having a laugh. Come back when you've worked in the real world, with a real world language. Or failing that, write one yourself, and convince us that it's worth wasting our time to learn.
Admin
Admin
My point was if you want to enforce proper data protection, which is the point of this wtf, you should use separate interfaces. Just because C++ is a real world language (go on, define real world language, moron) does not make it perfect. Its method of enforcing proper data protection is quite inadequate.
Separating interfaces from the definitions is not a Tiny semantic difference. In fact, if you had bothered to actually do any reading about Modula-3, you would discover that its compiler will only recompile modules if any interfaces they use have changed, which was also a topic mentioned earlier.
So with regard to your questions: (a) There probably is no perfect OOP language, but in as far as this discussion has been about data protection and maintaining public definitions, Modula-3 is far superior to C++, since it offers partial types and separate interfaces.
(b) Why not just put all the source code in the header files? How about readability? Or maintainability? What happens if add my own class to the list of friend classes in a header?
Wow, that's just stupid. Really stupid.(c) Wow, I misspelled a word. Do you want a medal? You tell me to look up the spelling of a word and then tell me that having separate interfaces is a tiny semantic difference. Did you even look up any of the languages I did mention?
So you work in the "real world", do you? I suppose you would have told the people you developed Java the same thing when it was first released. Or C++ for that matter. And in case you don't know, and obviously you don't, both Oberon and Modula-3 have influenced the development of Java.
Have you even tried using any language that isn't a "real world language"? People like you who work in the "real world" and only use "real world languages" don't develop the languages you use.
I have actually written my own language, but it's more suitable for scripting so is not relevant for the problem in this wtf. So unlike you, I'm perfectly capable in saying that it's not at all the correct language in this case.
How about you? Have you written the language you use? No? Then SHUT UP, SIT DOWN and type away at whatever language someone else TOLD YOU to use. You're not going to improve things for anyone else, let alone yourself.
Admin
[quote user="real_aardvark"][quote user="Bored Bystander"] BTW, and it's not worth much, C++ has read-only fields too. They're called "const" or "mutable", depending upon whether the object/class can write over them or not.[/quote]
Sorry, I missed this when I replied last time. What I meant to say about Oberon is that it has read only exporting, i.e. variables that are fully writable within their defining module but only readable from outside it.
So yes, another reason why you're a moron.
Admin
I just tell everyone to leave my privates alone...
Admin
I've never commented here before (in my 2 years of reading it), but the pure stupidity of the assertions people are making about C++ has forced me to act.
(1) Languages have nothing to do with the performance of a given program (which is obvious; however, it must be said because apparently it's not obvious to the people here).
(2) C++ does indeed have "read only" variables. It's called const. (Although yes. One cannot have a variable be publicly const while privately mutable without the aid of a function)
(3) I would like to be shown where in the C++ standard it says that an implementation cannot inline non inline functions? (Well, I already know that it doesn't, but you people really should look anyway).
Of course we do actually live and program in the real world. In which languages are actually compiled and have finite performance.
Which is great, because all major C++ compilers currently support IPO. gcc intel msvc llvm (btw, llvm can JIT also... so good bye DLL/ABI problems)
I'm sure there's more misinformation to correct, but It's too painful to read through the comments anymore than once.
Moral of the story: nothing is constant (except for const variables! :P (well actually, you can hack around that...)).
Admin
Ah yes. So, without any getters and setters - what do you do when later on you decide to be more sensible than just "expose(ing) atomic, internal data" and want to add code which does some sensible checking before setting data or create defensive copies of instances of types which are mutable and in fact shouldn't be?
It seems that you might be talking about Java (because of the terms "getter" and "setter"): Did you ever waste a thought, why all the setters in java.util.Date are deprecated? And why this doesn't solve the problem, because a deprecation warning never has hindered any given dork to use deprecated APIs anyway? You can solve this problem by defensice copying, though. But this can only be done if your field of type Date is not public, because you have to code this somewhere.
If an API is published without being thought through properly (e.g. leaving stuff public just for "convenience" or "performance"), it is extremely hard and often impossible to revert these wrong decisions later on.
Admin
What you call "Just-In-Time allocation" and what you made that term up for does already have a name: "lazy loading", or more specifically "lazy initialization" (or "lazy instantiation" in OO, as opposed to "eager ...")
BTW, most versions of the Singleton Pattern do additionally use some variation of lazy instantiation, therefore the getInstance()-method looks similar to the "Butt"-example you quoted, and I'm sure that it's author MoronBoy intended just that. Otherwise I think he wouldn't have talked about the "need to wrap that getButt in a mutex".
And that's very probably the reason why real_aardvark pointed this out - no reason to diss him for that :o)
Admin
Being a masochist, I think I'll go back and read the previous comments before I commend my soul to an obviously ungrateful God.
Admin
A "real world" language is a language that is used in the real world.
Good enough definition for you?
Now, granted, this includes things like Java and VB6 and Cobol and even TRS-Basic, which I find incomprehensible but will accept because they give people warm and fuzzy feelings, and it doesn't really include functional languages from Lisp through Scheme to Haskell (or vice-versa -- I forget); although I dearly wish that it would.
It doesn't really include Oberon or Modula-3, though.
Nice to know you've written your own language. At least, now, you have somebody to talk to.
Nobody told me to use C++. I happen to find it useful in my line of work. I also use Perl, where appropriate, and Python, where I'm allowed to do so. And anything else that comes up.
Really.
Don't get your panties in a twist.
Admin
As for 'const' members, I find those useful too.. and NOT because I want to leave a member public so that client code can get to it... sometimes you really do have members that should never be changed after the object is created... common examples for me are most functor members and things like an id.
Admin
C++ has an "inline" directive to put on functions. So, "inline" functions don't have be in the headers class Name {...}; block. We can write the function in a .cpp file, like this:
inline int Name::get_some_int() const { return this->some_int; }
This makes the class definition in the headers easier to read. This also helps hide the implementation details. Such practice is good for a C++ library, where the header files are shipped with the final build to compile & link.
Admin
Great definition, "it's a real world language because I say so". In my original post, which you obviously did not read correctly, I did not say that Oberon and Modula-3 were widely used languages. However, they are usable languages, for a lot of the situations where C++ is used. So why not use them? If more people used them, then would you consider them a "real world language"?
You use Python? Until relatively recently (compared to Perl, C++, etc), Python was unheard of. What made you decide to use this "real world language"? A language that changes its semantics nearly everyday? Have you even looked at any non-"real world languages"?
To recap:
I named some other languages which some people here may have not heard of before. I gave some (albeit very brief) information about why they may be more suitable for data protection. Both languages are stable and there exist some decent development tools for them. Maybe, just maybe, one reader here has decided to look them up and adopt them, even for a small project.
On the other hand, you ranted on about the real world, said something stupid about sheep, and corrected a spelling mistake. You told me to go write my own language for some reason (after a post where I gave examples of other languages I thought were good specifically for data protection). When I told you I had, you said something about talking to someone, whatever that was supposed to mean.
All in all, do the world a favour and shut up.
Admin
You would do well to follow your own advice. Both of you are boring me to tears.
Admin
Accepted. Still, I can't believe you read all that.
Admin
Sometimes programmers run their programs on more than one system. Sometimes the differences between systems cause differences between fully optimised machine code.
Sometimes programmers use really shitty compilers/linkers. If your compiler/linker can't automatically inline accessors of every variety, don't use it. Find one that performs this optimisation, which shouldn't be difficult considering the complex optimisations most common compilers/linkers perform (eg. dead code elimination).
If it turns out that your compiler/linker is poor, but you can't change your choice, then that's a small wtf. Profile your code to determine which functions to look at optimising. If you don't perform this step, then you're committing a much larger wtf. As computers/compilers/linkers can vary so significantly, it may be that the optimisation you're choosing to perform manually may cause other parts of the system to slow down. How would you know, unless you were to take the time to produce and compare profiler stats of the program before and after?
If it turns out that there's a more significant optimisation to perform, you probably won't even need to perform this micro-optimisation. If profiling and testing proves that the optimisation produces no negative affects, then I suggest finding an open-source C++ compiler so you can modify it to perform the micro-optimisation automatically.
Admin
I know what you're trying to say here, and it's a good thing, but...
Please show me where in the C# specification it says that C# fields are "insanely fast racing C++ fields"?
Please show me where in the Java specification it says that Java is a "RAD system"?
Admin
Please show me what part of the C++ specification (n3337.pdf, IIRC) makes you believe that function "actually ends up being a push on the stack"?