Difference among programming languages

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
mahaju
Posts: 487
Joined: Mon 11 Oct 2010, 07:11
Location: between the keyboard and the chair

Difference among programming languages

#1 Post by mahaju »

Hi
What is the main difference between all the programming languages and compilers anyway? I mean, the only thing the computer understands is machine code, and they all convert high level text into machine level code. Still, each language looks and feels much different than the other (eg, C and BASIC)

Similarly, what does it mean by one compiler being better (or worse) than the other, or more (or less) suited for a particular application? I am not trying to talk about languages and compilers designed for different operating systems (Windows/Linux) or different types of computers (PC/Mobile). I am talking about compilers and languages for the same platform. For example, I can write a C program (hello World for example) and compile in Turbo C or gcc and get the same results (at least I think they are the same, I know there should be some difference even if I haven't noticed it, but that's why I am posting this question).

So what's the difference?

PS: Could you please tell me in brief about various types of compiler optimizations, what they are, what they are good for and not good for and how the C volatile keyword is related to it?

Thanks in advance.

User avatar
RetroTechGuy
Posts: 2947
Joined: Tue 15 Dec 2009, 17:20
Location: USA

Re: Difference among programming languages

#2 Post by RetroTechGuy »

mahaju wrote:Hi
What is the main difference between all the programming languages and compilers anyway? I mean, the only thing the computer understands is machine code, and they all convert high level text into machine level code. Still, each language looks and feels much different than the other (eg, C and BASIC)
Compilers compile "human readable" code into machine language. The language itself defines the grammar and vocabulary required for the compiler to convert the "human readable" language into machine language (though with C, "human readable" is a strange concept... :lol: )

C looks nothing like Basic. Basic looks more like Fortran than C.

Which language do you know? What do you want to do with it?

FWIW, a friend of mine recommends learning python or perl, rather than some of the older languages.

Re C: http://linux.die.net/man/1/gcc
[url=http://murga-linux.com/puppy/viewtopic.php?t=58615]Add swapfile[/url]
[url=http://wellminded.net63.net/]WellMinded Search[/url]
[url=http://puppylinux.us/psearch.html]PuppyLinux.US Search[/url]

User avatar
Pizzasgood
Posts: 6183
Joined: Wed 04 May 2005, 20:28
Location: Knoxville, TN, USA

#3 Post by Pizzasgood »

Using two different C compilers, the resulting executables should both generate a program that performs the same task. However the means by which it performs the task may be slightly different due to different methods of optimization and such. There is not a 1-to-1 conversion between C and whatever instruction set a particular processor supports, so different compilers are going to do the conversion in different ways.

I can't say much regarding specific optimizations.

Different languages being suited for different tasks has to do with... being suited for different tasks. Writing code to perform certain actions is just much cleaner with some types of syntax and feature sets than with others. Bash is great for the type of system scripting it is used for, what with its easy capturing, piping, and redirecting of inputs and outputs. However, it would be horrible at the types of stuff that Javascript is used for (traversing the DOM, attaching interesting functions to HTML elements, etc.). Bash's array support is somewhat cumbersome to use, and it has basically no easy way to deal with hierarchical structures (besides the filesystem tree anyway).
[size=75]Between depriving a man of one hour from his life and depriving him of his life there exists only a difference of degree. --Muad'Dib[/size]
[img]http://www.browserloadofcoolness.com/sig.png[/img]

User avatar
Cust0dian
Posts: 28
Joined: Fri 22 Oct 2010, 11:26
Location: Russian Federation, St. Petersburg

#4 Post by Cust0dian »

Hi, mahaju.

About compilers ― no big difference for same language (GCC\C and Ch), it's more about specifications of a particular compiler.

Compilers for different languages produces different output code. Why is that? As already told, different languages ― different tasks. But for some reasons, for example code written in functional language is simpler to optimize by compiler. But this ones are so called "academic" languages, because mostly used for science purposes.

About compiler optimization ― there are a lot of optimization techniques. Most significant are loop optimization (a lot of programs spend most of their work-time in loops) and hardware dependent optimization (for a particular processor), but last one is quite useless if not compiling program for yourself only. And don't forget ― any optimization mostly is a choice between speed and size.

Loop can be optimized in different ways... If not all, most of following optimizations can be done by the programmer in native source. As for modern compilers:
​​ ​ • Code, that changes nothing in the loop must be out of the loop.
​​ ​ • Two loops adjacent loops can be forked in one (with only one iterator).
​​ ​ • Forcing cache use for loops that are not intend to use it, but will have more performance in such way.
​ ​ • If first iteration(s) is(are) problematic, split them in different loop
​ ​ • Body of loop can be repeated for a number of times, so there will be less checks and switches (more memory consumption for better speed)

But really, most powerful optimization is math, logic (algorithm and design perfection) and experience (right choice when optimization must occur and which technique to use).

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#5 Post by technosaurus »

see pet packaging in my signature for optimization flags for the key size optimizing flags... or the documentation of your compiler for others - most optimizations that decrease size also improve speed but not vice versa -Os will increase speed and decrease size while -O3 will typically increase size and _sometimes_ increase speed ... when code gets too large it takes longer to load but more importantly it can cause cache issues that slow things down -- graphite (enabled by cloog and ppl) _should_ help to minimize this in gcc (still does not seem stable though)

different compilers do make a difference - tcc gcc and llvm/clang implement different optimizations ... versions even make a difference

the C library you choose to base on makes a bigger difference than people realize - contrary to popular belief, the size difference is not limited to the compiled size of the respective shared library. It even affects the size of code compiled against its headers, because it uses the internal structures. (it is fairly common for a static linked dietlibc binary to even be smaller than a glibc binary that is dynamically linked)
The same can be said for C++, but the effects are even greater due to the object containerization.

some c libraries: glibc, eglibc, uclibc, bsdlibc, dietlibc, newlibc
some c++ libraries: libstdc++(gcc), libc++(llvm/apple), stdcxx(apache), uclibc++(uclibc) , embeddedstl(dietlibc) (there are a lot of other standard template libraries around)
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

User avatar
Lobster
Official Crustacean
Posts: 15522
Joined: Wed 04 May 2005, 06:06
Location: Paradox Realm
Contact:

#6 Post by Lobster »

There is a woefully out of date explanation and list of Puppy languages here:
http://puppylinux.org/wikka/ProgrammingLanguages

Maybe someone will have the inclination to update . . . :)
Puppy Raspup 8.2Final 8)
Puppy Links Page http://www.smokey01.com/bruceb/puppy.html :D

Post Reply