So far in the course we are finally merging in the knowledge of CSC165 and CSC148 to create real-life applications of our knowledge of computer science. A famous question in computer science which is likely well known by almost every computer scientists is P = NP, and learning measurement of algorithm run time is the first step in relation to learning the heart of computing.
Measurement of time algorithm is very useful and quite interesting. Often when looking for coding help, I'll see people on StackOverflow arguing over optimization of code, and this is especially important for me!I paid quite close attention to this unit as it was genuinely interesting (a bit more interesting than the previous units which was also quite interesting as I've posted before).
As a web developer, optimization is extremely important, especially when your database usually contains a huge amount of data that needs to be fetched, sorted, indexed, inserted, modified, updated, fetched randomly, etc. There is one scenario that requires me to quickly sort a list of items by their ranking, prior to which I would often use something that I now know to be called bubble sort, which of course runs in polynomial time, significantly slower than quicksort and mergesort (that I now use). Another example is I would have one large table (about 1 million rows) that were partitioned into multiple tables and needed to do a weighted random selection on them with each row occupying a "range" of a total sum. At first, my weighted selection was very slow, about 10 seconds, as I needed to calculate the sums, generate some random value and then race through all the partitioned tables to find the weighted post.
However, after learning exactly how BTREE indexing works and through that researching on Fenwick trees (which are actually optimized to run in log(n) time for this sort of criteria which includes optimization of calculating prefixed sums), I was able to apply big Oh calculations as well as measuring the runtime of multiple ways to select the random post (ended up creating a prefixed table of sums), I managed to get down selection all the way from nsqrt(n) time and eventually very close to sqrt(n) time (not quite log(n) time because there were admittedly some data structures I didn't quite understand in the fenwick tree).
This class knowledge about measuring runtime HAS helped significantly in my coding process as well as with multiple other selection and sorting methods I use on multiple other databases, and I look forward to furthering my knowledge by reinforcing my knowledge from reviewing the lectures and doing some practice questions.
CSC148 SLOG
Sunday, 5 April 2015
Saturday, 28 March 2015
Revisit previous SLOG
I will revisit my SLOG of "Learning OO programming in a day", back when I was severely struggling with multiple elements of the course (as I had never taken a single CS course in my life and my prior knowledge was some rudimentary starts in PHP and MySQL back in September which was all procedural and did not use anything special)
Looking at this SLOG makes me realize how much my knowledge of computer science has grown. I remember writing this blog fondly thinking that OO programming was a incredibly powerful concept. Of course, it still is a very important paradigm of programming and is indeed very powerful, however after learning multiple concepts such as recursion, binary tree, and measuring the runtime complexity of algorithms, I've learnt that there are still many concepts that I have yet to learn and OO is nowhere near as "important" as I thought it was.
One of the main reasons is because of how applicable I have found the lecture material. It has been continually advancing my coding "etiquette" and constantly making connections to my current coding in PHP, AngularJS, and MySQL, especially in optimizations, and searching in the data structures of my database. Recursion is an incredibly simple yet powerful technique that can be modified so easily to drastically change its outcome (polynomial run time vs log or even constant).
Learning this course material has also had profound impacts that I never really expected out of it. For the most part, I drew a line between "coding" and "computer science" and thought it was mostly mathematics and had little to no application unless you were coding something INCREDIBLY complex that was nowhere near my ability. However, I completely disagree now, computing in general underlies a very certain fundamental "property" of the universe of a set that encompasses all the problems of the universe.
After noticing the little ways it is influencing my coding habits as well as my intellect (coding optimized functions and thinking about smarter data structures), it has also sharply increased my interest in computer science and algorithms in general. For example, in a recent hackathon, I was able to apply and learn A* and BFS algorithms to data searches (connecting multiple links to other multiple links). As well, I have become interested in hashing and its optimization towards databases:
https://www.youtube.com/watch?v=0M_kIqhwbFo&index=16&list=WL, 24:00 and onwards
Other impacts include my increased understanding in how MySQL works and being able to understand this has allowed me to flex the true strengths of MySQL support for multiple types of indexes.
Also, looking at my PHP code, I have completely changed to a MVC approach that still utilises OO programming, but in a largely different method. Understanding how OO works has helped me transition to this very quickly (something I never would've learnt without this course0. Furthermore, since PHP and most Web 3.0 sites use the MVC model to operate with Google's V8 Javascript Engine (which has full support for the very powerful AngularJS which also happens to be MVC), this knowledge has helped tremedously.
Often, the knowledge I learn in this course helps very minor things in my code, but eventually aggregate into a large change. Before the course I was convinced I could learn most coding knowledge by myself (which is why I am sadly currently enrolled in Commerce, but I WILL (if they accept me) be transferring out to comp sci, a choice this course helped solidify, when I posted this SLOG, I was still a bit unsure). However, after learning so much more than I ever could have imagined, I am glad to say I have found something I would love doing for a large portion of my life. A few other of my classmates also seem to share the same resolve:
http://mengziqiao.blogspot.ca/2015/02/i-have-learned-much-more-materials-than.html
This course has helped me in more ways than I'd ever imagined. I'm now interested in multiple computer science problems, such as the subset problem/knapsack problems, and would love to enter comp sci as my program.
Looking at this SLOG makes me realize how much my knowledge of computer science has grown. I remember writing this blog fondly thinking that OO programming was a incredibly powerful concept. Of course, it still is a very important paradigm of programming and is indeed very powerful, however after learning multiple concepts such as recursion, binary tree, and measuring the runtime complexity of algorithms, I've learnt that there are still many concepts that I have yet to learn and OO is nowhere near as "important" as I thought it was.
One of the main reasons is because of how applicable I have found the lecture material. It has been continually advancing my coding "etiquette" and constantly making connections to my current coding in PHP, AngularJS, and MySQL, especially in optimizations, and searching in the data structures of my database. Recursion is an incredibly simple yet powerful technique that can be modified so easily to drastically change its outcome (polynomial run time vs log or even constant).
Learning this course material has also had profound impacts that I never really expected out of it. For the most part, I drew a line between "coding" and "computer science" and thought it was mostly mathematics and had little to no application unless you were coding something INCREDIBLY complex that was nowhere near my ability. However, I completely disagree now, computing in general underlies a very certain fundamental "property" of the universe of a set that encompasses all the problems of the universe.
After noticing the little ways it is influencing my coding habits as well as my intellect (coding optimized functions and thinking about smarter data structures), it has also sharply increased my interest in computer science and algorithms in general. For example, in a recent hackathon, I was able to apply and learn A* and BFS algorithms to data searches (connecting multiple links to other multiple links). As well, I have become interested in hashing and its optimization towards databases:
https://www.youtube.com/watch?v=0M_kIqhwbFo&index=16&list=WL, 24:00 and onwards
Other impacts include my increased understanding in how MySQL works and being able to understand this has allowed me to flex the true strengths of MySQL support for multiple types of indexes.
Also, looking at my PHP code, I have completely changed to a MVC approach that still utilises OO programming, but in a largely different method. Understanding how OO works has helped me transition to this very quickly (something I never would've learnt without this course0. Furthermore, since PHP and most Web 3.0 sites use the MVC model to operate with Google's V8 Javascript Engine (which has full support for the very powerful AngularJS which also happens to be MVC), this knowledge has helped tremedously.
Often, the knowledge I learn in this course helps very minor things in my code, but eventually aggregate into a large change. Before the course I was convinced I could learn most coding knowledge by myself (which is why I am sadly currently enrolled in Commerce, but I WILL (if they accept me) be transferring out to comp sci, a choice this course helped solidify, when I posted this SLOG, I was still a bit unsure). However, after learning so much more than I ever could have imagined, I am glad to say I have found something I would love doing for a large portion of my life. A few other of my classmates also seem to share the same resolve:
http://mengziqiao.blogspot.ca/2015/02/i-have-learned-much-more-materials-than.html
This course has helped me in more ways than I'd ever imagined. I'm now interested in multiple computer science problems, such as the subset problem/knapsack problems, and would love to enter comp sci as my program.
Tuesday, 17 March 2015
SLOG Impression Week 8- 9
These past few weeks of CSC148 has been incredibly insightful and helpful and has multiple real-life applications beyond the classroom that I do encounter on a daily basis. These past 2 lesson we have learnt three simple and powerful data structures:
- Abstract Data Type, Tree
- Binary Search Tree
- LinkedList
Trees are a data type with a value and a set/list of children such that parent references the child, but the child does not have any data stored for its parent. These abstract data type trees are incredibly powerful for traversing, finding data, and also show the data structure that recursion operates in, such that one value depends on multiple branches of values that depend on other branches of values. A disorganized abstract tree such as:
Seems to have relatively little use, other than providing a data-integral structure for recursive operations. However, once we began learning about binary trees, a lot of things I've been doing have clicked. I work with MySQL and PHP on a daily basis and often have to worry about optimization (this includes partitioning literally millions of search rows, complicated JOINS, CASES, etc.) , and often need to deal with indexing data, BTREE, Fenwick trees, database engines, etc. I didn't really understand much, but I've always heard MySQL (which is renowned for its incredible speed) SELECT statement on BTREE indexed runs in log(n) time. It was not until we learnt about trees and BST that I made the connection from on why BTREE (Binary Tree) index runs in log(n) time almost immediately:
This is extremely fast and efficient, 10,809 rows to search through for a u_id of 5963 and it was found in less than 0.03 seconds, and there isn't a considerable increase when you increase it to 100,000 rows either (which runs in roughly 0.04 to 0.05 seconds). BTREE search is much much faster than a linear search across an array. Another interesting data structure is the Fenwick tree:
http://en.wikipedia.org/wiki/Fenwick_tree
Which is a type of BTREE indexed data tree that is used to calculate very quickly a continually and cumulative increment of a sequence (useful for calculating likes on posts and for random-weighted select statements). The last data structure was for LinkedLists which actually finds a lot of use in comments on posts and other structures on websites:
LinkedLists allows for very quick insertion and deletion (as you just slice a reference out), but have slow indexing and random-access as well as other uses arrays may be used for.
With learning these applicable data structures beyond just the exam and term tests, I am quite excited to see what we will continue to learn and the next years of computer science.
- Abstract Data Type, Tree
- Binary Search Tree
- LinkedList
Trees are a data type with a value and a set/list of children such that parent references the child, but the child does not have any data stored for its parent. These abstract data type trees are incredibly powerful for traversing, finding data, and also show the data structure that recursion operates in, such that one value depends on multiple branches of values that depend on other branches of values. A disorganized abstract tree such as:
Seems to have relatively little use, other than providing a data-integral structure for recursive operations. However, once we began learning about binary trees, a lot of things I've been doing have clicked. I work with MySQL and PHP on a daily basis and often have to worry about optimization (this includes partitioning literally millions of search rows, complicated JOINS, CASES, etc.) , and often need to deal with indexing data, BTREE, Fenwick trees, database engines, etc. I didn't really understand much, but I've always heard MySQL (which is renowned for its incredible speed) SELECT statement on BTREE indexed runs in log(n) time. It was not until we learnt about trees and BST that I made the connection from on why BTREE (Binary Tree) index runs in log(n) time almost immediately:
A BTRE, or BST, organizes data such that the left side of a node is always less than that node value and the right side is always more. While I'm not entirely sure how MySQL organizes its BTREE index, it makes sense behind how it works. By organizing data like this, we can continually eliminate half of the tree as we traverse it, thus running in log(n) time on average cases, explaining partially why MySQL SELECT statement is so fast:
http://en.wikipedia.org/wiki/Fenwick_tree
Which is a type of BTREE indexed data tree that is used to calculate very quickly a continually and cumulative increment of a sequence (useful for calculating likes on posts and for random-weighted select statements). The last data structure was for LinkedLists which actually finds a lot of use in comments on posts and other structures on websites:
LinkedLists allows for very quick insertion and deletion (as you just slice a reference out), but have slow indexing and random-access as well as other uses arrays may be used for.
With learning these applicable data structures beyond just the exam and term tests, I am quite excited to see what we will continue to learn and the next years of computer science.
Tuesday, 24 February 2015
Minimax and Shannon's Number
As we've been recently learning about recursion and game strategy (evolving from the random strategy to something more intuitive), I'm a bit amazed at just how relevant and simplistic it is. The thought of being able to solve almost any problem using computation and the fact that we can use it to being to solve something like Tic Tac Toe or more complex games with our relative limited knowledge is quite surprising.
I have been interested in Chess since I was in Grade 11, and Chess is a HUGELY complex a game, that is easy to learn, difficult to master. It amazes me that any player above 2000+ ELO rating can easily see what I see (1736 ELO) in just a few seconds while seeing over 5 moves ahead. A 2600+ player can play around 10 chess games blindfolded simultaneously and can memorize more than 100,000 different positions he/she has played.
The ingenuity of ranking a position based on a numeric value is great way of breaking a problem and I'm a bit surprised at just how applicable the very essence of computing is and that it can be used to solve a wide array of problems. The computer does not care about the position it's not, just the move that will lead it to the minimized loss or maximized win. It puts shame to the idea of creativity, creativity does not exist as if there is a "creative" way of doing something (a way that may seem quite novel), the computer will find it and elect it if it is the best MOVE possible, in essence, the computer is the most creative thing there is, as contradictory as it may sound. (A machine being creative?)
Of course the way we are doing it is an exponential problem, and practically impossible to solve many games that are of higher complexity (Go and Chess). In fact, Chess is widely regarded as being unsolvable:
http://en.wikipedia.org/wiki/Shannon_number
The number of possible move states our minimax algorithm would have to look for is more than the number of atoms in the observable universe, but the fact that we can begin to "tackle" the problem and emulate what other chess engines do (Stockfish) is quite astonishing. In an interesting end-off, in an algorithm that was coded using A* search and other mechanisms played Super Mario. Although playing Pacman very strangely and taking advantages of multiple glitches in the game code, it completed it, but when it came to Tetris it struggled to complete all the possibilities quick enough to play logically. When it was a single move from losing, the computer did something unexpected. It paused the game forever. The creator of the algorithm (Tom Seven), phrased it like this "As soon as he unpauses the game, he will lose, and really the only winning move is to not play at all", and it's true, the only winning move in any of those games, is to not play at all.
I have been interested in Chess since I was in Grade 11, and Chess is a HUGELY complex a game, that is easy to learn, difficult to master. It amazes me that any player above 2000+ ELO rating can easily see what I see (1736 ELO) in just a few seconds while seeing over 5 moves ahead. A 2600+ player can play around 10 chess games blindfolded simultaneously and can memorize more than 100,000 different positions he/she has played.
The ingenuity of ranking a position based on a numeric value is great way of breaking a problem and I'm a bit surprised at just how applicable the very essence of computing is and that it can be used to solve a wide array of problems. The computer does not care about the position it's not, just the move that will lead it to the minimized loss or maximized win. It puts shame to the idea of creativity, creativity does not exist as if there is a "creative" way of doing something (a way that may seem quite novel), the computer will find it and elect it if it is the best MOVE possible, in essence, the computer is the most creative thing there is, as contradictory as it may sound. (A machine being creative?)
Of course the way we are doing it is an exponential problem, and practically impossible to solve many games that are of higher complexity (Go and Chess). In fact, Chess is widely regarded as being unsolvable:
http://en.wikipedia.org/wiki/Shannon_number
The number of possible move states our minimax algorithm would have to look for is more than the number of atoms in the observable universe, but the fact that we can begin to "tackle" the problem and emulate what other chess engines do (Stockfish) is quite astonishing. In an interesting end-off, in an algorithm that was coded using A* search and other mechanisms played Super Mario. Although playing Pacman very strangely and taking advantages of multiple glitches in the game code, it completed it, but when it came to Tetris it struggled to complete all the possibilities quick enough to play logically. When it was a single move from losing, the computer did something unexpected. It paused the game forever. The creator of the algorithm (Tom Seven), phrased it like this "As soon as he unpauses the game, he will lose, and really the only winning move is to not play at all", and it's true, the only winning move in any of those games, is to not play at all.
Thursday, 12 February 2015
Learning OO programming in a day
Since I come from a background of AngularJS and PHP web development, I have almost no experience designing object-oriented program, skipped CSC108, and haven't taken a single comp sci course in my life. Although PHP does have a an Object-Oriented side to it, I've never used it much before learning Python's OO. I had a few books on Python and decided to read a few to get a solid understanding of OO as I pretty much had no idea what was happening in class.
I learnt that OO in Python is very similar to OO in PHP and an "emulation" of AngularJS. First, Python supports multi-inheritance while PHP does not. AngularJS does not really use the concept of "objects" much and uses the MVC model. I quickly caught the concept of OO in Python after reviewing and learnt that Python calls a "parent" object to create a new object. This parent object contains callable methods such as init and new, but can re-defined by Python:
Python:
class X:
def __init__(self, x):
self.x = x
self.y = x + 1
PHP:
class X {
public function __construct(x) {
$this->x = x;
$this->y = x + 1;
}
}
As you can see, PHP uses the term this instead of self. Also, PHP does not need to pass self into the parameter while Python separates these two processes in that you must include self inside the parameters of the function. Furthermore, PHP immediately declares a function as public, private, or protected, while Python uses @property to emulate this. By learning Python OO, I was able to apply it immediately into PHP and boost my knowledge it. It also helped reinforce the concept of MVC in AngularJS, the same code in AngularJS:
var myMod = angular.module('myMod', []).
config(function($provide) { //$provide is an injectable parameter in the config attribute
$provide.provider('exampleProvide', function() {
this.$get = function(x) {
return x + 1
};
});
});
myMod.controller('x', ['$scope', 'exampleProvide', function($scope, exampleProvide) {
//Dependency injection from $scope and the provider function that will be used to reference a service from the creation of the module
//Set up initial scopes from the ng-init module
$scope.xInit = function(x) {
$scope.x = x;
}
$scope.y = exampleProvide($scope.x);
}]);
AngularJS uses dependency injection to allow functions into a controller or module. The controller can be viewed as a function in Python. The ng-init module defines a directive (a function that sends code) to receive a parameter and define it as x, ($scope is a service that manipulates the "Pyhton shell" (HTML) of the code)
I'm glad I was able to learn OO and apply to lots of my code in PHP and AngularJS. It especially helps as I'm currently Node.js and MonogoDB and most of them deal with objects encoded into JSON.
I learnt that OO in Python is very similar to OO in PHP and an "emulation" of AngularJS. First, Python supports multi-inheritance while PHP does not. AngularJS does not really use the concept of "objects" much and uses the MVC model. I quickly caught the concept of OO in Python after reviewing and learnt that Python calls a "parent" object to create a new object. This parent object contains callable methods such as init and new, but can re-defined by Python:
Python:
class X:
def __init__(self, x):
self.x = x
self.y = x + 1
PHP:
class X {
public function __construct(x) {
$this->x = x;
$this->y = x + 1;
}
}
As you can see, PHP uses the term this instead of self. Also, PHP does not need to pass self into the parameter while Python separates these two processes in that you must include self inside the parameters of the function. Furthermore, PHP immediately declares a function as public, private, or protected, while Python uses @property to emulate this. By learning Python OO, I was able to apply it immediately into PHP and boost my knowledge it. It also helped reinforce the concept of MVC in AngularJS, the same code in AngularJS:
var myMod = angular.module('myMod', []).
config(function($provide) { //$provide is an injectable parameter in the config attribute
$provide.provider('exampleProvide', function() {
this.$get = function(x) {
return x + 1
};
});
});
myMod.controller('x', ['$scope', 'exampleProvide', function($scope, exampleProvide) {
//Dependency injection from $scope and the provider function that will be used to reference a service from the creation of the module
//Set up initial scopes from the ng-init module
$scope.xInit = function(x) {
$scope.x = x;
}
$scope.y = exampleProvide($scope.x);
}]);
AngularJS uses dependency injection to allow functions into a controller or module. The controller can be viewed as a function in Python. The ng-init module defines a directive (a function that sends code) to receive a parameter and define it as x, ($scope is a service that manipulates the "Pyhton shell" (HTML) of the code)
I'm glad I was able to learn OO and apply to lots of my code in PHP and AngularJS. It especially helps as I'm currently Node.js and MonogoDB and most of them deal with objects encoded into JSON.
Wednesday, 4 February 2015
Object Oriented Programming Overview
Object Oriented Programming is a different approach at programming where the application or code is made up of many parts (objects) and its built piece by piece to create a functional program. It uses the concept of treating parts of the code as "objects" in which these objects contain certain "attributes" and when completely put together can make up the functional program allowing for a logical and simple structure, flexibility, and readability. Object Oriented programming is more read-friendly to humans and has multiple support inside the coding language to create it.
Learning about object-oriented programming has really changed the way I code and likely the way many people code when it was first introduced. The most striking difference is the mindset "adopted" when coding in OO as compared to procedural programming. The most prominent difference is in PHP from my experience, where one learns coding it from a procedural point of view and then learns the OO approach. A example in pseudo PHP code, extends means A extends B, A is a child of B. $this is a the keyword for the python equivalent self and does not need to be passed in the function argument as PHP already does this automatically:
As you can see, with the procedural approach, we made it a bit more intuitive than normal. We created function that preform specific tasks such as eat an orange, or peel a banana. We are under the assumption that peeling an orange and a banana require two difference types of actions and thus require different code for both of the, but eating them is universal. We started by creating a value for an orange and a banana, then peeled them and got a new value for them and assigned that to them, then we ate them and assigned the new value to the orange and the banana after they had been eaten. Essentially we were creating a value, and creating a new modified value and assigning it to said previous reference and did this a bit like issuing commands to a command line and getting the wanted final result. It is logical to read from up to down and you can follow it, but it's not very intuitive or easy to read when you get to more complex code. Let's take a look at the OO approach
The OO approach does things differently. We can see that the only thing that seperates an orange and a banana (other than the real world physical difference) is the way they are peeled. Otherwise, they all share common characteristics, the eat method and the peel method. They are also both FRUITS, and this is where OO becomes to be relevant. Since both the orange and the apple need to be eaten, and since there is no difference in code between eating an orange and eating a banana, we create the super class "Fruit", a class that will not only show the similarities of an orange and a banana, but also act as a general class for ANY "fruit" we create, whether it be a grape, or a pineapple. We can't implement a peel method in fruit (although we could do something like declare that all child fruits (oranges, bananas) must have a eat method in them, this can be done through abstract classes and I have shown below what it might look like along with improvements to the OO code:
Learning about object-oriented programming has really changed the way I code and likely the way many people code when it was first introduced. The most striking difference is the mindset "adopted" when coding in OO as compared to procedural programming. The most prominent difference is in PHP from my experience, where one learns coding it from a procedural point of view and then learns the OO approach. A example in pseudo PHP code, extends means A extends B, A is a child of B. $this is a the keyword for the python equivalent self and does not need to be passed in the function argument as PHP already does this automatically:
As you can see, with the procedural approach, we made it a bit more intuitive than normal. We created function that preform specific tasks such as eat an orange, or peel a banana. We are under the assumption that peeling an orange and a banana require two difference types of actions and thus require different code for both of the, but eating them is universal. We started by creating a value for an orange and a banana, then peeled them and got a new value for them and assigned that to them, then we ate them and assigned the new value to the orange and the banana after they had been eaten. Essentially we were creating a value, and creating a new modified value and assigning it to said previous reference and did this a bit like issuing commands to a command line and getting the wanted final result. It is logical to read from up to down and you can follow it, but it's not very intuitive or easy to read when you get to more complex code. Let's take a look at the OO approach
The OO approach does things differently. We can see that the only thing that seperates an orange and a banana (other than the real world physical difference) is the way they are peeled. Otherwise, they all share common characteristics, the eat method and the peel method. They are also both FRUITS, and this is where OO becomes to be relevant. Since both the orange and the apple need to be eaten, and since there is no difference in code between eating an orange and eating a banana, we create the super class "Fruit", a class that will not only show the similarities of an orange and a banana, but also act as a general class for ANY "fruit" we create, whether it be a grape, or a pineapple. We can't implement a peel method in fruit (although we could do something like declare that all child fruits (oranges, bananas) must have a eat method in them, this can be done through abstract classes and I have shown below what it might look like along with improvements to the OO code:
Now this code shows completely what we want to achieve through OO. Before, we were doing almost the same thing as procedural, just changing the functions under this fancy "class". But now we are treating our code as objects and directly manipulating them instead of returning some value. We know that every fruit has to have some "peel" function, so we declared it as an abstract function which pretty much means, I don't know how to peel said fruit, but I know that if you are going to call yourself a fruit, you should be able to peel it, enforcing that every fruit that is a fruit (child of class Fruit), must have a function that peels it.
Now, our peel function is immediate and directly manipulates the fruit object, instead of returning a value like it used to. If we are eating the fruit it should be something like this:
$orange = 'not eaten';
$orange->eat_fruit();
print($orange);
'Eaten'; //Although this would be a JSON call
As you can see, we are treating our code as objects, directly manipulating it, taking advantage that it has many shared features of other parts of our application and combining them into one universal category to allow us to give them special attributes to them. Oranges, Apples, Grapes are all fruits and all need to be eaten the same way, but not all peeled the same way, some of them (Grapes) don't need to be peeled while some (pineapples) have a radically different way of being prepared/peeled. So the object hierarchy is something like:
Fruits -> (Oranges, Bananas, Grapes, Pineapples)
And maybe more intuitively:
Fruits -> (Oranges, Bananas, Grapes, Berries -> (Blueberries, Blackberries, Raspberries), Pineapples)
All these share common attributes (functions or methods as seen in the code) but almost all have something specific to them. A few examples could be if we introduced a variable or methods called color or calories, sugar_content, create_juice. Not many people create juice purely from bananas, but a create_juice method for oranges makes much more sense. The power in OO is creating this logical and easy to understand structure while maintaining machine logic and flexibility to control the code more. When you see the procedural code, you may or may not know what an orange can do, what it can't or what it needs to do (especially since in code, variable terms aren't nearly as simple as an orange or an apple, but in object oriented code, you know what it cant do or can do, and you also know what role it plays in the code. Like a house:
House -> (Kitchen -> (Sink, Stove, Cabinet -> (Forks, Knives), Fridge -> (Lettuce, Tomatoes)), Living_Room -> (TV -> (Screen, Remote Control), Couch, Lights -> (Methods: Turn On, Turn Off, Replace)), Garage -> (Garage Door (Methods: Open, Close))
Forum -> (Topic -> Array of Comments -> (each comment as variables and methods: comment_text, author_username, insert_reply, delete))
When correctly utilized OO is a logical and intuitive way to approach a large problem and break it down into smaller pieces and solve them to create a functional solution, something that would just be too complicated to do in procedural as the problem scales up. After all, it is a progammer's job to take a impossible large task and divide it into possible smaller tasks.
Friday, 30 January 2015
Why should geeks write?
From Wikipedia:
"The word geek is a slang term originally used to describe eccentric or non-mainstream people; in current use, the word typically connotes an expert or enthusiast or a person obsessed with a hobby or intellectual pursuit, with a general pejorative meaning of a "peculiar or otherwise dislikable person, esp[ecially] one who is perceived to be overly intellectual".[1]"
As such, geeks is a term used to describe an eccentric or non-mainstream person, in essence a non-average person, with a non-average interest, with a non-average personality, and a non-average everything. This is an inherent advantage, a non-average method and non-average thinking process is an asset to an extent in that there are options and mindsets that have not been fully considered. This reason alone should be enough for Geeks to write. There is no gain in having thoughts and assets kept to yourself unless communicated to the world. In order to express these "non-average" thoughts, skill, and possibly ideas, it is crucial for geeks to write to express themselves in a world that now demands visual and creative thinking as a competitive edge.
"The word geek is a slang term originally used to describe eccentric or non-mainstream people; in current use, the word typically connotes an expert or enthusiast or a person obsessed with a hobby or intellectual pursuit, with a general pejorative meaning of a "peculiar or otherwise dislikable person, esp[ecially] one who is perceived to be overly intellectual".[1]"
As such, geeks is a term used to describe an eccentric or non-mainstream person, in essence a non-average person, with a non-average interest, with a non-average personality, and a non-average everything. This is an inherent advantage, a non-average method and non-average thinking process is an asset to an extent in that there are options and mindsets that have not been fully considered. This reason alone should be enough for Geeks to write. There is no gain in having thoughts and assets kept to yourself unless communicated to the world. In order to express these "non-average" thoughts, skill, and possibly ideas, it is crucial for geeks to write to express themselves in a world that now demands visual and creative thinking as a competitive edge.
Subscribe to:
Posts (Atom)






