Your Ad Here

Posts Tagged ‘c++’

Programming tips


These tips are generalized and not to any specific language that is the reason why I included code from many different languages. The techniques are almost the same though variations exist in the syntax of things.

By referring to variations, I mean the different methodologies of coding, e.g

So let the tips come.

When beginning a method, class, loop, function, condition statements (such as if, switch, etc), open and close it before starting to code.

e.g.

if(condition)

{ //place this and the closing of the curly bracket first, then code

//this reduces a lot of problems faced when writing complicated problems

/*don’t start typing here first*/

}

By this a typical error is often removed that is just because of the { , } that is often encountered by new programmers.

Code indentation

Indentation is normally done using the tab key typically 5 or 6 spaces are left.

e.g. the following is a C/C++ code.

Indentation helps when catching errors in larger programs such as databases. In a database related program where a database such as SQL, Oracle. Etc run in the backend the code is very complicated and there are lots of things we have to do. So why not indent the code so that errors can be caught easily. Not only are database programs long. Full calendar software in C exceeds 500 lines with a lot of nested loops, and conditional statements. So if the code is poorly indented, there is very little probability that the code will run properly without any abnormalities. Where as in indentation we can figure out the loop of conditional changes and make necessary changes to it to fix the problem.

Comments inclusion

One of the very crucial points, often the point where many of the new programmers have difficulty in. when we start making larger more sophisticated programs (i.e. that involve more lines of cod, we can’t figure out every time that this variable was for this purpose and this was for this purpose). This often is helpful when code has to be updated. That is miscellaneous bugs have to be removed.

Ways of commenting.

One is the single lined comment that is started with // here is a comment

Another is the multi lined comment which has syntax as follows

/*

Here is comment line 1

Here is comment line 2

Here is comment line 3

*/

Here is a sample java code with and without codes.

Include author(s) name, created on, version, and purpose of program in the beginning of your source code. Source code is the code that we wrote. This way user knows who made the code, no on can claim that he/she wrote the code without seeing the source code.

How to write it?

The following template can be used in most of the languages such as C, C++, Java, etc.

Name Variables, pointers, functions, classes properly. Do not name the variables randomly as this can create a lot of complexities in larger programs.

e.g.

we are naming both the variables for the use of date.

int d; // d will be hard to remember

int date; // but date can be easily remembered

What about the case for first name. Many things can be done;

This is not allowed in most of the languages

char first name [100];

Correctly we can name variables such as

char first_name[100];

char f_name[100];

Use of data structures

The purpose of data structures is to help us to use fewer computer resources and do a specific purpose without the hesitation of buying a new computing machine.

E.g. we have a record of cars for a whole city. We have 10 million cars in the city. We want to store them in a database, if our program is badly written it will take up hours, days or even weeks to execute. Where as if our program is written properly with the use of data structures we can minimize this to even 20 minutes. The process we are doing on the records can be sorting, searching, or any other thing. We are using the same computer for the manipulation of records in the system.

Always make an algorithm, flowchart, what is the point of getting into more trouble? Actually this is even a little time consuming when writing small programs.

Algorithms are not meant for any programming languages; instead they can be used to create the same program in different languages.

A sample Algorithm is as follows. This algorithm shows the process of registering a user.

Registering a User

This is done because when writing complex programs is not that easy, one can not just open up the compiler and start coding. When working with larger systems, we need to design it properly so that bugs are not there as well. We often use a model called ADITE model (Analysis Design Implementation Testing & Evaluation) to create full systems. The following is a flow chart




Posted on November 25th, 2008 by Mutedart  |  4 Comments »

Basic information about Java



There are many programming languages, each with different importance. Each have the power of there own. Now I will discuss one of the languages that I have studied a little which is Java. Java is a high level language. It is a very powerful language. Sun was developed by Sun Microsystems. When it was being launched it had been tested by many people who were experts in C++ and approved Java of being a programming language. The logo is a coffee cup. A little note to the c++ programmers, many of the functions of java derive from c++, but it’s more cohesive and more consistent than c++. It gives programmer full control, and reflects exactly who you program. A few of the reasons why use java

  • Simple
  • Secure
  • Portable
  • Object oriented
  • Robust
  • Multithreaded
  • Architecture neutral
  • Interpreted
  • High performance
  • Distributed
  • Dynamic
  • Very powerful

Where is java used? Lets see Web servers, Internet applications/ applets, Servlets, Relational databases, Mobile technology and personal digital assistants, Mainframe computers, Operating system that is Solaris, Orbiting telescopes, Credit card sized smart cards, Telephones, Architectural and 3d design, Etc… And these are becoming even more and more every day due to extensive research being done in Sun Microsystems. One important thing that people really don’t know is java is not at all becoming obsolete. This is rather a strange statement I heard from people but I strongly disagree with it. One more important note Java script is not a part of java, Java script has been designed and developed by some one else. The method of coding in both is different. And Java is a programming language where as Java script is not a programming language. But both can be used for internet. How? Well java allows user to make applications that can work on the internet one example of such applications is applets. Java script is like an add on for web pages.

So in a nutshell, Java is a highly professional programming language. Not made for a beginner. Gain some knowledge about programming and computers before starting java. As there exist a lot more than it looks. The home page for Java is www.java.com and www.sun.com. There are a lot of resources there to go through for beginning your step into the vast field of java.




Posted on October 10th, 2008 by Mutedart  |  3 Comments »