Welcome Guest ( Log In | Register )

 

SMTWTFS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

Request A Topic!
Want me to blog about something? Perhaps a language? A piece of software? A specific topic? Let me know! Even guests can post here on my blog!

If you would like to request a topic, please post a comment here and I'll get on it right away! smile.gif

Search My Blog


Categories

 | Category: Key Concepts and Theory
entry 2 Nov, 2008 - 01:45 PM
Topic Requested By: red_4900

This article is going to cover three methods of programming: Object Oriented, Aspect Oriented, and Procedural. Of course, these styles have their benefits and their liabilities. But solutions often combine all these styles, in order to create the most managed code.

To those of you who know me: You know that I'm not much of a writer. I keep it on more of a "layman's terms" basis, keeping it short and to the point. This is why I'll be offering a demonstration, using the widely known "fizz buzz" example: Print numbers 1 to 100, printing "fizz" if the number is a multiple of 3, "buzz" if it is a multiple of 5, and "fizz buzz" if it is divisible by both 3 and 5.
NOTE: The solution offered will be a little impractical. I need to break it down into more functions than necessary, to demonstrate the various styles. At the end of this entry, I'll provide a final solution, which is the simplest possible.

So what are they, put simply?

Object Oriented Programming: A style of programming which is based around objects. This is the most common style of programming in the industry.

Aspect Oriented Programming: Often written to complement an OOP solution. Hard to explain in short, but basically, it's main use is to keep your OOP code organised, without having to scatter various aspects of code across several objects.

Procedural Programming: This is the "old school" style of programming. Less commonly used now~ The main language (which is still used within the industry) which still focuses on this style is C.


These sound interesting. How do I know which is best for me?
Like I already said, solutions often combine these styles. The whole purpose is to create code that is well managed. Time to get into the more nitty-gritty stuff~


Procedural Programming
Like I said, this is much less common than object oriented programming nowadays. However, this doesn't mean that procedural programming is without benefits! In fact, the main reason that I like C++ is that it allows the programmer to combine procedural programming with OOP. procedural programming is also known as "Functional Programming."

Basically, procedural programming is entirely a 1-way system. There's no major data grouping (the main benefit of OOP) so you're basically working with nothing more than variables, loops, and functions. (Everything but objects, basically)

The obvious benefit to procedural programming is that you don't need objects for everything. Take a look at Java, as an example. Everything has to be contained within a class. What about if you just want one function to do something really simple? (Obviously, this is also a drawback of OOP, so you'll be reading this again in a bit)

The main drawback is that there is no major data grouping. With an object oriented language, it's easy to keep everything organised~ Variables and methods go in the appropriate classes.

Here's the previously mentioned example. Remember, this is not the best way to tackle this problem. It's been broken down into various functions to create a better demonstration.

The key point to notice here is that our variable has to be passed around to various functions. OK, so this could be solved by a global variable, but no one likes global variables... tongue.gif

Procedural Demonstration
#include <stdio.h>

// no objects here!

void FizzBuzz(); // our function to perform the fizz buzz operation
bool ByThree(int); // a function to check if a number is divisible by 3
bool ByFive(int); // a function to check if a number is divisible by 5
void PrintFizz(); // a function to print the word "Fizz"
void PrintBuzz(); // a function to print the word "Buzz"

int main() {
FizzBuzz();
return 0;
}

void FizzBuzz() {
int i = 1;
for (i; i <= 100; i++) {
if (ByThree(i)) PrintFizz();
if (ByFive(i)) PrintBuzz();
if (!ByThree(i) && !ByFive(i))
printf("%d", i);

printf("\n");
}
}

bool ByThree(int x) {return (x % 3 == 0 ? true : false);}
bool ByFive(int x) {return (x % 5 == 0 ? true : false);}
void PrintFizz() {printf("fizz");}
void PrintBuzz() {printf("buzz");}


For more information: http://en.wikipedia.org/wiki/Procedural_programming

Object Oriented Programming
OOP is a great way to manage your data. Put simply, it's a way to store variables, and methods together, to create an object. When creating your objects, you'll have to take into account how this object is going to need to interact with various other objects. This could be considered a disadvantage, since it takes more planning. Also, it can sometimes be awkward to come up with the best way for your object to interact with another.

Remember the key benefit of procedural programming? Well it's time for a reminder.
When programming in a language which is purely based around OO concepts (such as Java) then you might run into a bit of an annoying problem. What if you have a method to do something, which doesn't specifically belong in any of your classes? Maybe it can be applied to more than one of your classes~ Why rewrite it in each class? However, there are solutions to this. One way would be to use a "general" class, and call the methods from this class each time. Another way is to create a base class, containing these general methods. Then, each of your objects which require the method will inherit it from the base class.

Time for that example again. The key thing to notice now is that we no longer need to pass that variable around everywhere. It simply gets accessed from within the object.
Object Oriented Demonstration
#include <cstdio>

class FizzBuzz {
public: // our publicly accessable stuff
void Execute(); // our function to perform the fizz buzz operation
public: // our private stuff, that only the class really needs
int i; // the variable which we will use in our loop
bool ByThree(); // a function to check if a number is divisible by 3
bool ByFive(); // a function to check if a number is divisible by 5
void PrintFizz(); // a function to print the word "Fizz"
void PrintBuzz(); // a function to print the word "Buzz"
};

void FizzBuzz::Execute() {
this->i = 1;
for (i; i <= 100; i++) {
if (this->ByThree()) this->PrintFizz();
if (this->ByFive()) this->PrintBuzz();
if (!this->ByThree() && !this->ByFive())
printf("%d", i);

printf("\n");
}
}

bool FizzBuzz::ByThree() {return (this->i % 3 == 0 ? true : false);}
bool FizzBuzz::ByFive() {return (this->i % 5 == 0 ? true : false);}
void FizzBuzz::PrintFizz() {printf("fizz");}
void FizzBuzz::PrintBuzz() {printf("buzz");}

int main() {
FizzBuzz *fb;
fb->Execute();
return 0;
}


For more information: http://en.wikipedia.org/wiki/Object_oriented_programming

Aspect Oriented Programming
Basically, AOP is used to separate your solution into various aspects. It best complements OOP concepts, as previously stated.

AOP is used to allow an application to grow as time progresses. It allows a programmer to modify a static object-oriented solution to create a system which is capable of growing and meeting new requirements.

Consider AOP to be a way to meet requirements which are later added to a specification. You will develop an object-oriented solution for a client, and a few years later, your client comes back to you, asking you to alter the application to meet some new requirements. Rather than going through all the old code, you will dynamically change the application.

No demonstrations here. The best way to explain is with an example of something other than code. ohmy.gif

The best way to explain AOP is to compare it to an object in the real world. Consider a packet of crisps. (That's potato chips, if you're in America wink2.gif)
The manufacturers are always reducing the salt content, and making them taste better, right? Do you think they start from scratch when they make these changes?
More likely, they would make alterations, instead of completely re-inventing the flavour.

For more information: http://en.wikipedia.org/wiki/Aspect_oriented_programming




And after all that, we're finally done! Thanks for reading! smile.gif

 | Category: Key Concepts and Theory
entry 27 Oct, 2008 - 12:12 PM
My first blog entry in a long time that might actually be read-worthy. ohmy.gif

Anyway, this topic is one that we see oh too often in the forums. "Which language is the best?"

Well, that entirely depends on what you want to do, and which makes the most sense to you.

But there are so many! How am I supposed to pick one out of this huge list I found on Wikipedia?
Well, fortunately for you, very few of those languages are still in demand. In fact, a lot of them never even were in demand! Many of them are actually esoteric programming languages.

The list even includes languages that never were big~ simply languages which were created by individuals, for fun or for a specific cause. As an example, brainfuck has never been in demand. It was designed to be challenging, and when Urban Müller, the creator of the language, came up with the idea, it was simply because he wanted to make a language with the world's smallest compiler.

So, after a quick discussion of languages that you really didn't need to know about, let's get into the actual discussion of "which language is the best?"

Here's your answer: No language is the best. Each has it's pros, and each has it's cons.

But, I can give you my opinion of which language is best suited to which task. I've studied 15 languages (a forever growing number) and come up with an opinion of each~ what it's best suited to, advantages, disadvantages, etc...

Anyway, let's get down to the main point of this post before I get too side-tracked.

I'm going to offer one or two languages for each topic.

First Language?
This one is entirely up to you. I'm not making any solid suggestions here, aside from the main (most used) languages in industry. This is your most important language in my opinion, since this is the one that you're going to learn the logic and the theory behind all programming languages.
My first language was C++ and so higher level languages are easier for me to pick up.
I've heard a lot of people learnt Visual Basic as a first language, because the syntax is so user friendly and easy to pick up. (Personal opinion of the language: It's vile. I actually hate the syntax)

Game Programming
Personally, I think the best language to program games in is C++ because it's the most common language used within the industry (and it's what employers want, if you want to make games for a living.)

Aside from that, the language itself is easy to use, when you get used to it. It tends to be faster than other languages, and with C++ you create everything from scratch.

Recommended book: Game Programming All in One by Bruno Miguel Teixeira de Sousa.

Java is also becoming more and more common for games ~ particularly mobile games. I haven't done too much in Java, so I can't say a lot about it to be honest. Though a friend of mine studied it as a first language, and he loves the language.

Game Programming: Graphics Libraries
OpenGL (Open Graphics Library)
SDL (Simple Direct-Media Layer)
DirectX (Windows Specific)

Software Development
This depends on what kind of software you want to do. I'm going to suggest three languages, it's up to you to decide which one you want to go for.

First up, we have C++ (again! ohmy.gif) this time using the wxWidgets toolkit. It's a cross platform toolkit (meaning you can develop your applications for Windows, Linux, Mac, etc)

Reference: wxWidgets documentation.

Then, we have the .NET family. Specifically, I'm going to summarise C#.NET and VB.NET (together as one)
So, the .NET framework is really easy to use, and really well documented. Everything you need is built in, and you even get a nice little design view. How cool is that? You can just drag and drop the components into design view and play with the properties until you're happy. After that, you just have to add the functionality, which really isn't too difficult when you refer to the documentation over at MSDN. (Microsoft Developers Network)

Reference: MSDN

Web Design/Programming
Almost everyone knows at least a little HTML. (HyperText Markup Language)
If you want to get into web development, I think it's quite important to learn the stuff in a certain order. Start out with (X)HTML. It's really basic stuff~ it's not a programming language, it's a markup language.

Then, move on to CSS. (Cascading Style Sheets)
This is a neat way to manipulate your HTML, by placing your content in layers and positioning them as necessary.

Lastly, you might want to take web development a little further. From here, you could go into JavaScript, or maybe even C# or VB with some ASP.NET thrown in.

Web Development Tutorials: W3Schools

And that's it~ Thanks for reading!
I think this is my longest ever article in my blog, but more will follow. I hope that this entry has been enough for you to get started with your life of code, or maybe even just realise which language is best for you.

If you have any questions, please feel free to comment this entry, and I'd be happy to answer them.

 
0 user(s) viewing
0 guest(s)
0 member(s)
0 anonymous member(s)

gabehabe's off-topic ramblings
Follow me on Twitter!
lol, my other blog died a horrible lonely death. Ah well.

Smiley of the [however often I change it]
IPB Image

Contact Me
e-mail: gabehabe@gmail.com

Google Talk: gabehabe@gmail.com
MSN: gabehabe@hotmail.com
Yahoo: gabehabe (rarely used)
AIM: gabehabe (rarely used)

Skype: gabehabe

Want me to work for you? [click]

My Blog Links