Monday, October 25, 2010

Project 2 - The internet

Based on the article: The Web Is Dead: Long Live The Internet

I don't really agree with the premise of this article, the web is still well and alive, not even mortally injured or sick in my opinion and I can see the web staying alive as time goes on.

As to what's written in the article itself... it's rather silly, in my opinion, to try to point the blame at either "us" or "them" (meaning consumers or corporations). For several reasons, first off: it's like writing a eulogy for someone who's alive and blaming someone for their death. Second, the consumer/corporation relationship is too complex to simply say either one is solely responsible for any change. If people didn't want it, corporations wouldn't make it, and if corporations didn't think they could get people to want it they wouldn't make it. Often times, consumers give some sort of feedback on some product that corporations try to take advantage of and sell (i.e. hey this is nice, but it would be cool if...).

The distinction being drawn in the article is that of: people use the internet, but are moving away from browsers. The blaming difference is why this is going on. The writer giving the opinion of we are to blame, Chris Anderson, primarily argues that the reason for the web "dying" is that smaller app-based things fit into our daily lives better. The writer giving the opinion of we are to blame, Michael Wolff, primarily argues that the reason for the paradigm shift towards apps over the web as we know (knew perhaps) it, is about making money. Of course, because of how capitalism works companies would do their best to make money, but they alone can not kill the web. In particular, there are many aspects of the web that have nothing to do with profit at all, such as the many sites devoted to Linux. Linux is a term used to describe many pieces of freeware (Ubuntu etc.) that are worked on by just anyone who has a mind to. The graph showing a supposed decline in the web over time has a significant issue in it. Whilst it may be true that a smaller amount of internet traffic is used on websites, it should be remembered that the number of people on the internet back in 1990 (when the graph starts) is significantly lower than that in 2010 (when the graph ends), ergo, it is not really representative in how much the web is used except as a comparison to other mediums and it would not surprise me in the least if the amount of web traffic taken by itself shows an increase over most of that time period, instead of the sharp decline that particular graph shows.

Though both articles bring up valid points and ideas about what is going on with the internet market so to speak, it is silly to consider the web dead, by any stretch of the imagination.

Project 12 Program Termination and Return Codes

For the project 12 subjects I will be comparing Java, C++ and Python. All being object oriented languages they share many things in common, but differ on several points as well.

All three of these languages provide exception statements (as discussed earlier). If the program runs into an error that is not handled by an exception, it will terminate. It is good to review code to make sure you have all possible exceptions handled. This way you prevent abnormal termination, although with larger programs it is difficult to place in an exception for every potential error the program may encounter during normal running.

Java provides a line to terminate the code, System.exit(int). The integer doesn't mean anything except for usage in debugging purposes. Typically, and it is considered good convention, a return of zero in there means you reached the end you hoped for, and a return of some other integer will let you know which exit it actually ended up getting to, one or two for instance (though in theory you could use any number, whichever number you as the programmer feel best represents what you want to convey via the exit).

In C++, it is possible to end a program or function prior to its normal termination by using an extra return 0; statement. This will end the entire program or function at that point, which may not always be what you had in mind so it should be used carefully. You can also use the exit(value) function, similar to Java's System.exit() command, this returns a value to the IDE that can than be used for error trapping.

Python is also has a similar ending command, sys.exit(value). Again used for the same thing as the C++ exit() function and Java System.exit() function. There are also a few other commands which you can use, such as raise SystemExit or just exit() though there are a few different things that they do and generally sys.exit is the preferred method to quit out of a program, since it is more "friendly" to other code. Good usage of this command will help during debugging if the program quits at certain times it normally shouldn't and returns a specific number, telling you why it quit.

The return command is also virtually identical through the three languages. Typically, it is used to end a function and return a particular value, be it a string, integer, double or anything else. It can also be used in C++ and Java by adding what is known as an "extra" return 0 command, which basically causes the same thing to happen as the standard exit commands for those languages. The break command, common to all three languages, can be used to quit out of a loop early instead of a return command, and is useful if the loop ends up going somewhere you didn't intend for it to go originally. It will not stop the external loop if you are using a nested loop, just the loop in which it has been places.

Saturday, October 23, 2010

Project 12 Program Errors

For the project 12 subjects I will be comparing Java, C++ and Python. All being object oriented languages they share many things in common, but differ on several points as well.

All three languages provide for try catch statements. The purpose of these statements is to isolate segments of code that may, while the program is running, cause some severe error that would otherwise disrupt the execution of the program, such as a division by 0. By using the exception statements the programmer can prevent sections of code that may cause an issue from terminating the program. Though the exact syntax for exception throwing in the different languages is different and there each language offers a few different options with try catch type statements the basic concept is the same between all three. Reserved words in the languages may only be used for a single purpose, whatever it happens to have been made to do and can not be used as variable or any other identifier names. Common reserved words are things such as: if, while, else, and, except, break and so on. Attempting to use any of these as identifiers will cause errors in compilation.

Java syntax is derived from C and C++, however unlike C++ it is almost exclusively object-oriented. There are no global functions or variables, all code belongs to classes and all values are objects, with the exception of primitive types. Java is case sensitive with everything so a call to System and another call to system will not point to the same place, and will cause an error during compilation. Often times in Java the compiler will not point to where the actual issue is, and you will need to look around to figure out what in the world it wants. Also: fixing one simple issue such as a missing semicolon may cause dozens of other errors to pop up because the compiler hasn't checked those parts because of that first error.

In both Java and C++ lines of code do not necessarily need to be separated, the computer will still be able to read them fine. Example: 


int main ()
{
  cout << " Hello World!";
  return 0;
}


int main () { cout << "Hello World!"; return 0; }
 
Both of these code segments will run properly. However, in Python lines and indentation are rigidly enforced because Python does not end lines with semicolons, as C++ and Java do, so there is nothing directly in the code that allows the computer to know the end of a line other than the return usage at the end.

if True:
    print "True"
else:
  print "False"

if True:
    print "Answer"
    print "True"
else:
    print "Answer"
  print "False"

The first example would run fine, however the second would not because the second line under else: is not indented properly.

Friday, October 22, 2010

Project 12 Program Test Data

For the project 12 subjects I will be comparing Java, C++ and Python. All being object oriented languages they share many things in common, but differ on several points as well.

Java primarily makes use of primitive and reference data types. Declaration follows the same general format for all of them: <data type> variableName;. You fill in <data type> with any given one of the types, int for integer, char for character, boolean for booleans, String for strings and so on. It also allows for printing of the min and max values of types in the form of: System.out.println(<Type>.(MIN/MAX)_VALUE);. Java makes use of several statements controls to decide what portion of code to execute, such as: if and ifelse statements, try catch statements, and switch statements. if and ifelse statements check the if statements in sequence, if elses are tied to an if statement, and as soon as one of their expressions is found true that code segment is run and the others are skipped over. Try catch statements do a portion of code, as as it goes through it checks for (or catches) some exception that may pop up in that code. Switch statements can be used in place of if statements, and check multiple possibilities with just one call of switch, and than subsequent calls of case for each possibility.

C++ uses more or less the same listing of variable types that Java has, (not surprising as Java was influences by C++, amongst others). C++ also uses the same general format for declaration of variables. C++ also makes use of the if, ifelse and else statements, as well as switch statements, to control the flow of the program. Unlike Java and Python, C++ allows for the usage of goto statements to jump to another spot in the code, though the usage of goto is typically shunned in C++, as well as other high level languages. C++ allows you to check the size of a variable with the sizeof(<variable>) command.

Python differs from Java and C++ in its variable declarations. In Python, you do not need to specify what type of variable it is you're putting in, you just assign it a value and it knows what type of variable you want based off of that (100 would be an int, 1000.0 would be floating point, etc.). Python also contains methods for its list and tuple types which allow the programmer to get out the min and max. This is called simply with min(list) and max(list), the same with tuples only you would put in the name of the tuple instead of the list. Python makes use of if, elif (else if) and else statements to decide which segment of code to run and makes use of many fairly standard operators for true/false checking such as ==, !=, >, and <.

Tuesday, October 19, 2010

Project 11 - Problems Solving Techniques (part 7)

 Translating PDL, specifically for the purposes of this part of project 11, into QBASIC.

PDL or Program Design Language is as high-level a language as you can get, without turning speech directly into computer code. When you code in PDL you code in plain English, and use absolutely no computer code, the idea is to make it as ambiguous as possible so you can easily translate it into any other language. There should be absolutely nothing in the PDL code that would indicate a specific language (for instance, ending each line with a Semi-colon would be indicative of Java or C++ amongst others, but not languages such as QBASIC). For instance, saying Lock the surface to prevent access by other programs (when talking about the drawing surface) could easily be attributed to Directx and Lock(), so it would be better to say Prevent the surface from being accessed by other programs.

Making out your code in PDL first, before putting it in another language gives you several advantages. First off, it's easy for project managers and lead programmers to review and look over to make sure you're on the right track and have the right specifications that the program needs, and this way they won't need to sift through endless lines of code to figure out what's going on with your routines and methods. Having done it first in PDL also means you've already written out the comments for your program, and you can just put them on the particular lines of code that they expressed originally.

QBASIC is a very high-level language, and translates from PDL quite well. Becuase QBASIC uses commands such as: PRINT END INPUT RANDOMIZE it is easy to take a similar PDL form and translate it. For example: in PDL you could say: Output the answer. In QBASIC this would come out to: PRINT "The answer is:", answer$.

Similarities in other parts of life would be like British English into American English (or vice versa). For instance, the British refer to football as meaning Association football, known as soccer to Americans, and Americans would refer to Association Football only as soccer, and than Football is the American football. Another small difference would be the term "to table" something during a meeting. To Americans, this would mean to remove it from discussion and bring it up next time. To British, this would mean to bring it into discussion. Translating a book between the two would also be a fairly easy task, as most of the language is the same, however a few changes would need to be made like if the word naff (unstylish, usually used to mean "not very good") the translator would want to change that so an American reader would not be completely confused coming across that word. The same goes with Australian English, as it is also derived from British English, however has it's own divergences.

Those would all be good examples going from PDL to QBASIC, but you can go farther down the levels than that, for instance taking PDL and making Java. This would be like translating English into French, they share a common base in Latin, and there are many similarities between the two, however a lot more effort of translation would be needed to make it work well, unlike translating different types of English between each other.

Project 11 - Problems Solving Techniques (part 6)

 
Using flow charts and pseudocode to plan for and prepare to program.

Flow charts (see right) are useful to show a linear progression of your program and what it will do. Making a flow chart gives you a visual representation of how your program should run, or flow. Since it is simple, it forces the designer to think in very simple terms how their program will flow. You should follow one path linearly before going back up to follow alternate activity paths.








Pseudocode is compact and informal high-level description of a computer algorithim that uses the structural conventions of a programming language, but is meant for people to read rather than machines. It typically omits things not necessary for human understanding of the algorithm, like variable declarations, system specific code and subroutines. For example:


<variable> = <expression>

IF <condition>
    DO stuff;
ELSE
    DO other stuff; 
 
Since pseudocode is similar to the code it mimics it is fairly easy 
to convert into the wanted program. It is also fairly easy to build 
and maintain, since all you need is a text editor (wordpad or notepad would do). 
 
You could use a flow chart to demonstrate a plan or sequence for just about anything. 
It is well used to demonstrate a decision making process. Like how to choose an item 
over others whilst shopping. In this instance you would start off with a desire for some 
particular product, or a need to be filled. Once you have that you would think of 
nearby stores, and decides which ones may have what it is you're looking for. Than 
go into that store, and based off of some rubric compare and contrast different products 
that may fullfill that need. If, by some chance, the store you chose originally didn't have 
what you were looking for, than you could return a few steps back and to choosing 
another store. Than, you would end it out by saying returning home once a satisfactory 
product has been chosen.
  
The idea of giving very simple vague instructions as in Pseudocode can be used to speak 
with professionals in some field you are not as familiar with, but they are, when you want 
to tell them what kind of thing you want done, thereby allowing them to fill in the specifics 
for themselves when it comes down to actually doing the work. They know the technical 
jargon involved in whatever it is they're doing specifically, all you need to know to tell 
them what you need is a general idea of what you would like them to do. This allows you 
to prevent yourself from looking like a fool trying to use technical terms you may not 
actually know or understand completely.

Project 11 - Problems Solving Techniques (part 5)

Arithmetic expressions, loops, arrays, logical expressions. These are all elementary subjects associated with beginning programming, and will stay with the programmer as long as they code. Arithmetic expressions make use of variables, constants and operators to make calculations. Variables come into play in most every equation a programmer will write and allow for almost infinite possibilities as to what equations you can write. Loops will continue running the same part of code until some condition is met, whether it's a simple counter or waiting for some input from the user to exit the loop. Care must be taken not to accidentally throw your loop into infinity, being off by just one in your count will mess everything up (called an OBO or Off By One error). Arrays are used to contain data, they can come in many dimensions. They can be used like a simple list of objects, (objects being any data type, i.e. integers, strings etc.) this kind of array is known as a one dimensional array, a grid of objects, known as a two dimensional array, and so on. Most languages can support arrays above 3 dimensions, which can be very confusing to work with. Logical expressions are true/false statements. These are primarily used for decision making, and come in to play mostly in IF statements, and loops. All of these functions need to be understood in order for higher level programs to be created. Once these concepts are understood, it is relatively simple to make a solution for a problem and translate that into using these concepts to fulfill the problem.

In doing anything you need to understand the basics. Understand at the very bottom what is required of you and move from there. Take driving a stick shift car as an example. You need to know 3 pedals, the clutch, the brake and the accelerator. You also need to know the turn signal, and the shifter. You need to know which positions on the shifter put you in what gear. You need to understand at how many RPMs you make a shift up or down. You need to know how to recover from a stall, in case that happens. You also need to know how all of these things interact with each other. So, the accelerator increases your speed and RPM, when you hit around 3 thousand RPM you let go of the accelerator and push in the clutch, move the shifter appropriately so you shift one gear up, and slowly release the clutch. This will reduce your RPMs somewhat, and allow for a greater speed. When you down shift you need to brake a down and as your RPMs drop repeat the same process, only shifting down instead of up, so after each shift your RPMs will go up instead of down. In order to properly drive a stick-shift car, you need to understand how all of this occurs so you won't stall your car or blow out your engine from pushing its RPMs up too much. Every little thing interacts with each other, and when you understand it all, to some degree, you can drive safely and with confidence.