Friday 27 January 2012

My Free Small Programs

Folder Watch
Ever need a program that copy all the changed or created files you worked from your work space to another folder. I needed today. Because I'm now dealing with a pretty old software written in Visual Studio 2003 and .NET Framework 1.1 which i should work in a virtual machine (XP), run in Windows 7 and collect my changed files to upload a server. (Don't ask me why)

So I need to copy all changed files to windows 7 IIS environment as well as an "update folder". I collect my updated files in the "update folder" and bulk export to other company to compile and build with their codes.

It's somehow difficult to keep tracks manually. So I developped this small software using file system watcher. You may reach this small program's setup here, or you may reach the source codes here.

Feedbacks are welcome.

Friday 20 January 2012

Many to many data table connection handling

There are some other ways to create connnections but as a programmer you should allways consider the future. An ideal program should work when it's grow or forcing the borders without changing any field lengths.

So you have to plan the future for the worst scenerios. Many to many connections are the gaps that new developers fall into it.

This is the ideal way of handling this situation.

When will you need many to many connections ?
Consider there are two tables Profile and Hobbies.
There are many profiles and many hobbies. How will you keep which profile has which hobbies or finding profiles who play chess ?
In this case you'll need another table to keep connections. Which we call "Cross Reference Table"

Here is the table structure

ProfileHobbyProfileHobbyCross
IDIDID
........ProfileID
........HobbyID

You may say that there is no need to keep ID field in cross reference table. I find it useful but it's up to you.

Keeping a cross reference table expands the horizons of your program. Whatever the record numbers will be you can handle it. Also updates can be done easily.

Database Table and ID Naming

Database, Tables and Fields should have clear, understandable and functional names. I think all programmers agree on that. But I'm not sure that all are agree in same standards.

Database name can be anything unless it's not a copy of other. But it's the easiest one.

Lets think about table names. Although you are completly free in naming, you should allways think that one day, another stranger will have to continue coding your programs. Or even you will forget how you did something. Believe me, may be you would have full control in your first 4-5 programs but then you will loose your control. When it happens, "standards" are the life saver.

You may notice that there are some naming standards for variables, file names, table names, field names etc. I admit that most of them OK, but I have an objection to data table field namings in some point. Especially ID Fields. I am developing database applications nearly 20 years. In a large databases with more than 200 tables ID fields must be more specific. if you have just 10-20 tables you may understand anything with a quick look. But with 200 table it may be hard to follow tables.

This is my way of naming ID Fields. May be it's useful for you too. Actually it never let me down in 20 years.
Rule 1 : Name of the ID field in the table itself is "ID". Every single table has a field as ID. (only in few exceptions, you may not need ID field)
Rule 2 : A reference to an ID field of an other table must be named as TableNameID
Example
Assume there are two tables like Profile and Country.

ProfileCountry
IDID
CountryIDCountryName
FirstName

In this way when you look for at the profile table you see there is a link to an ID field in Country table easily and also when you will write an SQL sentence it's easy to remember the connection.
Like
SELECT * FROM Profile INNER JOIN Country ON Profile.CountryID = Country.ID

(We will mention how useful are the uppercase lowercase syntax later. )
if the connection with the tables is one to one or one to many this will be very easy to find. We'll mention many to many connections later.

I don't know why but it's not the Microsoft way. I think this is more logical than their namings .

When it comes to table names,  mostly related tables should begin with the same way. So that when you look at the database you could see them together. I will explain my way. It may enlight your vision.

First I decide which modules I need. For example if I use accounting, operation and crm modules in a program, I simply determine shortnames for them
Accounting -> acc
Operation -> opr
CRM -> crm
and also I'll need some  base modules which can be defined as prg

Now I name the tables like
accCurrency
accCurrencyRate
accAccount
accAccountHistory
oprTask
oprTaskAssignment
crmProfile
crmProfileDetail
prgParameters
In this way when you browse tables in SQL Management Studio your close related tables follow each other.
Also you can find accounting related tables easily.

I'll be happy for any comments or questions.

Tuesday 17 January 2012

Learning A New Programming Language Day 1

Hello and Welcome to my Day 1
Today I started the day by searching in google how can I install the environment and which setups do I need stuff. I found ruby installer for windows in http://rubyinstaller.org/downloads/ When I install it I found a ruby book in pdf format. This is even better to start a journey otherwise I probably now searching for a book.

I started to read the book, I skipped some story parts. (If you are experienced in 2 or more languages you can easily skip these parts) Later if I have time I may read the history, story etc.

Now I'm in Chapter One with the subtitle of (Strings, Numbers, Classes and Objects)
Like most of the programming languages there are some input and output commands. I can see that there are print and puts to print something on screen (I think I won't need them in the future but it's good to know) The first important thing is getting familiar with the syntax. If I can understand the logic and syntax then I jump thru the half way in once.

Now I will list the important parts I read in this book. I normally keep a small sized notebook and I suggest you to do so. It can fit into a pocket, no lines if possible and there should be more than 200 pages. And I write all the critical knowledge into this book with a permanent pen. Reason is simple 20 years ago I wrote my notes with other pens and in a rainy day I lost some of my writings. Since then I allways use permanent pens.

Normally I just read and take notes in the beginning, then I put those notes to their correct places. Unfortunatally not all the books follow my way of learning.

Ruby is case sensitive
Don't need to declare variables before use
Line remarks start with #
Multiline comments start with "=begin" end with "=end" and must be flushed with left margin
=begin
This is a
multiline
comment
=end

Condition Stuff
if (condition) then
do something
end
"if" condition can be in one line

global variables start with $

Class Declaration
Class name should begin with uppercase letter
class ClassName
  def subName(SubParameter)
    @MyName = SubParameter
  end

  def getName
      return @MyName
   end
end

variables starts with @ means instance variable which belongs to a class instance
variables starts with @@ means class variable which belongs to a class itself

mydog = Dog.new
mydog.subName('Fido')

When a class contains a method named initialize this will be automatically called when an object is created using the new method.

Ruby automatically de-stroys objects and reclaims the memory they used when they are no longer referenced in your program.

Inspecting Objects
ObjectName.inspect and p(ObjectName) are the ways to inspect objects - (I will look them later I think they are for debugging related)

Parent - Child / Super - Sub Classes
class Treasure < Thing means Treasure is a sub class of Thing

In a child class there is a keyword like "super" which pass child parameters to parent. and can be used standalone to pass all the parameters or with specific parameters

SET’ Accessor
When you write a set accessor in this way, you must append the = character to the method name, not merely place it somewhere between the method name and the arguments.
So this is correct: def name=( aName ) But this is an error: def name = ( aName )

Strings
Format Strings
%d – decimal number
%f – floating point number
%o – octal number
%p – inspect object
%s – string
%x – hexadecimal number

Now I need to do some work in .NET. See you in next session.

Monday 16 January 2012

Destiny of a Developer, Writing codes on other developers' softwares

In the first years as a developer I only developped my own programs. But then I changed jobs and I faced a new challange. Writing codes on other developers' softwares. If the previous developer implemets standards and had enough knowledge it was ok. Sometimes I worked with previous developer which was OK too. But the problem arised when previous developer was not around, or he was a newbie, or he hadn't got any idea of standards.  It's a kind of nightmare for a developer to put a brick on a terrible wall.

There are two ways you may follow in this sittuation.
1 - You can throw away the existing codes and build up a new perfect software
2 - You can look the sittuation as a money earning kind of thing and do your best on existing codes.

If you choose the first way, I may say you are brave. But according to my experiences it cannot be the best way. There are many other parameters should be taken into consideration to decide which one you should choose.

The most important parameter here is your employer. If the employer is not good at with computers ideal way is second. Don't even waste your time to tell the reality.
Here I got some question list showing how I decide what to do ?
  1. Does employer have enough knowledge what you talk about
  2. Is the code terrible enough to throw away
  3. How long will you planning to work in this job
  4. How long is your employer planning to use the software
  5. Is there any integrations with other softwares
  6. Is your role good enough to take this action (way 1)
  7. Do you have time for this ?
I recommend the second way. Even though if you are planning to do it in second way, start a new program but don't tell anybody until you reach the halfway.  Whenever you mention it you'll face time barriers.

What are the obstructions you'll face with a previous inadequate developers code ?
  • Wrong data structure
    • Wrong connections
      • I once faced a software written by a rookie who didn't know how to handle many to many relations, though there was a long string field to put the many relation IDs comma seperated.
      • I saw one field holding two connections at the same time like first 3 characters are one relation rest is another connection)
    • Wrong ID handling
      • I saw character based ID fields
      • Wrongly named ID fields (I couldn't find out which field related with which tables)
    • Wrong normalizations / optimisations
      • Keeping same data in 2 or more tables instead of relations. Which creates inconsistancy
  • Codes may be away from object oriented
    • Instead of writing a function or a class doing same job in different screens again and again. Like there are Insert and Update screens exactly the same but save functions written twice.
    • Because of not knowing about Enumarations there may be absurd values you may not understand unless you dig the code
    • Because of not knowing about DLL's same functions can be coded again and again in different programs.
  • Unnecessary excess codes
    • In an update screen, button_click event send data to save function and it can gather data and send to a web service, web service formats data and send to a stored procedure and repeat this cycle for insert screen. (Just put a parameter to save function to make the code simpler)
  • Performance can be ignored
    • To insert one line to database, reading all the table.
    • wrongly typed SELECT statements
      • I saw some nested SQL sentences with 3-4 levels depth.
  • Away from code formattings
    • No uppercase, lowercase formats of the code. (It makes really difficult to read)
      • Simple, You can read "SELECT ProfileID, FirstName, LastName FROM Profile WHERE Birthday BETWEEN '01/01/1970' AND '01/01/1980'  You'll see SQL commands are in uppercase and easily read it. Try it with all lowercase and you'll see it's more difficult to read.
  • Unnecessary complex architecture
    • Sometimes showing your ability is unnecessary. You may know AJAX but if you are coding an admin screen, postbacks can be simple and fast.
  • Unnecessary screens. If it's not desperetly needed, there is no mean to make 2 different screens for insert and update. Only difference is RecordID and SQL INSERT or UPDATE Command. You can handle it easily by using an IF statement. If there are 2 screens and you need to add a field, you may easily make mistake in one later. Less code, less screens are always preferable. For example I do all my different list entries in one screen by differentiating parameter. in this way I only do the screen once and I don't need to do same screens again and again. It is a real time saver. Also updates become very easy in this way

Learning A New Programming Language

This is my 19th year in IT. I've learned many programming languages, databases, platforms, operating systems, etc. I learned most of them by myself. I only take one course  16 years ago which was about SQL and r4gl (a programming language on UNIX / Informix databases).
When I begin to write programmes there was dBase and Dos. It was the good times only text based programmes, one way direct flows, simple operations. But then everything has been changed one by one.
First we switch xBase databases to SQL, then Dos to Windows, then came the Internet, then web based programming, then web + windows based programming, then .NET came and it's still coming.

I've learned these languages in order
Basic -> dBase -> Clipper -> r4gl -> Visual Objects -> Visual Fox Pro -> Visual Basic -> HTML -> ASP -> Javascript -> VB.NET -> ASP.NET -> C#.NET

After learning some of them I developped a methodology to learn languages. Now I will share my live experience while I'm learning a new language "Ruby".

Generally I begin with basic rules like variable definition, operators, function and subroutine syntax, passing parameters, conditions(if, case), loops (for next, while), startings (includes etc)

Then I go thru database connections, SQL implementations reading writing to a database etc. File operations and communications (mail, http sends and reads etc)

I'll write this new experience day by day. Because I'll not be dealing with this full time there can be gaps between blogs.

.NET Framework Problems

Problem / Symptom
Visual Studio .NET has detected that the specified Web server is not running ASP.NET version 1.1

Solution
 %windir%\Microsoft.NET\Framework\v1.1.4322\aspnet_regiis.exe -i