Friday, May 16, 2014

I Code Java : A Blog on Java Generics and Methods






This blog is inspired by the book “Effective Java” by Joshua Bloch. It is quintessential step to write good methods since these methods are exposed as APIs to other set of classes and packages.

Why should we all use Java methods?

  • For reusable code
  • For top down programming
  • To create conceptual units


Guidelines for writing a good Java method?

  • Whenever a method is exposed to an outside entity, we cannot make assumptions for the type of arguments which would be sent when the method is invoked.
  • Firstly if there is an operation performed over the arguments, we must assert for null ability. 
  • There are many ways in which we could make it null safe. We could use documentation, annotations or explicit null checks in the method. 
  • Documentation using JavaDocs is necessary but not sufficient. 
  • Annotations helps to preserve the sanity of the method but still results in runtime validation exceptions. 
  • Explicit null checks when done properly help in avoiding any runtime errors. Using all the above 3 ways in conjunction with each other is a good practice.

Ex:


/** Checks the equality of the given input arguments. 

* @args obj1      Object  1st argument
* @args obj2      Object  2nd argument
* @returns Boolean True if both are equals, False if not equal

**/
Boolean isEqual(Object obj1, Object obj2) {

                if (obj1 == null && obj2 == null)
                                return true;
                if (obj1 == null || obj2 == null)
                                return false;
                if (obj1.getClass() != obj2.getClass())
                                return false;
                return obj1.equals(obj2);
}


Specify the type of parameters as precise as possible. If the type of the argument can be subclasses, the method needs to ensure type safety.

Guidelines for using Java Generics

Generics is been a boon to java developers since its introduction in Java 1.6. Generics brings in a lot of freedom and abstraction to the developer. Consider the example below.


Abstract Class Shape {
}
Class Polygon extends Shape {
                int sides;
}
Class Pentagon extends Polygon {
                public Polygon (int sides) {
                                this.sides = sides;
                }
}
Class Circle extends Shape {
                int radius;
}
// Incorrect Way
Boolean getNumberOfEdges( <? extends Shape> foo){
                // business Logic
}
// Correct way
Boolean getNumberOfEdges( <? Extends Polygon> foo){
                // business logic
}
In the above example, we have restricted the type of object to anything of type Polygon as we expect instances of Polygon only to have edges. Whereas this is not guaranteed for all classes which extend the parent class Shape.

To end on a funny note!


















References:
[1] : http://uet.vnu.edu.vn/~chauttm/e-books/java/Effective.Java.2nd.Edition.May.2008.3000th.Release.pdf
[2] : http://java.dzone.com/articles/5-things-you-should-know-about-java-generics
[3] : http://www.tutorialspoint.com/java/java_methods.htm
[4] : http://www.leepoint.net/JavaBasics/methods/method-commentary/methcom-purpose.html

How to GIMP!



GIMP is the GNU Image manipulation tool is basically a raster graphics editor. It can be used for tasks such as photo retouching, image composition and image authoring. As a part of designing a handbook for the 180i website, we used this too extensively to create 2D puzzles which set the theme for our project. In this blog, I would like to share the intricacies involved in achieving the same.

Why choose GIMP over Photoshop?

  • GIMP is free because it is developed as an open source project. 
  • It is as powerful as Photoshop and you can open Photoshop files in GIMP.
  • It has versatile selection and transformation tools.
  • It is compatible with most operating systems.
  • Its easy to learn as compared to Photoshop.
  • Cost of GIMP : $0, Photoshop : $699
  • Size of GIMP : 18Mb, Photoshop : 1GB + additional space during installation 

Steps involved in Converting the Original image to a Jigsaw puzzle



  • Download and install GIMP from : http://www.gimp.org
  • Decide the dimensions of the puzzle and create an image with those dimensions
  • Draw the puzzle outline with : Filters --> Render --> Pattern --> Jigsaw

  • Set the options for the puzzle outline

  • In the Jigsaw dialog box, set the horizontal and vertical number of tiles to be numbers of horizontal and vertical rows calculated in Step 1. Set Bevel Width to 0 and Highlight to 0. That will make sure that the lines separating the puzzle pieces will be as thin as possible.
  • Bevel width : It controls the slope of the edges of the puzzle pieces
  • Highlight : It  controls the strength of the highlight that will appear on the edges of each piece. It can be compared with the glossiness of the material that the puzzle is made up of. Highlight width is relative to the Bevel width. As a rule, the more pieces you add to the puzzle, the lower Bevel and highlight values should be used.  
References : 
[1] http://docs.gimp.org/en/plug-in-jigsaw.html
[2] http://www.wikihow.com/Turn-a-Photo-Into-a-Puzzle-Using-GIMP
[3] http://geekitude.com/Gimp/creatingPuzzles.html


·  



Challenges involved in Beta Testing Video Games



Many of us have come across beta testing in real life situations – it could have been for one of our favorite games or one of the applications on our operating systems that we use on a daily basis.

Beta testing can be defined as allowing the software to undergo usability testing with users who provide feedback, so that any defects found by the users can be reported to the developers and fixed.”

Where does Beta testing fit in?



A big problem with beta testing video games, is finding people that are willing to test the software. Gaining peoples feedback on a piece of software is very difficult because many just want to experience the software and not provide feedback to the developers. Popular online games such as World of Warcraft and City of Heroes performed beta tests of their games before the actual release. The main reason for this was to test their hardware servers and make sure that they could handle the amount of players that are likely play at any one time.

What makes beta testing video games challenging?

  •  A video game tester requires thinking critically about video games and game play.
  •  A game tester will play a certain level on certain difficulty setting: examples can be  equipping certain weapons to fight enemies, complete missions etc. While doing so,  the tester has to watch out for all the errors and ambiguous behaviors in the game  and write up a bug report giving details about the error and how the error was  encountered.
  • A large error, like a game crash, is very easy to spot, but a smaller error like a graphical glitch can be difficult to spot.
  • Sometimes it is difficult to reproduce  the errors since the exact test scenario can be complex.
  • Many games feature multiplayer functionality, requiring players to test together to simulate a live experience.
  • Depending on the genre and content, the target participants of a game beta may be a very young audience, which lead to different recruitment and management issues.
  • For closed platform games (iPhone, etc.), distributing pre-release builds to testers is challenging. This is primarily due to security concerns which result in a number of obstacles.
  • Many games require very large participant pools. These pools can require an enormous amount of coordination, communication, and logistical planning. Seemingly simple tasks such as distributing beta builds become increasing complex as the number of participants rises.
  • Between the younger ages of game beta testers, the large size of many game tests and the excitement to test a new game, there is a higher likelihood that testers will want to discuss their experiences in game betas. This can increase the possibility of leaks about the product.
  • Game testers end up playing the same level literally hundreds of times. This is a far cry from the rosy picture most people have of video game beta testers enjoying their tasks.
  • To prepare for testing video games, beta testers should gain experience with using different console controllers. This is a huge ask!
  • The tester has to play the video game along all possible paths and make sure all the game logic is tested. The controllers and the audio also need to be tested for each of the levels.
  • The non-functional game features like balance, difficulty and fun factors are other areas which need to be covered. 
         Beta testing video games can really be fun and a good profession for people who love to try     their hands at different kinds of games.

          References :
          [1] http://www.animationcareerreview.com/articles/breaking-video-game-industry-                   quality-assurance-otherwise-known-video-game-testing
          [2] http://www.centercode.com/beta/types/games/
          [3] http://thegameprodigy.com/the-truth-about-being-a-game-beta-tester/