A couple basic (hah) computer programming questions

OK, I should probably know better, but my experience with any sort of programming is making silly little games in Basic in the pre-Windows 3.1 days.

  1. Does each language require a special editor, or can I use, say Notepad for any of them? If not, what sort of file would I save the work in? IIRC, Virtual Basic has it’s own GUI and but I’m not sure if that’s necessary to write programs in.

  2. I assume that some languages are more efficient than others. Are there some languages that have specific areas that they’re designed for and won’t well for other applications (uh, poor choice of words. That is, is there a “financial” language that won’t make good games and vice versa?)?

  3. How does one write a programming language? Do they need to know Binary? Do they use another language as a base?

I’m sure I’ll have some more silly questions as the day goes on. Thanks for your help.

Oh, I should probably define what I’d consider a language: a syntax to create a stand alone application, not as a “customization” markup for an existing program: that is, I’d say that C++ is a language, but HTML isn’t. Java is, but XML isn’t.

Is this the correct way of looking at things?

Most do not require a special editor–but you do have to have either a compiler or an interpreting program which may or may not cost money. VB is a rare instance where the compiler only comes with a editor, and the editor packs in a lot of stuff secretly for the compiler. In general, I wouldn’t recommend VB for any application beyond a 5 second test app (if you already know how to use it and have a copy already installed.)

Yes. Every single language was designed to be better for certain tasks. The level at which that language is limited to only a single task will depend on the language.

Compiled languages require that you know the instruction set of the underlying hardware. If you add in libraries of standard functions to your language, then you will also need to know how to interface with the OS and such.
If you’re making an interpretted language, then you just need to know the language you are writing in, and again possibly the OS calls if you have a library of standard functionality.

No problem. =)

You could write a program in, say, Java, using Notepad, and then use the DOS window to invoke the Java compiler, and then the Java virtual machine. IME, however, it’s more usual to use a language sensitive editor or integrated development environment. These have all sorts of bells and whistles to make writing and testing code easier.

Languages are either compiled or interpreted. To “write” a compiled language means essentially to develop a compiler for it. I don’t know much about how that’s done, but the general approach is to write logic to parse the incoming tokens, or “words” in the source code. That is, the program has to figure out what each symbol is supposed to mean in the context where it’s found. Then it writes out equivalent code in assembly or binary.

I know even less about how interpreters work.

Sage Rat’s covered it pretty well, but I’m happy to chip in with two cents when and where I can. Many languages work with a text editor just fine for the writing, but need a compiler or interpreter to run. C, C++, Ada, Pascal, Fortran*, Java, Lisp, PERL, Basic - you can use a text editor to write any of those, as I recall.

You (almost) have to have a GUI for the Visual languages - Visual C++, Visual Basic, etc. I say almost, because there may be a way for a true guru to specify on-screen object positions in the raw text format, but I’m unaware of it.

Though you dismiss HTML, and perhaps rightly so, one could use JavaScript to learn some rudiments of programming very easily - use a text editor to create, and your browser functions as an interpreter. No special software needed.

Now, I wonder what you’re trying to do exactly, so I can offer more specific help.

Nitpick: It’s Perl, not PERL. Yeah, I’m a Perl weenie.

Writing compilers is a bootstrapping problem. For instance, GCC, one of the most widely used C compilers, is written in C and can compile itself. Of course it wasn’t always so; the early versions required some other C compiler to compile it first. You can write a compiler in assembly or machine code, but with the exception of very few specialized applications, they are almost always written in some high-level language, very often C. (In fact, the standard Unix tools Lex and Yacc make generated abstract tokenizers and parser functions rather trivial, but I digress.)

Very true, but HTML isn’t Javascript. :slight_smile: In fact, you don’t even need a web browser to run Javascript. The MacOS Konfabulator package which lets you develop all sorts of neato desktop widgets provides a Javascript runtime, and all the widgets are written in Javascript.

I’ve made GUIs in Java before with nothing other than the straight text interface - it’s a required first-year computer science course where I went to university. Nothing too hard once you get used to it, although having a nice drag’n’drop interface would be appreciated.

I never said HTML was JavaScript. I mention them in the same breath because they’re strongly intertwined, but wanted to make the point to the OP that they were distinct entities, one of them quite useful for his apparent purpose. And given the question as phrased, I think it’s much more likely he owns Internet Explorer or Mozilla Firefox than Konfabulator.

And I’ve made GUIs in HTML/Javascript with a straight text interface. My comment about GUIs was specific to the Visual languages - which, when it comes to object positioning and the like, are often obfuscated.

Make that “programming language.” I think that is what you meant anyway, but the distinction is important. HTML and XML (and its individual document types) are definitely languages. Programming languages are languages for the description of algorithms. “stand alone application” is a bit problematic because all programs rely on something that executes them. Any definition would be arbitrary because there are so many shades of gray.

Is there a Visual C++ language? I had thought that the “Visual” part was just the name of the package. …Though, thinking about it, the wizards for ATL certainly come up with some stuff that definitely isn’t C++ (but also not terribly visual.)

<Questions=Chairman Pow> Lots of good answers already, my additions:

No. Well, not really. Though you can in principle write C++/C#/Java as bare text files you will have a hard time, a decent IDE makes life much easier. Text files very quickly become unfeasible with non-trivial projects. AFAIK IDEs are not interchangable, it’s no good trying to use your favourite Java editing environment for C++, it will get confused.

This is complicated – but yes. If you need something very quick write it in C/C++ better still Assembly. If you need it written quickly on the other hand :slight_smile:

Yes. (ignoring markup languages) To talk to databases you use SQL (which no-one learns for fun). COBOL is/was used for business applications. I seriously doubt that anyone ever wrote a game in COBOL, and I don’t see how you could write onr in SQL. In the curly-brace languages C/C++/Java/C# and VB/Dephi you can write almost anything you want unless you want to talk to the hardware, then you’re down to C/C++ or Assembly.

friedo covered this. I love the example that GCC is written in C and can be used to compile itself. Like using your own car to tow you home.

Or both!

Common Lisp implementations usually have both an interpreter and a compiler. One implementation (CMUCL) has an interpreter, a native-code compiler, and a byte-code compiler/interpreter.

And Java, too – (on both compiled and interpreted).

Java compiles to bytecode, then runs on the interpreter (Java Virtual Machine).

On this one:

Are you asking about writing the compiler/interpreter for a new language? or developing the language itself?

Yes, on both counts. Many languages now have syntax that’s based around another language. Java syntax developed from C++ syntax, but changed some things to make life easier in many regards (i.e. eliminating pointer notation, for starter). And there have also been many advances in compilers, usually starting with the C compilers (optimization of code by the compiler, etc). This can be taken advantage of by other languages – for example, the Ada compiler on my school’s system translates Ada source code into a form where the C compiler (gcc) can finish the job and build the actual fully-compiled target.

And the difference between the two is quite simple: interpreted languages are interpreted by software, while compiled languages are interpreted by hardware.

The details depend on the structure of the language, but the basics are pretty similar. First, you transform the input file of the program to some kind of data structure that you can execute and perform compile-time error checking. Then, you iterate over that data structure and execute the statements it contains.

I wrote a pretty simple XML-based scripting language that offered some basic features: commands, if-then logic, loops and variables. First, I had an XML parser read it into a tree structure, then I ran a DTD validator on it, and then I transformed that tree to a different tree that was a little easier to execute on.

The execute method was pretty straightforward: I traversed over every node in the tree and executed whatever was in there.

Er, no.

Usually when people say a given language implementation is “compiled” they mean it compiles to native code that is directly executed by a CPU. Usually when people say “interpreted” they mean there’s another program (an interpreter) that reads the source code and does what it says.

Java would best be described as “byte compiled.”

Common Lisp implementations can be any combination of compiled, interpreted, or byte-compiled. For example (I’ve done some trimming to make it cleaner):



* (load "simple.lisp")

* #'simple

#<Interpreted Function SIMPLE {58017D41}>

* (compile-file "simple")

; Compiling: /tmp/simple.lisp 16 MAR 05 11:00:29 am
; Compiling DEFUN SIMPLE: 
; Compilation finished in 0:00:00.

* (load "simple.x86f")

* #'simple

#<Function SIMPLE {580B8CB9}>

*  (compile-file "simple" :byte-compile t)

; Compiling: /tmp/simple.lisp 16 MAR 05 11:00:29 am
; Byte Compiling DEFUN SIMPLE: 
; Compilation finished in 0:00:00.

* (load "simple.lbytef")

* #'simple

#<Byte function SIMPLE {580DBB89}>


I want to say that MS J++ has an option to generate a compiled binary from Java code, but as that’s non-standard, it’s questionable whether you want to count it.

MS J++? What’s that? I can’t find it on java.sun.com. :wink:

Good point. I usually try and seperate a language’s definition from its implementations, unless there’s a single canonical implementation (e.g., Perl, PL/SQL). I’m so used to using Sun’s version I forgot there are others.

FTR, gcj, the GNU Java compiler, also compiles Java to native code.

Er, yes. The term “compile” doesn’t have to mean “down to native CPU instruction set”. And I was not using it in that way. I was not claiming that Java is compiled down to system-specific architecture. I was simply pointing out that the techniques of “compiling” and “interpreting” are both used in Java. The “javac” program from the J2SDK compiles the source code to an intermediate level (bytecode). The interpreter runs that code.

And Sun calls their javac tool a compiler, so that term works fine for me.

Which is why I said:

Instead of making a broader statement about what the word “compiles” means.

If you say a language is “compiled,” people are going to think you mean that the language gets compiled to native code. That’s just how the word is used in that situation.

If you don’t agree, we’ll just have to agree to disagree. But I’m right.