Protected: 5-10-09
Protected: New Module
Protected: 4-13 -> 4-18
Protected: Internal Office Blog – WIP no more
Protected: Something out of Crap
Internal Office Blog – still WIP
I haven’t even created one yet… Well, I was intending to start a blog about OOP in our office network, but never really got around to doing that. It’s mostly attributed to my dislike for writing. Just so I won’t forget my ideas about the blog (just in case I get around to actually creating the blog), I’ll post my ideas here for the meantime.
Here are my initial ideas for the internal blog:
- the blog title would be GOOD for GOOD Object-Oriented Principles (“GOOD” should be recursive:P)
- the about page would contain a short description of the contents that I would be putting in the blog (e.g., cohesion vs. coupling, the 5 principles of class design, OOP vs. functional programming, design patterns, etc.)
- the first post would be something like a “where to start” post where I would tell the story of how I discovered OOP and how I got hooked to OOP
- Succeeding posts would be about the 5 principles of class design (1 principle per post) and how each could improve a programmer’s code vis-a-vis the internal web framework being used in the company
Hope I can stop procrastinating and start working on the GOOD…
Skill set: mathematics = level 0
I suck at math and I intend to do something about it! That’s why I bought this book (Concrete Mathematics) that’s supposedly for computer science students. As I wanted to make the most out of summer break (from school), I started reading this book.
Chapter 1 had some really interesting concepts but sometimes some of its discussions were really really hard to follow. I especially liked the solutions to the Tower of Hanoi problem and the Lines in the plane problem. They were amazing and easy to follow. The solution to the Josephus problem, however, still eludes me:P
Anyway, wish me luck. I hope I can study as much as I can this summer break. I really want to improve the theoretical-computer-science aspect of my programmer’s skill set for which mathematics is an essential part.
(To all mathematicians out there: kudos to you!)
What do low coupling and high cohesion mean? What does the principle of encapsulation mean?
Low Coupling
Coupling refers to the relationship of a module with another module. A module is said to be highly coupled with another module if changes to it will result to changes to the other module. And a module is said to be loosely coupled if a module is independent of any other modules. This can be achieved by having a stable interface that effectively hides the implementation of another module.
Benefits of low coupling are
- maintainability – changes are confined in a single module
- testability – modules involved in unit testing can be limited to a minimum
- readability – classes that need to be analyzed are kept at a minimum
High Cohesion
Cohesion refers to the measure of how strongly-related the functions of a module are. Low cohesion refers to modules that have different unrelated responsibilities. High cohesion refers to modules that have functions that are similar in many aspects.
The benefits of high cohesion are
- Readability – (closely) related functions are contained in a single module
- Maintainability – debugging tends to be contained in a single module
- Reusability – classes that have concentrated functionalities are not polluted with useless functions
Principle of Encapsulation
Encapsulation is synonymous to information hiding. It is the process of concealing the internal representation and implementation of a class. Encapsulation shields the class from misuse and thus increases the resuability of the class. That is, it hides the implementation such that the internal structure of a class is free to change without affecting the implementation of the classes that use this particular class.
100 Interview Questions
Recently, I came across a blog post by Jurgen (in noop.nl). It’s all about the top 100 questions that Jurgen will ask a propective software developer. In order to prove myself worthy of being called a developer, I will try to answer his questions one-by-one (across different posts).
Here’s the list of his questions:
Requirements
- Can you name a number of non-functional (or quality) requirements?
- What is your advice when a customer wants high performance, high usability and high security?
- Can you name a number of different techniques for specifying requirements? What works best in which case?
- What is requirements tracing? What is backward tracing vs. forward tracing?
- Which tools do you like to use for keeping track of requirements?
- How do you treat changing requirements? Are they good or bad? Why?
- How do you search and find requirements? What are possible sources?
- How do you prioritize requirements? Do you know different techniques?
- Can you name the responsibilities of the user, the customer and the developer in the requirements process?
- What do you do with requirements that are incomplete or incomprehensible?
Functional Design
- What are metaphors used for in functional design? Can you name some successful examples?
- How can you reduce the user’s perception of waiting when some functions take a lot of time?
- Which controls would you use when a user must select multiple items from a big list, in a minimal amount of space?
- Can you name different measures to guarantee correctness of data entry?
- Can you name different techniques for prototyping an application?
- Can you name examples of how an application can anticipate user behavior?
- Can you name different ways of designing access to a large and complex list of features?
- How would you design editing twenty fields for a list of 10 items? And editing 3 fields for a list of 1000 items?
- What is the problem of using different colors when highlighting pieces of a text?
- Can you name some limitations of a web environment vs. a Windows environment?
Technical Design
- What do low coupling and high cohesion mean? What does the principle of encapsulation mean?
- How do you manage conflicts in a web application when different people are editing the same data?
- Do you know about design patterns? Which design patterns have you used, and in what situations?
- Do you know what a stateless business layer is? Where do long-running transactions fit into that picture?
- What kinds of diagrams have you used in designing parts of an architecture, or a technical design?
- Can you name the different tiers and responsibilities in an N-tier architecture?
- Can you name different measures to guarantee correctness and robustness of data in an architecture?
- Can you name any differences between object-oriented design and component-based design?
- How would you model user authorization, user profiles and permissions in a database?
- How would you model the animal kingdom (with species and their behavior) as a class system?
Construction
- How do you make sure that your code can handle different kinds of error situations?
- Can you explain what Test-Driven Development is? Can you name some principles of Extreme Programming?
- What do you care about most when reviewing somebody else’s code?
- When do you use an abstract class and when do you use an interface?
- Apart from the IDE, which other favorite tools do you use that you think are essential to you?
- How do you make sure that your code is both safe and fast?
- When do you use polymorphism and when do you use delegates?
- When would you use a class with static members and when would you use a Singleton class?
- Can you name examples of anticipating changing requirements in your code?
- Can you describe the process you use for writing a piece of code, from requirements to delivery?
Algorithms
- How do you find out if a number is a power of 2? And how do you know if it is an odd number?
- How do you find the middle item in a linked list?
- How would you change the format of all the phone numbers in 10,000 static html web pages?
- Can you name an example of a recursive solution that you created?
- Which is faster: finding an item in a hashtable or in a sorted list?
- What is the last thing you learned about algorithms from a book, magazine or web site?
- How would you write a function to reverse a string? And can you do that without a temporary string?
- What type of language do you prefer for writing complex algorithms?
- In an array with integers between 1 and 1,000,000 one value is in the array twice. How do you determine which one?
- Do you know about the Traveling Salesman Problem?
Data Structures
- How would you implement the structure of the London underground in a computer’s memory?
- How would you store the value of a color in a database, as efficiently as possible?
- What is the difference between a queue and a stack?
- What is the difference between storing data on the heap vs. on the stack?
- How would you store a vector in N dimensions in a datatable?
- What type of language do you prefer for writing complex data structures?
- What is the number 21 in binary format? And in hex?
- What is the last thing you learned about data structures from a book, magazine or web site?
- How would you store the results of a soccer/football competition (with teams and scores) in an XML document?
- Can you name some different text file formats for storing unicode characters?
Testing
- Do you know what a regression test is? How do you verify that new changes have not broken existing features?
- How can you implement unit testing when there are dependencies between a business layer and a data layer?
- Which tools are essential to you for testing the quality of your code?
- What types of problems have you encountered most often in your products after deployment?
- Do you know what code coverage is? What types of code coverage are there?
- Do you know the difference between functional testing and exploratory testing? How would you test a web site?
- What is the difference between a test suite, a test case and a test plan? How would you organize testing?
- What kind of tests would you include for a smoke test of an ecommerce web site?
- What can you do reduce the chance that a customer finds things that he doesn’t like during acceptance testing?
- Can you tell me something that you have learned about testing and quality assurance in the last year?
Maintenance
- What kind of tools are important to you for monitoring a product during maintenance?
- What is important when updating a product that is in production and is being used?
- How do you find an error in a large file with code that you cannot step through?
- How can you make sure that changes in code will not affect any other parts of the product?
- How do you create technical documentation for your products?
- What measures have you taken to make your software products more easily maintainable?
- How can you debug a system in a production environment, while it is being used?
- Do you know what load balancing is? Can you name different types of load balancing?
- Can you name reasons why maintenance of software is the biggest/most expensive part of an application’s life cycle?
- What is the difference between re-engineering and reverse engineering?
Configuration Management
- Do you know what a baseline is in configuration management? How do you freeze an important moment in a project?
- Which items do you normally place under version control?
- How can you make sure that team members know who changed what in a software project?
- Do you know the differences between tags and branches? When do you use which?
- How would you manage changes to technical documentation, like the architecture of a product?
- Which tools do you need to manage the state of all digital information in a project? Which tools do you like best?
- How do you deal with changes that a customer wants in a released product?
- Are there differences in managing versions and releases?
- What is the difference between managing changes in text files vs. managing changes in binary files?
- How would you treat simultaneous development of multiple RfC’s or increments and maintenance issues?
Project Management
- How many of the three variables scope, time and cost can be fixed by the customer?
- Who should make estimates for the effort of a project? Who is allowed to set the deadline?
- Do you prefer minimization of the number of releases or minimization of the amount of work-in-progress?
- Which kind of diagrams do you use to track progress in a project?
- What is the difference between an iteration and an increment?
- Can you explain the practice of risk management? How should risks be managed?
- Do you prefer a work breakdown structure or a rolling wave planning?
- What do you need to be able to determine if a project is on time and within budget?
- Can you name some differences between DSDM, Prince2 and Scrum?
- How do you agree on scope and time with the customer, when the customer wants too much?
Good Comment, Bad Comment
Not fairly recently, I heard a remark about comments in a developer’s code. While the remark was more of a compliment to another developer because he had put comments in his code, it still struck me how we put comments in high regard. Don’t get me wrong, I am not against code comments per se… What I am against is the indiscriminate use of these comments.
Some purists argue that we can do away with all comments. If we write our code clearly enough, then there’s really no need for comments. After all, isn’t it taught by Martin Fowler (although I’m not saying that he is a purist) in his book on refactoring that a comment can probably be replaced by a well-named method? The following snippet of code appeared in his book:
printBanner();
//print details
System.out.println(“name:” + _name);
System.out.println(“amount:” + amount);
}
And he had (excellently) refactored it to the following:
printBanner();
printDetails(amount);
}
void printDetails(double amount) {
System.out.println(“name:” + _name);
System.out.println(“amout:” + amount);}
With the extraction of a piece of code into a method, the code has become clearer.
So when should we use comments then? In Mike Gunderloy’s In Praise of the Lowly Comment article, he identified 4 types of comments that can serve as our guideline. These 4 types of comments are:
- Placeholder comments
- Summary comments
- Intent comments
- Rocket Science comments
Placeholder comments
Placeholder comments are comments that help remind you of some tasks that need to be done some time in the future. The TODO comment is an example of this type of comment.
Summary comments
Summary comments are comments that help explain what a chunk of code does. This type of comment helps explain a block of code at a glance. This prevents the need to read every line of code in the program.
Intent comments
Intent comments are comments that help explain why a class or method is there. For example, you might want to explain why you needed to extend from the DownloadClass instead of the ProjectClass.
Rocket Science comments
Rocket Science comments are like tutorials that help explain the intricacies of a very complex algorithm. References to the algorithms used may also be included in this type of comment.
The lesson here? To improve code clarity, use comments judiciously.