PROGRAMMING
by
What programming
language should I use?
Microsoft is dominant in the market, so using
Microsoft Visual Studio 2005 is obligatory for a developer nowadays. Visual
Studio is actually a program-development-environment, which supports building
projects by using many programming languages. Among those, C++ is the most commonly used and the most powerful.
However, the computer development environment
is rich and full of other powerful programming platforms as well, some of them
equally – or even more – widespread to Microsoft Visual Studio. Sun has
developed NetBeans, a programming-development-environment which supports Java.
Since Java is an extremely popular programming language and since all Java
programs can run to almost every Internet browser without any changes in their
code, it is also obligatory to learn programming in Java language as well.
It is important to note that Microsoft Visual
Studio also supports Java, as well as many other Java-compilers (compiler are
the programs which translate the program one writes in a programming language,
into machine code which the computer processor can understand and execute – a
programming-development-environment, such as Microsoft Visual Studio, includes
a compiler, the necessary libraries [see later on this text] and a graphical
interface which helps you develop your application). Moreover, there are also
many other C++ compilers other than Microsoft Visual Studio. The differences of
different compilers existing for the same programming language are the only
thing a programmer should know in order to use them. The main features (not
all) of the programming language stay the same. However, each compiler has
specific needs and requires from the programmer to follow certain rules in order
to build and successfully compile a program. These rules are usually documented
by the compiler creator. If not, then there is a problem and the programmer has
to find out on his own what the compiler’s peculiarities are.
Finally, one cannot ignore the Unix community
or the Macintosh users. One cannon forget that there are also some other
operating systems, besides Windows and Linux. The wxWidgets programming-development-environment supports the
development of C++ programs (it also supports other languages) that can execute
on many platforms with little (if any) effort to make the code ready to launch
on another platform. The C++ code you must write in this environment is
basically of the same structure and logic with the Microsoft Visual Studio C++,
but with some differences. If you know how to program in Visual Studio C++ it
wouldn’t be any problem for you to learn how to program in wxWidgets and vice
versa.
If I learn to write
C++ programs in a certain development environment, like Microsoft Visual Studio,
will it be difficult for me to write C++ programs in another development
environment?
The answer is NO. Every C++ development
environment may have small or big differences as far as the commands’ format is
concerned, but the language structure remains the same. So all you’ll have to
do in order to port one program from one environment to the other will be to
rewrite the program’s algorithm with respect to the new format needed from that
particular environment you want to port-to. Where you will find that format
requirements? That is simple: to the environments documentation.
Useful sites about programming
Do I need to know
Assembly programming? Why Assembly does even exists since we can do anything
with C++?
You cannot do anything with C++ (especially not
with the latest C++ 2005 edition, which embeds many safety valves restraining
you from doing anything you want in the computer’s memory) and YES, YOU MUST
KNOW ASSEMBLY!
Using Microsoft Visual Studio to develop programs
just with drag-and-drop, doesn’t make you a software developer! What
distinguishes serious software applications from simple child-level useless
little programs, is the algorithm which resides behind the front cover of
buttons, toolbars and labels. I am not implying that appearance is not
important! Actually it is what the users perceive and is extremely important if
one wants to develop some serious applications. However what I am saying is
that you should first concentrate all your efforts in developing a strong
program algorithm which works correctly and delivers the results expected by
the customer and then, develop a state-of-the-art graphical user interface to
communicate that functionality to the end user.
Developing programs without knowing how the
computer works inside its case is like operating a $100,000,000 clinical
analyzer without knowing chemistry and without having any medical knowledge:
You may be able to press buttons and read from the screen, but you will never
understand fully what you are doing and, most importantly, you will never be
able to explain to the patient fully the results of his blood analysis.
Likewise in software applications development, if you do not know assembly you
will never understand how computer memory is structured, how it can be
manipulated, how to cope with high-level difficult problems, how to develop
applications that are s efficient as your customer wants to. You may develop a
good-looking program with various beautiful buttons, but when you come up with
the first serious problem it is highly probable that you will stop right there
and raise your hands up in the sky looking for enlightenment.
Read about Assembly, learn what the Stack is,
what the Memory Registers are, how to write and read from the stack and you
will have made a leap towards real and constitutional computer knowledge. Then
you will be able to develop really efficient applications which will address
your client’s needs in a straight manner.
I did a search in the
Internet and found out that there are many people still using old computers,
even developing new software and hardware for them! Why are there still people
using their old Commodore computers? Why waste time on such old machines when
today’s 3 GHz computers can do anything?
The software and computer community has relied
on the increasing computing strength of the new processors for more than it
should to. As a result software developers did not care about writing efficient
code – they just wrote programs, then added new features, then added some more
new features without checking how they interacted with the previous ones, then
added some new features again, without never trying to optimize the whole
program again, without caring about memory leaks, performance problems… After
all, why care, since the new Intel or AMD processor could handle the new bigger
(and slower) program? As a result many programs nowadays have become huge
collections of code lines with 50-70% redundant and useless (or even just
error-generating) code.
There was a time when computer owners trying to
write programs had to use small variables in order to save memory space. There
was a time when developers had to optimize their code in order to use every bit
available. Microchess developed for Commodore machines is a perfect example of
efficient programming. Getting the computer to play chess with a program just
some bytes long, when compared to chess programs today many MEGAbytes long,
seems like plain magic for people who are used to just drag-and-drop buttons to
create monster programs doing nothing.
That is why every serious software developer
should buy a Commodore 128 (or any other old machine that can be programmed in
BASIC, assembly, machine language or any other language), use it, develop
programs for it, learn how to write correct, working, efficient and simple
code!
When one understands that 3 GHz computers are
on principle 1 MHz Commodore 128 computers with enhanced GEOS (graphics based
operating system developed for C128), then he would have made a giant leap (for
him, not for mankind).
He who forgets where he came from, he is lost
and cannot go anywhere. No one should forget from where software development
started…
What about machine
code? Can someone program in machine code? If yes, how can it be done? Is
knowledge of machine code necessary for a developer nowadays?
Machine code is the language the computer
understands. It consists of 0’s and 1’s which represent the passage of electric
current through the pins of the processor (or the existence of electric charge
in a certain memory chip position).
Certain combinations of 1 and 0 constitute
instructions to the processor. The processor fetches the instruction from the
memory (RAM, ROM, Flash etc) and then
executes it (search Yahoo! for “fetch processor instruction”, “processor
control unit”, “fetch and execute processor cycle” and you will find many
useful information about how the processors work).
Someone who knows C++, NASM and machine code,
knows the three levels of computer software languages, which are:
High Level Languages → Assembly →
Machine code
Computer understands directly only machine
code.
High Level Languages (HLL) like C++ or Basic
are languages which allow the developers to use expressions in order to build
their programs. For example, in order to write “Hello” on the screen using
Basic, you must type the command <PRINT “Hello”> in a Basic development
environment. Then a program called “compiler”, will transform this command to
the corresponding machine code so that the computer can read it and execute it.
A single command in an HLL corresponds to more than one machine code
instructions. HLLs are used because it is easier for someone to write a command
in plain English than to write a huge amount of 010101110’s in machine code
instead. When people used to program in machine code they used tedious charts
for all than machine code instructions needed to be written.
Assembly is in the middle of these two edges.
Even though assembly is a language executed at a very low level in the computer
(one assembly command corresponds to only one machine code instruction and vice
versa, which means that when one programs in assembly language he must guide
the processor step-by-step through every thing he wants it to do and not just
type <PRINT “Hello”>), it uses plain expressions (near the English used
by Basic, but not the same of course) for its commands, so it is relatively
easier than machine code.
If someone wants to program in Assembly, he
gets an assembler (like NASM, or MASM), writes his .asm code in Notepad,
assembles his program with the assembler into .obj code and then uses a linker
to link all resources together and generates the executable file (.exe) which
contains the machine code.
If someone wants to program in C++, he buys a
C++ Development Kit, starts programming and the compiler takes care of
everything and converts his C++ commands into machine code instructions.
But what happens if you want to program in
machine code? The answer is simple: Find where to store the machine code and
then tell the processor to load that code and execute it. But storing the
machine code somewhere is tricky.
The machine code can be hard-coded in the ROM or
EPROM or FLASH memory of the processor by its manufacturer, i.e. Intel or AMD.
So if you want to enter and execute machine code in the processor’s flash
memory, you should be a partner of Intel or AMD (or create your own processor,
so you would know where and how to enter machine code in it!), because Intel
and AMD do not reveal the way to program their processors to anyone. Please
refer to any Pentium Data Sheet you can find in the http://www.intel.com site. Intel and AMD
release huge amount of documentation on their processors and the instructions
they can execute, but say nothing about HOW to enter such instructions in the
processors. All this information is kept confidential for OS developers and
hardware manufacturers. Of course you can always try and give power (the 1’s)
to 344 pins of a Pentium 4 processor (leaving the rest without power – the 0’s)
and wait to see if that “machine code” really means something to the processor.
Tell me if that works…but please do not hold me responsible if the processor is
then destroyed. Everything said in this article is provided with no guarantees
and every person should first think logically (about if what he is about to do
violates the law or will harm any person or hardware or equipment) before
trying to do anything written or implied here. Remember: experimenting is a
good thing as long as it is not against the law or common sense…
Another way is to store the machine code in
RAM. There are some ways one might try in order to do this.
First of all, one can use the tools given to
him by the computers operating system. Commodore computers back in 80’s, had an
embedded machine code monitor which allowed the user to write directly in
machine code. Windows do not have such a tool because allowing everyone storing
easily machine code into Windows RAM would be catastrophic: every hacker in the
world would literally party…However there are some ways: Hackers often use
buffer overrun attacks (search Yahoo! about that) in order to execute machine
code in a computer. If for example one declares a char variable in C++ with a
length of 5 and then tries to store in than variable the code 1000111010 (which
has 10 digits) then a buffer overrun would follow and the 5 digits that cannot
fit in the 5-digit variable will load themselves in a RAM location. Someone who
has the knowledge can make that code loaded in to RAM execute and harm the
computer. Knowing how this machine code works is crucial for software security.
That is one good reason for you having to learn machine code and understand how
it works! SQL injections (again, search Yahoo! to find out more) are also a way
to plant machine code into a computer’s memory. Another, more legal, way to
store a program directly in machine code is by using a binary stream writer in
C++. Just write the machine code instructions you want in binary format this
way and you will have an executable program ready in no time. BASIC also offers
ways to enter machine code. Commodore users cannot easily forget the PEEKS and
POKES…If you do not like any of these ways, just be inventive. For example you
can type 0101010001 in Notepad and save the file as “test.exe” (by the way,
this will probably do nothing, but at least you have tried!)… Again do not hold
me responsible for any damage caused to your computer. Anything written here is
provided with no warranties and in case you want to program (in HLL, assembly
or machine code) you must first study a lot and be 100% sure that what you do
is legal and not harmful to you H/Y or to others.
Secondly, you can write your own Operating
System in which you can define on your own the way the user has access to RAM. When
working under Linux or Windows (or any other OS developed by someone else, but
not you) you must obey the Linux / Windows rules in order to store and execute
machine code. But in your own OS, you set the rules. It is that simple. In that
way, it will be easy for him to store 1010101001010 in RAM (in the Code Segment
Register – CS – and the IP to be exact, since the CS:IP memory location points
to the location of the next command to be executed) and execute it. Seek
information in Yahoo! about writing your own boot strap (most of them are
written in assembly – i.e. with NASM) and then the kernel (the core) of your
operating system that the boot strap will load in the first place (the kernel
can be written in C or C++ or any othe HLL).