Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 14th, 2005, 1:21 PM   #11
pr0gm3r
Hobbyist Programmer
 
Join Date: Dec 2004
Location: CA
Posts: 102
Rep Power: 4 pr0gm3r is on a distinguished road
Send a message via MSN to pr0gm3r
Smile

Quote:
Originally Posted by phenofire
Hello. I'm having a hard time understanding the interaction between code, programming language, and the actual computer.
I've seen tutorials on the net about how to write your own programming language, for example. To do that, aren't they using a programming language? That totally doesn't make sense to me.
Then there's the matter of how the code actually interacts with the computer. Can someone out there take me step by step through how code works its way down to the actual hardware and then back onto the screen? And wouldn't this entire process have to go through the windows operating system? It's hard for me to explain what I'm asking, I just don't understand how code works at its most basic level.
And how come I never see a command like "draw" in most programming languages? If games are written with these languages how do they get all the flashy stuff onto the screen?
As you can see, I'm in a doozy. Any help appreciated.
This is how compiler process your C/C++ code.


After that they will translated them to machine language. Finaly the Kernel send instructions to Computer hardware/computer devices.

To understand full concept of programming and all the computer architecture are very complex structure.

Please correct me if there any mistake in my explanations.

Thanks,
Harry
__________________
--
pr0gm3r
pr0gm3r is offline   Reply With Quote
Old Sep 14th, 2005, 2:22 PM   #12
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
At its most basic level, the "code" is a set of logic signals connected to hardware logic devices. These gate binary patterns here and there, including into and out of the ALU (arithmetic logic unit). One can easily build an adder and provide its code with switches and its output with lighted devices. As the industry has grown, this has progressed from a reasonably comprehensible handful of components to several zillion transistors. The basic premise is the same; you just need to lay your hands on the right material. As mentioned previously, a few posts aren't gonna getcha there.

Interesting sig, this:
Quote:
"Sharing is not an act of piracy"
Depends on who owns what you're sharing, huh?
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Sep 14th, 2005, 3:25 PM   #13
phenofire
Newbie
 
Join Date: Sep 2005
Posts: 4
Rep Power: 0 phenofire is on a distinguished road
Alright, thanks everyone! You know, I think Mr. Gates might have been on to something with the whole "computer" thing...
phenofire is offline   Reply With Quote
Old Sep 14th, 2005, 4:26 PM   #14
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Son, I hate to tell you this, be we were messing with these thangys when "Mr. Gates" was still in diapers.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Sep 14th, 2005, 6:06 PM   #15
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Quote:
Originally Posted by phenofire
You know, I think Mr. Gates might have been on to something with the whole "computer" thing...
*coughs* Babbage, Zuse, Turning, Neumann maybe, but Bill Gates? I think computers have been around a little longer than Microsoft
Arevos is offline   Reply With Quote
Old Sep 14th, 2005, 8:57 PM   #16
phenofire
Newbie
 
Join Date: Sep 2005
Posts: 4
Rep Power: 0 phenofire is on a distinguished road
OK wow I wasn't thinking clearly. *Slaps self*. We'll go with Zuse.
Another question though - they say high level programming languages aren't as efficient because they don't convert to machine code as fluently as lower level languages. Why is that? If they're being converted to 0s and 1s, how can it be any more efficient in one language than it is in another? Does the problem lie in an inefficient conversion process?
phenofire is offline   Reply With Quote
Old Sep 14th, 2005, 9:13 PM   #17
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Let me give you one brief example. If you write a procedure (function) in assembly language, you know what registers you are going to use and destroy. When you construct the call, you save those, so as not to mess up the calling code's data. Compiler writers will devise a set of things they expect to use (whether they actually wind up being used or not depends upon the things the coder does) and save all those. Some of that is wasted. Optimization is really good, these days, and it takes a good assembly coder (knowledgeable about really technical details like the operation of cache, and so forth) to beat it, but there's still waste because of the genericity of the translation.

The purpose of the higher-level languages is to put a layer of abstraction between the mind of the human and the operation of the machine. Their mechanisms are entirely different. Programming in ways tailored to the machine distracts the mind from abstract concepts to a significant degree. It's a different mindset. The problem space is human, generally, and the solution space is Von Neumann. Someone has to deal with that. Economic efficacy says it shouldn't be the day-to-day solution-deviser/coder.

In the past, resources were so expensive that one couldn't actually afford to write the higher level languages that provide the abstraction, and implement them on the machine. Now, one can't afford not to except in the most stringent of circumstances.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Sep 15th, 2005, 11:38 AM   #18
pr0gm3r
Hobbyist Programmer
 
Join Date: Dec 2004
Location: CA
Posts: 102
Rep Power: 4 pr0gm3r is on a distinguished road
Send a message via MSN to pr0gm3r
Quote:
Originally Posted by DaWei
Interesting sig, this:
Depends on who owns what you're sharing, huh?
Thank you.. hmm.. I like the idea of Free Software by GNU!
__________________
--
pr0gm3r
pr0gm3r is offline   Reply With Quote
Old Sep 15th, 2005, 11:45 AM   #19
coldDeath
Expert Programmer
 
coldDeath's Avatar
 
Join Date: Aug 2005
Location: UK
Posts: 862
Rep Power: 4 coldDeath is on a distinguished road
Send a message via AIM to coldDeath Send a message via Yahoo to coldDeath
Don't we all?
__________________
Join us at #programmingforums @ irc.freenode.net!

My software never has bugs. It just develops random features.
coldDeath is offline   Reply With Quote
Old Sep 15th, 2005, 4:45 PM   #20
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Quote:
Originally Posted by phenofire
OK wow I wasn't thinking clearly. *Slaps self*. We'll go with Zuse.
Good choice

Quote:
Originally Posted by phenofire
Another question though - they say high level programming languages aren't as efficient because they don't convert to machine code as fluently as lower level languages. Why is that? If they're being converted to 0s and 1s, how can it be any more efficient in one language than it is in another? Does the problem lie in an inefficient conversion process?
Essentially, yes. Computers aren't as intelligent as human beings, and therefore it's infeasible to get a high level language like Python to the same levels of efficiency as a program in C or Assembly.

For instance, say I wished to create a list of the first 10 square numbers. In C, I suspect the most efficient way to solve this problem would be:

unsigned char numbers[10];
unsigned char i;
for (i = 0; i < 10; i++)
  numbers[i] = i * i;
Whilst in Python:
numbers = [i * i for i in range(10)]
Python is more concise to us humans, but it's more difficult for a computer to understand.

In C, we've told the computer to create an array of ten bytes, and a counter of one byte, so the total size of all our variables is a measly 11 bytes. In reality, it's likely to be a little more than that, since I do believe we need to factor in the references to these variables, but we're still talking less than 20 bytes on the stack. That's tiny.

Python, on the other hand, doesn't bother its programmers with low level concepts of memory. And whilst in C, our array of numbers is literally just a string of 10 bytes, just 80 0s and 1s, in Python we get a list of numbers that's all singing, all dancing. We can query it's length, reverse it, sort it, expand it, shrink it; you name it.

If you wanted to make this python code as efficient as C, you'd have to do all sorts of things. You'd have to recognise that none of the numbers in the list go above 255, and thus only one byte per number is needed. You have to see that the list information does not change, and thus can be represented as a fixed array. You have to realise that none of the fancy list functions are used, and thus we can remove them from our machine code. And that's just the beginning of the things that our hypothetically perfect compiler would have to work out.

Computers aren't sophisticated enough to optimise code by this amount. Thus, Python is always going to be less efficient than C.
Arevos is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:11 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC