8 Replies - 1317 Views - Last Post: 05 March 2009 - 01:41 PM Rate Topic: -----

#1 Smurphy   User is offline

  • D.I.C Regular
  • member icon

Reputation: 35
  • View blog
  • Posts: 367
  • Joined: 07-July 08

Dont ask dont tell (Functions as Black Boxes)

Posted 05 March 2009 - 10:04 AM

Well the other day in my C class we began talking about functions. Our teacher explained we have already been using functions printf, scanf, pow etc etc. But he had to add in that we don't know what they look like and we do not care. So first question (I tried google no help.) What does printf actually look like? Second as a programmer is it better to not care what the function looks like and only care that it works? I would really love to know what the functions I use look like. I understand how in time crunchs and work situations I would be glad to have it done no questions asked. But a person that enjoys and loves programming why not try to understand everything I work with.
This actually goes for all programming not just C. When I use C# or javascript I want to know what the computer is being told to do. So as programmers do you care about what your functions look like or no?

Is This A Good Question/Topic? 0
  • +

Replies To: Dont ask dont tell (Functions as Black Boxes)

#2 KYA   User is offline

  • Wubba lubba dub dub!
  • member icon

Reputation: 3202
  • View blog
  • Posts: 19,233
  • Joined: 14-September 07

Re: Dont ask dont tell (Functions as Black Boxes)

Posted 05 March 2009 - 10:27 AM

Yes, it is always better to know, at the very least, how something works. This helps us not reinvent the wheel every day. Your teacher is probably telling you this so you can get a foundation before you start doing your own things. printf() is part of C's stdio so there really isn't a need to explore it in his eyes. To see printf(), you just go to its header, for example:

//inside stdio.h
_CRTIMP __checkReturn_opt int __cdecl printf(__in_z __format_string const char * _Format, ...);


Was This Post Helpful? 1
  • +
  • -

#3 Bench   User is offline

  • D.I.C Lover
  • member icon

Reputation: 944
  • View blog
  • Posts: 2,464
  • Joined: 20-August 07

Re: Dont ask dont tell (Functions as Black Boxes)

Posted 05 March 2009 - 11:37 AM

When you work with a large system theres usually no way that any one person can understand the exact workings of every individual component (Especially if its a system which has already been in place for some time before you started work on it) - usually you just need to accept that certain things will always behave as advertised (And if they don't, its not your problem). Get used to the idea that much of the time you'll be working with "black boxes" - because that's how large systems evolve, and for 99.9% of the things you need to do, knowing exactly how something works on the other side of the "Cloud" won't help you accomplish your goal anyway.

Its also a good habit to get into the idea of encapsulating knowledge of certain processes and concepts into black boxes if you want to learn about the Object-Orientated paradigm; for which such "selective ignorance" is a central theme. In other words - even if you do know how something works, you might choose to ignore it in order to design a more generic, reusable module. This is actually sometimes harder than it sounds because at this point you need to start challenging your own assertions about how something which you are creating may be used further down the line.

This post has been edited by Bench: 05 March 2009 - 11:54 AM

Was This Post Helpful? 0
  • +
  • -

#4 Hyper   User is offline

  • Banned

Reputation: 108
  • View blog
  • Posts: 2,129
  • Joined: 15-October 08

Re: Dont ask dont tell (Functions as Black Boxes)

Posted 05 March 2009 - 11:53 AM

Certian things are "black boxed" for a reason. That applies to more than just programming.
Was This Post Helpful? 0
  • +
  • -

#5 Smurphy   User is offline

  • D.I.C Regular
  • member icon

Reputation: 35
  • View blog
  • Posts: 367
  • Joined: 07-July 08

Re: Dont ask dont tell (Functions as Black Boxes)

Posted 05 March 2009 - 11:55 AM

Thanks guys this is really interesting to me. I appreciate both your fields of view. I have always found it interesting how things evolve and the thought process behind things. I will certainly look at "Selective ignorance".
Was This Post Helpful? 0
  • +
  • -

#6 boblied   User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 66
  • Joined: 20-February 09

Re: Dont ask dont tell (Functions as Black Boxes)

Posted 05 March 2009 - 12:04 PM

Beyond a certain point, all the details behind the scenes are simply overwhelming. If you can spare the time, it's fun to look, and you can get ideas about how things are done. But too often, it's simply a tangent that you can't afford to waste time on.

And, by the way, the internals of printf are grosser than you can possibly imagine.
Was This Post Helpful? 0
  • +
  • -

#7 Bench   User is offline

  • D.I.C Lover
  • member icon

Reputation: 944
  • View blog
  • Posts: 2,464
  • Joined: 20-August 07

Re: Dont ask dont tell (Functions as Black Boxes)

Posted 05 March 2009 - 12:05 PM

View PostHyper, on 5 Mar, 2009 - 06:53 PM, said:

Certian things are "black boxed" for a reason. That applies to more than just programming.

As a general rule, I despise Analogies, but I think this one is rather apt- (its not mine, I stole it from a programming book)

Consider learning to drive a car - any car, it doesn't matter. You'll learn that the big wheel in the middle makes the car go left and right; the pedal on the right-hand side makes it go faster, the one in the middle makes it stop, and the one on the left-hand side pulls the clutch plates apart and lets you change gear.

That's your black box interface. What's significant about this interface, is that you can go to any implementation of a car in the world, and your interface will be constant. Nobody cares how different manufacturers make their cars work, you can rely on your assertion that each pedal will always control the car in pretty much the same way; and you can drive your car equally well regardless of whether you're a car mechanic or not.

If that interface didn't exist. I'm sure driving would be a hellish experience - Juggling different factors such as how much petrol to feed to the engine at a time, how far to pull the plates apart, how much pressure to apply to the wheels to brake, controlling the angle of the front wheels yourself. Sure, you might have some fine-grain control over the vehicle, but who'd even have time to see what was happening in the road ahead?

This post has been edited by Bench: 05 March 2009 - 12:13 PM

Was This Post Helpful? 1
  • +
  • -

#8 Hyper   User is offline

  • Banned

Reputation: 108
  • View blog
  • Posts: 2,129
  • Joined: 15-October 08

Re: Dont ask dont tell (Functions as Black Boxes)

Posted 05 March 2009 - 12:06 PM

Being a mechanic has its own benefits (seldom), at times.
Was This Post Helpful? 0
  • +
  • -

#9 polymath   User is offline

  • D.I.C Addict
  • member icon

Reputation: 54
  • View blog
  • Posts: 670
  • Joined: 04-April 08

Re: Dont ask dont tell (Functions as Black Boxes)

Posted 05 March 2009 - 01:41 PM

Selective ignorance... if you want some of that, just look at java. That language relies on its users to be selectively ignorant :P

Disclaimer: I've used java before and found it very easy to pick up. It's just so much more fun bashing it than actually appreciating it for what it is :) Sometimes selective ignorance is fun, but my main c++ project is my kernel, so i can't afford to be ignorant at all.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1