March 17, 2014 –

O.k I’m back! I ddidn’t finish yesterday ’cause I was tired, hehehe.

So there are two global things we have to keep in mind. Global constants (apparently I’ll have to use that on lab 5) and Global variables. The prof told us not to use the latter. They are a bad idea.

Global constants are constants available to more than one function. So they are not declared inside any function body but outside. Even outside of int main. I found this weird. I guess it’s because I always saw int main a huge thing that blah blah, things you know. But now I’m over it, lol. Anyway these have to be declared before before any function that uses it so it’ll work.

Global variable are basically declared the same way and are available for many functions but the reason why they are not a good idea is that they programs difficult to understand/read/maintain. It is for this reason that they are seldom used.

Another interesting thing we covered in class was Overloading functions, I think it’s a tad confusing… I’m not sure if I would like to overload functions… Anyway this overloading is when you provide more than one declaration and definition using the same function name. The slides says they are very convenient when the same func is needed for diff numbers or types (like double and int) of arguments. Eh, I guess I’m starting to get how this could work. This is why I love blogging about this class!!! I wish we had to make a blog for every single class. But that would take waaaaaaaaay too much time I guess.

O.k, other important concepts from chapter 4 are the black box!

Image

 

This pic basically explains what it is.When you design a function you have to do it in a way that whoever reads it doesn’t have to know how it is done but clearly sees the result of it something like that. You hide information so that the function can be used without knowing how it is coded. The pic does a better job than me at explaining this, lol. A term closely related to black boxes is procedural abstraction. Which can be defined word by word. Procedure is a set of function like instructions and abstraction, in programming, is when you abstract away the code. So when you do procedural abstraction in functions you just do the black box. The function can be used without knowing how it does its thing. Egh.. I’m a tad confused. Procedural abstraction sounds like it = black box…

Top down design: it is the same as stepwise refinement. You start with a small description of what your program will do then you break it into tasks and then tasks within those tasks. It sounds pretty amazing and I understand this is obviously part of the problem solving Phase. So I guess this is done is Pseudocode. Or is part of it.

After all of this we started with Chapter 5: Functions for all subtasks.

A datatype defines a set of values and operations allowed on those variables, right? Well now we begin with a very peculiar/confusing new data type……… VOID. A.K.A THE EMPTY TYPE. Why? Because it has no values and because of it there are no operations. I still fail to get the point of this type. But I know I will when I decide to blow my mind with lab 5. A void function return NOTHING!!! But it has its things that it can do. For example we can cout from this function. But then again I understand we could do that w/ the other func as well.

So this girl suddenly made an interesting question this day that we took this class. She was like why return 0? Can’t we return 1? I had wondered the same thing for a while. The prof said that we could return whatever but f we don’t return 0 (at the end of our progs) then we can’t use them as building blocks for [wait I didn’t write what we can’t use them as building blocks for, lol. But I think it was] bigger programS?

So the thing is that with void functions you don’t always need to write return at the end of said func. You only need it when you need to return above in your program.

So an expression has a value but a statement is a side effect. It does not have a value. That is the diff between those two. Just saying. But you can use an expression where a statement is expected.

Ugh. Now we start with call by reference parameters. Call by value can’t be used for EVERYTHING so we use call by reference in those cases. After the prof said these things he went on to give us a very complicated example about how if you want to switch the value of a var w/ another you can’t use call by value. But then you use the ampersand symbol and you give the function? access to the variable and it works and that’s called call by ref. 

 

Image

 

I have here the ampersand is a specification of the parameter passing. Hmm i guess that explains the acess thing. Anyway I have to go to class so I’m leaving!! Bye!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s