[comp.lang.misc] A bad design decision early on in A

nevin1@ihlpf.ATT.COM (00704A-Liber) (01/09/88)

In article <472@m10ux.UUCP> rgr@m10ux.UUCP (Duke Robillard) writes:
		[some stuff deleted]
>
>But with a *real* implementation of data hiding, you wouldn't have to
>go back through that long chain of garbage.  To set some variable of
>type foo, you'd call a function called set_foo.  To print the time,
>you'd call a routine called print_time_t.  This is a major concept 
>behind "object oriented programming" languages, like smalltalk or (maybe)
>C++.
>

(Please follow this up to comp.lang.misc)

I really hated doing this back in the days when I programmed in Modula-2.  I
ended up having a lot of functions which did nothing but set and read
variables.  Unless you have a real smart optimizing compiler, using function
calls instead of just referencing the variables has a large cost associated
with it.  (Yes, I know that in some situations you would rather have function
calls because you can check for a legal value, valid range, etc., but that is
another story.)

Also, in order to use time_t (besides just printing it out), I do need to know
what type it is.

BTW, if you really need to do data hiding in C, you can use external static
variables and write functions to access them (see K&R section 4.6).
-- 
 _ __			NEVIN J. LIBER	..!ihnp4!ihlpf!nevin1	(312) 510-6194
' )  )				"The secret compartment of my ring I fill
 /  / _ , __o  ____		 with an Underdog super-energy pill."
/  (_</_\/ <__/ / <_	These are solely MY opinions, not AT&T's, blah blah blah

rgr@m10ux.UUCP (Duke Robillard) (01/12/88)

In article <3309@ihlpf.ATT.COM> nevin1@ihlpf.UUCP (00704A-Liber,N.) writes:
>In article <472@m10ux.UUCP> rgr@m10ux.UUCP (Duke Robillard) writes:
>>... To set foo, you'd call a function called set_foo.  To print the timet
>>you'd call a routine called print_time_t.  This is a major concept 
>>behind "object oriented programming" languages, life smalltalk 

>I really hated doing this back in the days when I programmed in Modula-2.  I
>ended up having a lot of functions which did nothing but set and read
                          ^^^^^^^^^^^^^^---this is the definition of an object
>variables.  Unless you have a real smart optimizing compiler, using function
>calls instead of just referencing the variables has a large cost associated

  I agree here.  Object-orientedism is more than a language definition,
  it's a way of life.  That's why Smalltalk is a whole programming 
  environment, rather than just a compiler/interpreter.  You've got to
  get away from thinking that some variable is an "integer" so you can
  add something to it.

  I don't know a whole lot about C++, but it makes me nervious--it seems 
  like they did it half-way, which can lead to the "data-confusion" you 
  complained about originally.

>Also, in order to use time_t (besides just printing it out), I do need to 
>know what type it is.

  Again, in real OOPS, you'd have a function (method, actually) for every
  possible use of the time_t.  I agree that this is a bizarre concept in
  C (the world's highest level assembly language) but it's an integral 
  part of OOPS.

  moral:  don't write Smalltalk programs in C.


> _ __			NEVIN J. LIBER	..!ihnp4!ihlpf!nevin1	(312) 510-6194

-- 
+                                
|               Duke Robillard, novice pagan. 
|       AT&T Bell Labs           m10ux!rgr@ihnp4.UUCP                 
|       Murray Hill, NJ          {any biggy}!ihnp4!m10ux!rgr