Welcome, Guest. Please Login
 
  HomeHelpSearchLogin FAQ Radified Ghost.Classic Ghost.New Bootable CD Blog  
 
Pages: 1 2 
Send Topic Print
Programming questions (Read 7090 times)
Rad
Radministrator
*****
Offline


Sufferin' succotash

Posts: 4090
Newport Beach, California


Back to top
Programming questions
Aug 17th, 2009 at 12:22pm
 
From page 9:

http://books.google.com/books?id=4LMtA2wOsPcC&printsec=frontcover&source=gbs_v2_...

Quote:
It is not yet clear to what extent, and in what problem domains, we can expect compilers to discover good algorithms for problems stated at a very high level. In any domain in which the compiler cannot find a good algorithm, the programmer needs to be able to specify one explicitly.

I was under the impression that compilers don't 'discover/find' anything .. that they simply convert into assembly code or bytecode the code a programmer has programmed (in a 'high-level' langauge).

This passage infers a compiler does more than I understand it does.

What am I missing?
 
WWW  
IP Logged
 

MrMagoo
Übermensch
*****
Offline


Resident Linux Guru

Posts: 1026
Phoenix, AZ (USA)


Back to top
Re: Programming questions
Reply #1 - Aug 17th, 2009 at 6:12pm
 
Rad wrote on Aug 17th, 2009 at 12:22pm:
I was under the impression that compilers don't 'discover/find' anything .. that they simply convert into assembly code or bytecode the code a programmer has programmed (in a 'high-level' langauge).

This passage infers a compiler does more than I understand it does.

An assembler converts assembly code to machine code.  Assembly code has almost a 1-1 translation between code and cpu instructions. 

A compiler takes high-level source and compiles it into machine code.  Each source code instruction has a few to several cpu instructions that have to be executed.  Even something as simple as A=5 has several steps:

1. Allocate enough memory for an integer
2. Label that memory A
3. Convert the number 5 to binary
4. Store that binary in the space labeled A

Compilers also do some level of optimization.  Which piece of memory should the program allocate?  Is there some that can be reused?  Should room be left to expand this integer into a float later? 

Java books often spend a lot of time praising both the compile time and run time optimizations Java can do.  The details of what these optimizations are and how they work are still over my head.

Rad wrote on Aug 17th, 2009 at 12:22pm:
What am I missing?

I'm missing Nigel.  He'd have a fantastic explanation for this question, and we'd both learn something.
 
WWW  
IP Logged
 
Rad
Radministrator
*****
Offline


Sufferin' succotash

Posts: 4090
Newport Beach, California


Back to top
Re: Programming questions
Reply #2 - Aug 17th, 2009 at 10:13pm
 
MrMagoo wrote on Aug 17th, 2009 at 6:12pm:
I'm missing Nigel.He'd have a fantastic explanation for this question, and we'd both learn something. 

Quote:
Compilers do much more than you might think in order to bridge the gap between source language and machine, because the source language a programmer writes in is often - indeed, usually - working with quite different concepts than those the machines themselves truck in.

There are two main ways this happens, one for lower-level and languages and one for higher-level languages.

Low-level languages like FORTRAN and C and their many successors started out being built to compile in a very straightforward way to the machines of their day (in the case of C, one machine - the PDP-11). Indeed, the official definitions of these languages make this very clear, by describing how the language works in terms of a notional abstract machine - so again for C, the compiler's first job is to decide how to map that abstract machine model on to the physical hardware the program is going to have to run on.

The thing is, modern physical machines are enormously more capable than machines of then not just in terms of raw speed and memory size, but also in that some of them can do some entirely new kinds of things which don't exist in the machines the languages were designed for.

Parallelism in particular is challenging for the entire class of languages which are built around a model of the computer being a single, sequential machine. There is (and has been for many years) a huge amount of research being done into ways that compilers can take programs written in these languages and generate efficient code for machines which have a large number of parallel units.

The most visible example of this would be things like vector and matrix operations; folks write lots of code to do these things in C and FORTRAN, and that code has to manipulate each element of a vector or array one at a time in sequence because there is no other way to describe what to do in those languages.

A compiler for those languages which targets a machine which has the capability to do massive numbers of operations on vectors or matrices in parallel at the same time thus has an interesting problem; in order to make the compiled executable work at the full speed the machine is capable of, it has to be able recognise when a program is trying to do things on vectors even though the language has no way of explicitly saying that.

The high-level language version of this problem is that as languages get further away from machines, the languages cease asking the programmer to describe things in terms of "do this, then do this, then do this" but instead become more about being a way for specifying outcomes and leaving the details up to the system (the compiler and the associated run-time which supports it).

Take, for instance, database querying - which some languages have integrated into themselves quite thoroughly. In that case, the designers of the compiler for the language have to decide for themselves what specific algorithms to employ to achieve those outcomes, and so the language and its run-time itself are expected to evolve and get better over time.

The logic-programming languages have a long history of this; the language Prolog is a great example.

- Nigel

Yer right. That's pretty cool .. especially the part about "specifying outcomes and leaving the details up to the system."

From the text:

Quote:
One might suspect that concurrent languages also form a separate class (and indeed this book devotes a chapter to the subject), but the distinction between concurrent and sequential execution is mostly orthogonal to the classifications above. Most concurrent programs are currently written using special library packages or compilers in conjunction with a sequential language such as Fortran or C. A few widely used languages, including Java, C#, Ada, and Modula-3, have explicitly concurrent features. Researchers are investigating concurrency in each of the language classes mentioned here.
 
WWW  
IP Logged
 
Rad.in.UbuntuVM
Radmeister
**
Offline


Rad in Ubuntu 9.04 Jaunty
Virtual Machine

Posts: 92


Back to top
Re: Programming questions
Reply #3 - Aug 17th, 2009 at 10:16pm
 
Stumbled upon this site today:

http://jruby.codehaus.org/

Quote:
JRuby is an 100% pure-Java implementation of the Ruby programming language.

I do not understand how you can have a "Implementation" of one language by another. I mean, it would seem, you would have either Java or Ruby. I don't get how you can mix the two.
 
WWW  
IP Logged
 
MrMagoo
Übermensch
*****
Offline


Resident Linux Guru

Posts: 1026
Phoenix, AZ (USA)


Back to top
Re: Programming questions
Reply #4 - Aug 18th, 2009 at 2:29pm
 
Rad.in.UbuntuVM wrote on Aug 17th, 2009 at 10:16pm:
I do not understand how you can have a "Implementation" of one language by another. I mean, it would seem, you would have either Java or Ruby. I don't get how you can mix the two.

Think of it as a compiler that takes Ruby source and compiles it to Java bytecode.  It's sort of a converter.  I think technically it's a Ruby interpreter written in Java.  The official Ruby interpreter is written in C.

JRuby is actually pretty cool.  It runs a lot faster than Ruby1.8, and slightly faster than Ruby1.9.  It also runs on the JVM, so you can run it on any system that supports Java.  On the disadvantage side, it does take slightly more memory and slightly longer to start up than the official Ruby.

Of special interest to me is that there are some hacks that allow JRuby to run on the Android mobile platform.  Theoretically, I should be able to write code in Ruby and run it on my phone (although I haven't tried it out yet.)

Rad.in.UbuntuVM wrote on Aug 17th, 2009 at 10:16pm:
JRuby is an 100% pure-Java implementation of the Ruby programming language. 

I think its more like 99.9% compatible.  I've heard a few things don't mesh up perfectly.
 
WWW  
IP Logged
 
Rad
Radministrator
*****
Offline


Sufferin' succotash

Posts: 4090
Newport Beach, California


Back to top
Re: Programming questions
Reply #5 - Aug 22nd, 2009 at 12:56pm
 
Sounds like you've already heard of it.

A convertor. Cool. I can understand that. I'm starting to become more familiar with the term 'implementation.'

Was gonna ask 'why' but you answered that also.

Speaking of implementations .. regarding interpreters and interpreted languages .. or scripting languages .. is it your understanding that languages such as Perl and Python and Ruby & PHP set up some kind of 'virtual machine' to process the code?

I always imagined source code for scripting langauages was compared to whatever files are contained in (for example, Perl files):

Code:
/usr/bin/perl 


And somehow generated output (magically). But this concept may be inaccuarte. Do you have any insight regarding how scripts are actually run?

Learning terms such as 'compiler' .. 'interpreter' .. 'translator' .. 'virtual machine' .. 'pre-processor' .. etc. Very cool. Feels good.

One term I keep hearing/seeing, but don't really understand is > 'library'.
 
WWW  
IP Logged
 

MrMagoo
Übermensch
*****
Offline


Resident Linux Guru

Posts: 1026
Phoenix, AZ (USA)


Back to top
Re: Programming questions
Reply #6 - Aug 22nd, 2009 at 3:26pm
 
Rad wrote on Aug 22nd, 2009 at 12:56pm:
Speaking of implementations .. regarding interpreters and interpreted languages .. or scripting languages .. is it your understanding that languages such as Perl and Python and Ruby & PHP set up some kind of 'virtual machine' to process the code?

There's no virtual machine.  A better way to think of it is that the interpreter reads the code, then compiles and runs a single line at a time.  It's often more complex than that, but thinking of it that way will get you close as far as understanding the process.

Just an FYI - I don't think PHP is an interpreted language - it is compiled.  I think it is compiled at runtime, just before it is executed.  You can also compile it at ahead of time.

http://en.wikipedia.org/wiki/PHP - See the "Speed Optimization" section.  It mentions compiling. 


Rad wrote on Aug 22nd, 2009 at 12:56pm:
One term I keep hearing/seeing, but don't really understand is > 'library'.

A library is basically a set of pre-written functions to help save you the trouble.  Here's an example:

Earlier, we talked about making a function to calculate the area of a circle.  Now, say we found it very helpful and decided to make more functions to improve our code even more.  We make functions to calculate the area of squares, triangles, etc.  We end up with a few dozen functions.  We decide that these functions might be useful to other people as well.

So, we take these functions and put them into a separate file, called areaFuncts.  We can now include this file in any other program we write, allowing us access to those functions.  areaFuncts is now a library. 

It differs in every language, but most languages have some ability to use libraries in your code.  A language isn't very useful without libraries because everyone would have to write everything from scratch every time.  Hackers hate that.
 
WWW  
IP Logged
 
Rad.Test
Technoluster
***
Offline


Rad's non-Admin test-profile
in Firefox

Posts: 108


Back to top
Re: Programming questions
Reply #7 - Aug 22nd, 2009 at 10:08pm
 
MrMagoo wrote on Aug 22nd, 2009 at 3:26pm:
Just an FYI - I don't think PHP is an interpreted language - it is compiled.

Really? (Rad scratches head.)

I thought it started as cgi script thingy .. and is/was similar to Perl. That kinda blows my whole idea of compiled vs interpreted/scripting.

So does the term 'scripting' not apply to PHP?

"Pre-written functions" .. okay, I can dig that. And I can see why that would make them valuable. I heard Java has tons of libraries .. no? I'm still not crazy about the term 'library' tho.
 
 
IP Logged
 
MrMagoo
Übermensch
*****
Offline


Resident Linux Guru

Posts: 1026
Phoenix, AZ (USA)


Back to top
Re: Programming questions
Reply #8 - Aug 23rd, 2009 at 5:11am
 
Rad.Test wrote on Aug 22nd, 2009 at 10:08pm:
So does the term 'scripting' not apply to PHP?

It is definitely considered a scripting language.  'Scripting' language is a term that is applied somewhat subjectively.

Rad.Test wrote on Aug 22nd, 2009 at 10:08pm:
That kinda blows my whole idea of compiled vs interpreted/scripting.

Yes, interpreted/compiled have to do with fundamental design choices on the internals of the language which affect how it goes from source to binary.  Scripting vs application language has more to do with the common use case - what do people most use it for and what is it best suited to doing? 

Java is considered an application language.  Perl is considered a scripting language.  Both are compiled to byte-code and then the byte-code is interpreted at run-time (although Java is usually compiled ahead of time while Perl is usually compiled at run-time.)  So the waters are much muddier than the fanboys of some languages would have you believe.

Rad.Test wrote on Aug 22nd, 2009 at 10:08pm:
I thought it started as cgi script thingy .. and is/was similar to Perl.

I understand that it replaced a set of CGI scripts the author was using for his web site.  It is still used almost exclusively for web cgi-type scripts.  I wouldn't consider it similar to Perl.  Syntactically, it feels a little like C++ mixed with html.

Rad.Test wrote on Aug 22nd, 2009 at 10:08pm:
I heard Java has tons of libraries .. no?

Yes, Java has a lot.  Perl also has a library for nearly anything you can think of.  My experience is that Perl libraries are easier to find and easier to use, but my experience with Java is very limited so the comparison may not be fair.  I think it depends heavily on what type of program you are writing.
 
WWW  
IP Logged
 
Rad
Radministrator
*****
Offline


Sufferin' succotash

Posts: 4090
Newport Beach, California


Back to top
Re: Programming questions
Reply #9 - Aug 23rd, 2009 at 10:44am
 
MrMagoo wrote on Aug 23rd, 2009 at 5:11am:
It is definitely considered a scripting language.

So it's a compiled scripting language? Never heard of one of those b4. What other languages fall into that category?

MrMagoo wrote on Aug 23rd, 2009 at 5:11am:
Scripting vs application language 

You are now using the term 'application' to refer to compiled languages, yes? Is that a common synonym?

MrMagoo wrote on Aug 23rd, 2009 at 5:11am:
Perl is considered a scripting language.Both are compiled to byte-code and then the byte-code is interpreted at run-time (although Java is usually compiled ahead of time while Perl is usually compiled at run-time.)

So you're saying Perl is also a 'compiled' language?

Perl is compiled TWICE .. both times at run-time?

Does different processors and chipsets and operating systems have an effect on how Perl is interpreted/compiled/run (how it works)??

Both the forums & blog are Perl scripts. (Or maybe a SET of Perl scripts.) Does upgrading your copy of Perl have an effect on how they are run?
 
WWW  
IP Logged
 
MrMagoo
Übermensch
*****
Offline


Resident Linux Guru

Posts: 1026
Phoenix, AZ (USA)


Back to top
Re: Programming questions
Reply #10 - Aug 23rd, 2009 at 3:50pm
 
Rad wrote on Aug 23rd, 2009 at 10:44am:
You are now using the term 'application' to refer to compiled languages, yes?

No.  My point is that interpreted/compiled depends on how the languages was *designed*.  Scripting/Application language depends on how it is commonly *used* and is somewhat subjective.

Rad wrote on Aug 23rd, 2009 at 10:44am:
So you're saying Perl is also a 'compiled' language?

No, Perl is considered an interpreted language.  I was comparing Perl to Java to make the point that both languages go from source code to execution following a similar path, but Perl is usually considered a scripting language while Java is considered an application language.  So interprted/compiled does not equal scripting/application language.

Rad wrote on Aug 23rd, 2009 at 10:44am:
Perl is compiled TWICE .. both times at run-time?

No, it is compiled once to byte code.  Then the byte-code is interprted.

From Wikipedia:
http://en.wikipedia.org/wiki/Perl
Quote:
The life of a Perl interpreter divides broadly into a compile phase and a run phase.[25] In Perl, the phases are the major stages in the interpreter's life cycle. Each interpreter goes through each phase only once, and the phases follow in a fixed sequence....

At compile time, the interpreter parses Perl code into a syntax tree. At run time, it executes the program by walking the tree.



Rad wrote on Aug 23rd, 2009 at 10:44am:
Does different processors and chipsets and operating systems have an effect on how Perl is interpreted/compiled/run (how it works)??

It can, but if the code is written carefully it won't.

Rad wrote on Aug 23rd, 2009 at 10:44am:
Does upgrading your copy of Perl have an effect on how they are run? 

It can.  Perl usually preserves backward compatibility as much as possible, but sometimes there are minor differences, especially in major revision changes of Perl.  I would say that most of the time, upgrading Perl won't break you site, but you'd want to check with the forum/blog software authors to make sure their software has been check to run against the new version of Perl.
 
WWW  
IP Logged
 

Rad
Radministrator
*****
Offline


Sufferin' succotash

Posts: 4090
Newport Beach, California


Back to top
Re: Programming questions
Reply #11 - Aug 23rd, 2009 at 4:03pm
 
Lotsa "No's" there. I been a little spacey today. Not sure why.

So Perl is compiled (to byte-code) but it is not a "compiled" langauge? That seems contradictory.
 
WWW  
IP Logged
 
MrMagoo
Übermensch
*****
Offline


Resident Linux Guru

Posts: 1026
Phoenix, AZ (USA)


Back to top
Re: Programming questions
Reply #12 - Aug 23rd, 2009 at 5:13pm
 
Rad wrote on Aug 23rd, 2009 at 4:03pm:
Lotsa "No's" there. I been a little spacey today.

These concepts can stretch your mind a little.  That's probably where the extra space is coming from.
 
WWW  
IP Logged
 
Rad
Radministrator
*****
Offline


Sufferin' succotash

Posts: 4090
Newport Beach, California


Back to top
Re: Programming questions
Reply #13 - Aug 24th, 2009 at 12:21pm
 
the term 'parse' i read refers to syntactic analysis.

does this mean a parser does nothing but ANALYZE source code? that it does not change or modify it in any way?

if so, would this infer that the purpose of a parser is to verify/validate syntax? (and generate error messages where the source does not comply)
 
WWW  
IP Logged
 
MrMagoo
Übermensch
*****
Offline


Resident Linux Guru

Posts: 1026
Phoenix, AZ (USA)


Back to top
Re: Programming questions
Reply #14 - Aug 25th, 2009 at 6:15pm
 
Rad wrote on Aug 24th, 2009 at 12:21pm:
does this mean a parser does nothing but ANALYZE source code? that it does not change or modify it in any way?

Correct.  A parser's job is to read things and find out what it says.

Rad wrote on Aug 24th, 2009 at 12:21pm:
if so, would this infer that the purpose of a parser is to verify/validate syntax? (and generate error messages where the source does not comply)

I don't think the error messages would come from the parser.  I think the compiler or interpreter would generate the error message based on what it finds when it parses the source.
 
WWW  
IP Logged
 
Pages: 1 2 
Send Topic Print