Monday, September 27, 2010

Project 5 - Interpreters and Compilers

In this project we'll be looking at interpreters and compilers for languages such as BASIC, PASCAL, C and C++. What they are, how to get one and how to use one.

Compilers take your source code, that is the code that you have written, and translate it into machine language so that the computer can understand it. It checks to make sure everything is grammatically correct first. Should it find something wrong it will spit out syntax errors and stop compiling. Should everything check out, it will create a separate file with the machine code translation and run it. Compiling large amounts of code will take some time, which is why interpreters are often used during the creation process, however, compiled code usually runs much faster than interpreted code.

So the main advantages of compilers is that they:
  • produce programs which will run very quickly.
  • can spot syntax errors whilst the program is being compiled (however this does not necessarily mean the program is error free if it completely compiles, just that there are no grammatical errors)
Interpreters take your high-level language and translates it to a low-level one. You write the program than instruct the interpreter to run it. It takes the program, one line at a time and translates each line before running it. Something worth noting is that it has no memory for translated lines, so in order to run a loop it will re-translate every line when it comes to it. Using this is a much more effecient way to check your program as you're writing it since you don't have to wait for the compilation to finish. However, it is usually much slower overall, and for this reason interpreters are primarily used to check code. Most software you buy was most likely interpreted whilst the designers were making it, however what you usually get is the compiled code. Since this is machine code opening up with a text-editor will just get you a whole bunch of meaningless gobbly-gook.

So the main advantages of interpreters is that they:
  • have no lengthy compile time, i.e. you do not have to wait between writing a program and running it. As soon as you have written the program you may run it, which is great for checking larger programs.
  • tend to be more portable, that is an interpreter will run on a greater variety of machines, because each machine can have it's own interpreter for that language.

Finding interpreters and compilers for these languages is typically a very simple process. A simple Google search will turn up many interpreters and compilers that you could choose from. Often these are largely similar with a few key or minor differences between them in how they run and what they output. For example: a Google search of "interpreter and compiler for C" on the first page gives you 6 different possibilities for a download, mostly free software. The other 4 are pages with explanations of interpreters and compilers. It is crucial that you read the page you find it on and find out what exactly that particular interpreter or compiler will do. For many languages the developers will have a website with their compiler program for the language on it, such as Sun Microsystems with their Java language or Microsoft with their C# language.

Friday, September 24, 2010

Project 7 - GUI Object oriented languages

Comparing BlueJ, GUI Alternatives and Visual Basic.

Since the comparison base is the creation of a simple game the first thing to do is lay down what is in a simple game. When I hear that term I think games like Asteroids or Pong.
So a few things are needed:
  • Movement of an object (non-player controlled) (Asteroids/Ball)
  • Movement of player controlled object (Space Ship/Paddle)
  • AI (for Pong, opposing paddle moving)
  • Numerical Counter
  • Controls (Movement/Fire)
  • Object interaction
All fairly basic things, and I will be discussing which of the various GUI OO languages would (In my opinion) best accomplish these.

First off to throw out some ones that don't look good or are stated to be for some other purpose.

The BuoyBuilder link on the GUI Alternatives site appears to have been taken over by someone else so I'm going to throw that out right off the bat. The Jaxx link also seems to have lost it's domain since the writing of the GUI Alternatives page (2006). As well as the Matisse in Netbeans link.

JFormDesigner is stated to be primarily for the creation of professional looking forms, so that one gets thrown out.

Visual Basic is "primarily used to develop Windows applications and to interface to database systems", not really what we're looking for here so going to set that aside.

There are a lot more but most of the others fall under the same reasons to be thrown out for this case as the above so I won't bore you with every one.

BlueJ I have some experience with, and I believe it would also be a viable one to use, so I'm going to go ahead and check it out as our solution.


http://upload.wikimedia.org/wikipedia/commons/5/50/BlueJ_screenshot.png
BlueJ is, at it's heart, Java with a GUI interface for dealing with classes.To the right is a picture of the interface (source) to give you an idea of what it looks like. Inside of each of those classes it has a typical text code. This makes BlueJ good for keeping in line how classes interact with or build off of each other etc. This is helpful for determining object interaction between different things inside of your game.




Some other programs/languages that aren't brought up on those pages but are definitely work mentioning are Flash and C# Microsoft Visual Studio.

Flash is a program that you've most likely seen in many places on the internet and it's designed for both making videos and games. There are a lot of sites with games made entirely from flash on them, and it's a good place for beginning programmers to start making some basic games.

If you've been around on the XBOX Live Arcade at all, than it's likely you've run into games made with Microsoft's Microsoft Visual Studio which uses C#. This is a good place to go to after you feel you have a firm grasp of game programming concepts with Flash. It's got more power to it, and it's much more complex, however it's much better suited for creation of more professional level games.

So which is best? You're likely to do best getting your foot in the door with flash, and getting your game published on some popular flash game sites (armorgames.com kongregate.com and addictiongames.com for a few examples). If you want to publish on XBLA or make a standalone game for PC it's worth your time to learn C# and use Microsoft Visual Studio (though I'm fairly certain you'll need to use another language if you wish to publish on Mac OS X, however I imagine the code for that would be similar). As for BlueJ... well I wouldn't personally use it for game creation, however it is good for other purposes.

Tuesday, September 21, 2010

Project 6 - Object oriented languages

JAVA, C++, Python, Object-C, Delphi, and Ruby

JAVA's Key Characteristics:
  • Platform Independent - programs written in Java can be run on any machine with JVM (Java Virtual Machine)
  • Simple - does not use pointers explicitly, harder to write a program in Java that crash the system, strong memory management and automatic memory allocation and deallocation
  • Robust - exception handling and type checking mechanisms, compiler checks the program whether there any error and interpreter checks any run time error and makes the system secure from crash.
  • Multithreaded
  • Interpreted
  • Architecture neutral
  • Fewer low-level facilities and simpler object model than C/C++
(source : Wikipedia)

C++'s Key Characteristics:
  • Statically typed
  • Free-form
  • Multi-paradigm
  • Compiled
  • General-purpose
  • Comprised of both high-level and low-level language features
  • Designed to support multiple programming styles (Procedural, data abstraction, OOP, generic)
(source: Wikipedia)

Python's Key Characteristics:

  • very clear, readable syntax
  • strong introspection capabilities
  • intuitive object orientation
  • natural expression of procedural code
  • full modularity, supporting hierarchical packages
  • exception-based error handling
  • very high level dynamic data types
  • extensive standard libraries and third party modules for virtually every task
  • extensions and modules easily written in C, C++ (or Java for Jython, or .NET languages for IronPython)
  • embeddable within applications as a scripting interface
(source: Python main page)

Object-C's Key Characteristics:
  • Reflective
  • Adds Smalltalk-style messaging to C
  • Used primarily on Mac OS X and iOS
  • Programming paradigms: OO, dynamic typing and reflection
  • Supports reflective features
Delphi's Key Characteristics:
  • Rapid Application Development tool for Windows
  • Easy to create forms based applications for Windows
  • Easy to pick up
  • Hundreds of thousands of third-party components
  • No runtime is needed (unlike other RAD tools)
  • The core of Delphi is its Object Pascal compiler
(Source: Delphi wiki)
    Ruby's Key Characteristics:
    • Dynamic and duck typing
    • Reflective
    • General-purpose
    • combines syntax of Perl and Smalltalk
    • Supports functional, oo, imperative and reflective programming paradigms
    • Interpreted
    • Succinct and flexible syntax
    • Exception handling
    • Implemented on all major systems
    (source: Wikipedia)

    Many of these languages share core elements in common, for instance Ruby, Python and Java all use exception based error handling. Ruby, Object-C, and C++ were all designed with the usage of multiple paradigms in mind. Ruby, Java, Python, and C++ were all built with multiple platform OSes in mind, however, Delphi was purpose built for Windows and Object-C was purpose built for Mac OS X.

    Saturday, September 18, 2010

    Project 4 - Advantages and disadvantages of programming languages

    This is about 4 major types of programming languages and their primary advantages and disadvantages. References will be posted after the section in which they have been used.

    The first language type is Object-Oriented Programming. OOP languages are languages that revolve around the concept of an object in their code.

    Adavantages include:
    1. OOP provides a clear modular structure for programs which makes it good for defining abstract data types where implementation details are hidden and the unit has a clearly defined interface.
    2. OOP makes it easy to maintain and modify existing code as new objects can be created with small differences to existing ones.
    3. OOP provides a good framework for code libraries where supplied software components can be easily adapted and modified by the programmer. This is particularly useful for developing graphical user interfaces.
    Disadvantages include:
    1. The biggest drawback of OOP in terms of general simulation programming is probably that the real world refuses to divide up into neat classes and subclasses.
    2. The problem in IF programming is that sometimes several objects will interact in complex ways - maybe even ways we didn't necessarily anticipate when writing the program.
    3. Decreased system / software performance. With many OOPLs (such as Java) being interpreted, rather than compiled into native machine code, run-time speeds are impaired. Problems with dynamic memory allocation (the method used to create objects), means that either more memory is used-up on garbage, or that the system run-time speed is compromised by the need for garbage collection.
      http://www.bookrags.com/research/object-oriented-languages-csci-02/
      http://www2.tcl.tk/13398 http://www.tads.org/t3doc/doc/techman/t3oop.htm
      http://www.cs.bham.ac.uk/internal/courses/intro-se/unit-3-4-ood-conclusion.pdf

      The second language type is Procedural. Procedural languages revolve around keeping code as concise as possible, and focuses on a very specific end result.

      Advantages include:
      1. It is written in a step-by-step function, smaller programs written this way are very easy to follow.
      2. Easy to maintain, as each procedure/function can be debugged in isolation from the rest, allowing for easy isolation of problems, in contrast to OOP which can often take very long to find the problem code.
      3. Since it is written for a very specific purpose the code often gets you extremely efficient and high-performance applications.
      Disadvantages include:
      1. Procedural coding tends to get very difficult to maintain the larger the code gets. When the lines of code needed start ending up in the thousands it is very difficult for a team of people, or even one person to maintain.
      2. Unlike in OOP, portions of the code are so interdependent that the code in one application will not be useable in another, meaning despite being somewhat similar the code for one program will not able to be carried to a new one, which OOP can do.
      3. Procedural code is difficult to relate with real world objects.
      http://www.associatedcontent.com/article/84318/procedural_programming_pros_and_cons_pg2.html?cat=15
      http://www.wisegeek.com/what-is-procedural-programming.htm
      http://www.webdotdev.com/nvd/content/view/110/
      http://chipkidz.wordpress.com/2009/08/07/procedural-programming/

      The third language type is Functional. Functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids state and mutable data.

      Advantages include:
      1. Easier to reason about subprograms. A subprogram's function is completely described by what goes in and what comes out. 
      2. Most functional languages provide a nice, protected environment.
      3. FP encourages quick prototyping.
      Disadvantages include:
      1. Generally more difficult to pick up for new coders.
      2. Functional idioms often do lots of inversion-of-control or laziness, which often has a negative impact on debugging
      3. It doesn't match the hardware as well as most imperative languages.
       http://www.c2.com/cgi/wiki?AdvantagesOfFunctionalProgramming
      http://stackoverflow.com/questions/1786969/pitfalls-disadvantages-of-functional-programming

      The fourth and last type of coding is Logical. Logical programming is the use of mathematical logic for computer programming.


      Advantages include:
      1. It is well suited for to expressing complex ideas because the drudgery of memory management, stack pointers, etc., is left to the computational engine.
      2. Allows for data to represent both an explicit fact and as a rule which implicitly describes the fact and representing many facts compactly.
      3. Logic programming languages are particularly suited for rapidly prototyping data structures and code to express complex ideas. Reduced drudgery and compact expression means the developer can concentrate on what should be represented and how.
      Disadvantages include:
      1. Methods of making large programs with logical programming are yet to be developed.
      2. It has proven to be highly inefficient.
      3. Only effective for a few relatively small areas of applications, certain kinda of database management systems and some areas of AI.
      http://www.biocheminfo.org/moirai/cs_magenta/prolog.html
      Book: Concepts of Programming Languages by Robert W. Sebesta, Seconds edition, copyright 1993


      So for the last part, taking the information from this site and with it predicting what the most popular programming language will come to be.


      So for starters, based on this first chart it would seem Objective-C has the highest growth rate, however it is well behind Java and C so even given current rates it would take some time for it to pass Java (about 4-5 years) and possibly a little longer for C since it currently is going up. Both Java and C have about an 8% lead on 3rd place so it will take some time for either of those two to be passed up (based on this table)


      In the next diagram shown (and this is a tad hard for me as I'm slightly colorblind and many of these colors are similar enough to throw me off) but it would seem most of the languages have somewhat leveled off for the time being, with only minor changes in the past year or so. though given the recent growth spurt of Objective-C it seems the only one likely to continue growing and becoming stronger.


      The third diagram, a table showing positions 21-50 doesn't give much detail, but it seems unlikely that any of these languages will take up more popularity in the coming years.


      The next diagram seems to simply support my earlier assertion that Objective-C is the only one going through growth spurts, the others seem to be growing only slowly, going in reverse or stagnant.


      The fifth chart shows something a little different, that in 2009 Go grew the most, though it would seem as of sep 2010 Go grew much less so it may be leveled off. 

      The last 3 diagrams show based on language type. Based off of the first one it would seem OO languages are up top and there to stay, procedural languages come next and are on the decline, though still with a huge lead over functional and logical languages, both small and growing only very slowly. The next diagram in this triplet compares Statically typed languages vs. Dynamically typed languages. The graph underneath shows them over time since 2002, until now, it would seem Statically typed languages started out much higher than Dynamically typed languages, but came down quite a bit (10% about) and Dynamically typed languages grew to match, though it would seem they have leveled off a bit in recent years and Statically typed languages are there to stay well in the lead by about 30%.


      Overall I would hazard a guess and say that Objective-C is likely to take over the top spot in coming years and that Java and C are going to stay near the top for some time to come.