Radified Community Forums | |
http://radified.com/cgi-bin/yabb2/YaBB.pl
Rad Community Technical Discussion Boards (Computer Hardware + PC Software) >> PC Hardware + Software (except Cloning programs) >> Programming questions http://radified.com/cgi-bin/yabb2/YaBB.pl?num=1250529721 Message started by Rad on Aug 17th, 2009 at 12:22pm |
Title: Programming questions Post by Rad on Aug 17th, 2009 at 12:22pm
From page 9:
http://books.google.com/books?id=4LMtA2wOsPcC&printsec=frontcover&source=gbs_v2_summary_r&cad=0#v=onepage&q=&f=true Quote:
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? |
Title: Re: Programming questions Post by MrMagoo on Aug 17th, 2009 at 6:12pm Rad wrote on Aug 17th, 2009 at 12:22pm:
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:
I'm missing Nigel. He'd have a fantastic explanation for this question, and we'd both learn something. |
Title: Re: Programming questions Post by Rad on Aug 17th, 2009 at 10:13pm MrMagoo wrote on Aug 17th, 2009 at 6:12pm:
Quote:
Yer right. That's pretty cool .. especially the part about "specifying outcomes and leaving the details up to the system." From the text: Quote:
|
Title: Re: Programming questions Post by Rad.in.UbuntuVM on Aug 17th, 2009 at 10:16pm
Stumbled upon this site today:
http://jruby.codehaus.org/ Quote:
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. |
Title: Re: Programming questions Post by MrMagoo on Aug 18th, 2009 at 2:29pm Rad.in.UbuntuVM wrote on Aug 17th, 2009 at 10:16pm:
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:
I think its more like 99.9% compatible. I've heard a few things don't mesh up perfectly. |
Title: Re: Programming questions Post by Rad on 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:
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'. |
Title: Re: Programming questions Post by MrMagoo on Aug 22nd, 2009 at 3:26pm Rad wrote on Aug 22nd, 2009 at 12:56pm:
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:
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. |
Title: Re: Programming questions Post by Rad.Test on Aug 22nd, 2009 at 10:08pm MrMagoo wrote on Aug 22nd, 2009 at 3:26pm:
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. |
Title: Re: Programming questions Post by MrMagoo on Aug 23rd, 2009 at 5:11am Rad.Test wrote on Aug 22nd, 2009 at 10:08pm:
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:
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 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:
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. |
Title: Re: Programming questions Post by Rad on Aug 23rd, 2009 at 10:44am MrMagoo wrote on Aug 23rd, 2009 at 5:11am:
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:
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:
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? |
Title: Re: Programming questions Post by MrMagoo on Aug 23rd, 2009 at 3:50pm Rad wrote on Aug 23rd, 2009 at 10:44am:
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:
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:
No, it is compiled once to byte code. Then the byte-code is interprted. From Wikipedia: http://en.wikipedia.org/wiki/Perl Quote:
Rad wrote on Aug 23rd, 2009 at 10:44am:
It can, but if the code is written carefully it won't. Rad wrote on Aug 23rd, 2009 at 10:44am:
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. |
Title: Re: Programming questions Post by Rad on 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. |
Title: Re: Programming questions Post by MrMagoo on Aug 23rd, 2009 at 5:13pm Rad wrote on Aug 23rd, 2009 at 4:03pm:
These concepts can stretch your mind a little. That's probably where the extra space is coming from. |
Title: Re: Programming questions Post by Rad on 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) |
Title: Re: Programming questions Post by MrMagoo on Aug 25th, 2009 at 6:15pm Rad wrote on Aug 24th, 2009 at 12:21pm:
Correct. A parser's job is to read things and find out what it says. Rad wrote on Aug 24th, 2009 at 12:21pm:
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. |
Title: Re: Programming questions Post by Rad on Aug 30th, 2009 at 3:18pm
Is there a simple way to describe the distinction between 'keywords' and predefined 'identifiers'?
They look like much the same thing to me. Maybe they are used for different purposes. |
Title: Re: Programming questions Post by MrMagoo on Aug 30th, 2009 at 7:30pm
Keywords are words that mean something to the compiler/intrepreter. They can be commands, notations, or several other things, but they are words that the compiler/interpreter has built-in knowledge of.
Identifiers are names that you give to objects. In the statement 'answer = part1 + cos( angle1 )' "answer" is an identifier. It is a name you have given to something (in this case a variable.) In the same statement, the cos() is a function that computes the cosine of an angle. 'cos' would be a keyword if the function is built into the compiler. If it is instead the name of a function that you wrote yourself, then it would be an identifier for that function. Keywords are often also called reserved words, because they are reserved for use by the compiler. |
Title: Re: Programming questions Post by Spanky on Aug 31st, 2009 at 12:18am
nice, thanks.
i was having trouble with the identfier part. |
Radified Community Forums » Powered by YaBB 2.4! YaBB © 2000-2009. All Rights Reserved. |