Programming Index Cards

August 16, 2008

Model View Controller

Filed under: design patterns — Tags: , — apcig @ 1:38 am

Model View Contoller – a … design pattern often used by applications that need the ability to maintain multiple views of the same data.1

Model

  • Encapsulates core application data and functionality Domain Logic/Business Logic.
  • Since the model must be independent, it cannot refer to either the view or controller portions of the application.

View

  • obtains data from the model and presents it to the user.

Controller

  • receives and translates input to requests on the model or the view.

Benefits of MVC

  • Substitutable user interface
    Different views and controllers can be substituted to provide alternate user interfaces for the same model.
  • User interface components
  • Multiple simultaneous views of the same model
  • Syncronized views
  • Easier user interface changes
  • Easier testing

Drawbacks of MVC

  • Increased complexity
  • Close coupling of views and controllers to model
  • Potential for excessive updates
  • Close coupling between view and controller

Summary of article by the Web Application Component Toolkit
Source

August 11, 2008

OOP Basics

Filed under: OOP — Tags: , — apcig @ 2:20 am

Polymorphism - appropriate method is called depending on the object type

Inheritance
- represents “Is A” relationship between classes.  Class A “is a” class B
- the ability to inherit properties and methods and extend the functionality of an existing class in a new one1

Composition
- represents “Has a” relationship between classes.  Class A “has a” class B

Encapsulation - used to hide information

Immutable - the data value cannot be changed

Arrays in .Net - cannot store more than 1 data type

Override - change behavior method for the derived class

Overload - having 2 or more methods with the same name in a class

Boxing - value to reference conversion -> heap

Unboxing - reference to value conversion -> stack

1Object-oriented programming with ActionScript 3.0

Where Are All the Qualified Programmers?

Filed under: career — Tags: , , — apcig @ 2:15 am

Where Are All the Qualified Programmers?

Wed 12 Dec 2007
Posted by Scott Westfall
http://blog.slickedit.com/?p=180

FTA: When Mr. Gates decries the lack of available programmers, he offers the solution that we should increase the number of H-1b visas. Indeed, if there truly is a shortage then this seems like a reasonable solution. However, this is more likely a ploy to address the true problem that these companies aren’t willing to admit: there aren’t enough programmers available at the salary they are willing to pay.

Even without relying too much on years of experience, most companies put too much emphasis on experience with a specific combination of technologies. This includes things like Oracle, Struts, .NET, XML, etc. I consider these to be extrinsic abilities. Knowledge of these things must be specifically learned and aren’t generally applicable to other areas. In contrast, intrinsic abilities are more portable and can be applied in many areas. These include problem solving, communication, and the ability to learn quickly.

If we had an opening on this team, many companies would make the mistake of requiring a couple years of experience in XML since it is so important to the project. A good programmer, who learns quickly, would be able to get up to speed on our use of XML in no more than a day.

When hiring, consider what you truly need in your candidates. Don’t fall into the trap of just listing all the technologies you use. Determine which can be learned on the job and which truly require experience.

August 6, 2008

Passing reference types by ref and by value

Filed under: programming — Tags: , , , — apcig @ 2:30 am

Original Article1

…Whenever an instance of reference type is created the pointer is returned back… Now when this pointer is passed by val, all we are doing is duplicating the pointer but it still points to the same memory on the heap and hence any manipulation done to the object in the called method will manipulate the same data to which original hashtable pointer was pointing. In case of passing by ref, the original pointer itself is passed to the called function.

Shared Sub Main()
Dim hst As Hashtable = New Hashtable(3)
hst.Add(1, 1)
‘by default.net parameters are passed by val
PassHashTableByVal(hst)
‘will print 2
Console.WriteLine("Count after passing byval: {0}", hst.Count)
PassHashTableByRef(hst)
‘will throw a null reference exception.
Console.WriteLine("Count after passing byref: {0}", hst.Count)
Console.Read()
End Sub
Shared Sub
PassHashTableByVal(ByVal h1 As Hashtable)
h1.Add(2, 2)
h1 = Nothing
End Sub
Shared Sub PassHashTableByRef(ByRef h2 As Hashtable)
h2.Add(3, 3)
h2 = Nothing
End Sub

A null reference exception in case of passing hashtable as by ref is thrown because in the PassHashTableByRef() we are setting h2 to null which actually is same as hst, whereas in case of passing it by val we are only setting the copy of the hst pointer to null.

1Difference between passing reference types by ref and by value
By Sachin Nigam November 07, 2005

Parameter passing in C#
Honorable Mention

August 5, 2008

Powershell’s popularity is rocketing skywards

Filed under: career, programming — apcig @ 2:42 am

TIOBE Programming Community Index for July 2008

July Headline: Powershell’s popularity is rocketing skywards

The TIOBE Programming Community index gives an indication of the popularity of programming languages. The index is updated once a month. The ratings are based on the number of skilled engineers world-wide, courses and third party vendors. The popular search engines Google, MSN, Yahoo!, and YouTube are used to calculate the ratings. Observe that the TIOBE index is not about the best programming language or the language in which most lines of code have been written.

The index can be used to check whether your programming skills are still up to date or to make a strategic decision about what programming language should be adopted when starting to build a new software system. The definition of the TIOBE index can be found here.

Pos.
Jul 2008
Pos.
Jul 2007
Delta in Position Progr. Language Ratings
Jul 2008
Delta
Jul 2007
Status
1 1 Java 21.345% +0.33% A
2 2 C 15.945% -0.42% A
3 3 C++ 10.693% +0.19% A
4 4 (Visual) Basic 10.447% +0.72% A
5 5 PHP 9.525% +0.87% A
6 6 Perl 5.131% -0.20% A
7 8 Python 4.973% +1.95% A
8 7 C# 4.000% +0.29% A
9 9 JavaScript 2.757% +0.24% A
10 10 Ruby 2.735% +0.64% A

August 3, 2008

Test Driven Development Using NUnit in C#

Filed under: Unit Testing, c#, programming — apcig @ 3:56 pm

Read the full article

Test Driven Development emphasizes the … need to prepare test scenarios or test cases before writing the code itself… It requires that the programmer be very clear about what tests the program should pass and what test it should fail, bringing such concerns to the forefront of the software design process… An automated job is one that’s always very, very easy to do. These automated tests are meant to be run every time there’s a code change and are referred to as unit tests.

Unit testing with NUnit is useful for testing class libraries that makeup an ASP.NET application, but is not designed to test the UI portions of an ASP.NET application. There is, however, an additional free tool, NUnitAsp, that is designed to provide unit testing for the GUI portion of a Web application.

August 1, 2008

Why Use SQL Over procedural?

Filed under: SQL, database, programming — apcig @ 3:01 am

http://www.paragoncorporation.com/ArticleDetail.aspx?ArticleID=27

Why Use SQL Over procedural?

Structured Query Language (SQL) is a set-based language as opposed to a procedural language. It is the defacto language of relational databases.

The difference between a set-based language vs. a procedural language is that in a set-based language you define what set of data you want or want to operate on and the atomic operation to apply to each element of the set. You leave it up to the Database process to decide how best to collect that data and apply your operations. In a procedural language, you basically map out step by step loop by loop how you collect and update that data.

There are two main reasons why SQL is often better to use than procedural code.

  • It is often much shorter to write – you can do an update or summary procedure in one line of code that would take you several lines of procedural.
  • For set-based problems – SQL is much faster processor-wise and IO wise too because all the underlining looping iteration is delegated to a database server process that does it in a very low level way and uses IO/processor more efficiently and knows the current state of the data – e.g. what other processes are asking for the data.

Blog at WordPress.com.