I'd like to learn a language that compiles to machine code. I feel that this is Java's main weakness. I'd like something that has Java-like syntax, and doesn't have Microsoft's hands all over it. I'd also like it to be declarative. Right off the bat, there are a few languages that are disqualified (plus a few I don't like):
C++
C#, consider me wary about Microsoft and this.
Python

Hmm... I thought there were more. (See Kerm: I don't hate everything)

Anyway, if you could all suggest your favorite languages, including some sample syntax and an object or two, and some justifications. I really haven't looked into this too much, so a lot of variety would be nice.
I'm rather partial to Haskell. It's very clean mathematically (since it's a pure functional language), but it can be a bit of a challenge to get your head around. The syntax is far from Java's, which might put you off it. Here are a few implementations of the Fibonacci sequence:
Code:
```-- Type signature (may be omitted, but helps clarity) fib :: Integer -> Integer -- Explicit recursive function to get the nth number fib 1 = 1 fib 2 = 1 fib n = fib (n - 1) + fib (n - 2) -- Define it as an infinite list instead fibs :: [Integer] fibs = 1 : 1 : zipWith (+) fibs (tail fibs) -- Two ways to get the 200th number, then f200 = fib 200 -- !! is the list indexing operator f200' = fibs !! 200```

As it happens, the infinite list version is appreciably faster. This is an good example that demonstrates the power of Haskell's lazy evaluation (which is impossible in traditional impure languages), in which expressions are only evaluated when their values are needed. The Fibonacci sequence is potentially infinite, but the machine will only compute the values that you need.

You might like D, but it's pretty similar to C++.

I think plain C is an excellent language when you want to work close to the metal- it's worth the additional effort to abstract things up cleanly in C in order to achieve good performance. For applications where you are less concerned with absolute performance and want safety, that's exactly what languages like C#, Python and Java are for.
Tari wrote:

Code:
```-- Type signature (may be omitted, but helps clarity) fib :: Integer -> Integer      -- Explicit recursive function to get the nth number      fib 1 = 1      fib 2 = 1      fib n = fib (n - 1) + fib (n - 2)      -- Define it as an infinite list instead      fibs :: [Integer]      fibs = 1 : 1 : zipWith (+) fibs (tail fibs)       -- Two ways to get the 200th number, then f200 = fib 200 -- !! is the list indexing operator f200' = fibs !! 200```

As I understand it, that would be how it would be indented. Correct? It seems pretty different from Java, but it's for a different purpose, too. I think it looks worth a shot. Thanks.
Declarative languages are quite hard to find, probably because in the end most don't execute code! (See this Wikipedia Category)

My take on "declarative languages" is XML, pretty much. XML in modern programming is typically used to hold data or define GUIs. SQL is also declarative where you specify a pattern for the server to find (queries). Java itself is not declarative (it's OOP), but you might be referring to JavaFX, which is declarative.

For you, I think the best path to take is to learn C++. It seems to be the most direct path from Java, since they are both OOP and contain similar syntax. I would recommend dabbling in C first to get familiar with the low-level stuff, then step it up higher to C++. (C is procederal)

Once you've gotten C++ down, you have a variety of libraries to use! There's SDL/OpenGL for games; wxWidgets, Qt, or GTK (GTK is C, but GTKmm is a C++ binding for GTK) for GUI creation (all are cross-platform, but the last one sucks at it); and a few other great libraries ready for use! If you are thirsty for declarative programming, QML is a declarative language for GUI specification for Qt. GtkBuilder is also a declarative language... also for GUI specification, this time for GTK. They both integrate into their C++ libraries nicely, and combine to become a whole project.
I say you should start with C; it's a lot cleaner (IMO) than C++ is, and has a lot of libraries for it, such as SDL and SFML. I think Tari's notion towards Haskell is a decent one as well; is sounds like an obscure language, but it is very cool and also has many libraries for it (it even has SDL bindings -- and the bindings are very haskell-oriented). However, learning it straight from Java will be a lot harder than from learning C.

Regarding your new indentations to Tari's Haskell code, they are actually not correct they would work, (I think? I know Haskell is pretty lenient with spacing in some senses, and that it matters more with blocking action structures and the such) but it would be messy code and it isn't how it's supposed to be done. The different lines like "fib 1 = 1" are actually declaring an input -> output prototype for the same fib function, in a sense like a piece-wise function in Algebra.
C++
C#
Python

so essentially you want to rule out some of the best and most popular languages? I would suggest C# because it is very similar to java syntax-wise...
C# isn't as Microsoft-centric as you might think, it's actually a very nice language that's fun to play with. It's cross-platform too, with Mono, and its syntax is extremely similar to Java.
Meh, I see .NET and I think Microsoft proprietary sh**. Tell me more about this C#. (Code examples, et cetera).
Well, let's just say that it is a great language for a varity of applications. I really insist you try it first, you might really like it.

if you do consider, you will need Visual C# Express (google for it) in order for making certain applications, such as Windows Form Applications, much easier to make.

and now for an example of basic I/O.

http://pastebin.com/b6v8ChkZ
For the record, you can compile Java to native machine code. I do so for some of my own Java programs. I use the gcj "ahead-of-time" compiler for that. You can compile class files, jar files, or Java source code files.
qazz42 wrote:

Code:
```     using System;  //So like "import java.lang.*" except different?           class test {             public static void Main(string[] args) {                   Console.WriteLine("Enter your name ");  //Where'd this console come from?                                         string request;                     request = Console.ReadLine();  //Why does this go on two lines?             if(request == "") {                           Console.WriteLine("I said to enter your name");                     Environment.Exit(0);  //Environment?     }             Console.WriteLine("Hello " + request + " howz you?");     }     } ```

seana11 wrote:
Meh, I see .NET and I think Microsoft proprietary sh**. Tell me more about this C#. (Code examples, et cetera).
I think since you're already a Java programmer, it's worth reading the Comparison of C Sharp and Java article of Wikipedia. The syntax is similar enough to Java that it's not really worth giving you any large code samples. I guess something that is nice is C# is that it has lambdas, so, for example, you can do this to print the numbers 1 to 100:

Code:
```var a = new List<int>(Enumerable.Range(1, 100)); a.ForEach(i => Console.WriteLine(i));```

With LINQ you get lots of fun functional-type programming features. It's really quite nice. I suggest giving it a try. If you really want some more examples, you can check out my Directory to HTML project, which is pretty straightforward; you can ask for something specific, and I can write you up some code; or you can check online, there are tons of tutorials and code samples available.

Here is a page by Microsoft that has some Java and C# code side-by-side. And here has some other stuff.
Environment and Console are both classes of the System namespace (which is called into scope using the "using" statement at the beginning) this makes it so we don't have to keep on typing System.Console.WriteLine or System. Environment.Exit. MSDN is a great resource for a varity of these classes and methods.

and as for the Console.ReadLine question, I made that program when I was just starting out and didn't think to do "string request = Console.ReadLine();" <==== that works too...
qazz42 wrote:
Environment and Console are both classes of the System namespace (which is called into scope using the "using" statement at the beginning) this makes it so we don't have to keep on typing System.Console.WriteLine or System. Environment.Exit. MSDN is a great resource for a varity of these classes and methods.

and as for the Console.ReadLine question, I made that program when I was just starting out and didn't think to do "string request = Console.ReadLine();" <==== that works too...

So this is more like "java.lang.system.out.println" vs. "system.console.writeline"
yep, pretty much. just remember that the using statements at the begining only work with namespaces, so no cheating with "using System.Console;" or something

(not exactly how it works in java..)
Neither C# nor Python compile to machine code, so why did you feel the need to exclude them when they didn't qualify in the first place?

Regardless, if you intend to learn a language that can actually be used in complex applications AND is fast AND has a decent set of libraries, your options are:

C++

And, uh, that's about it, as it turns out. Since you excluded C++, that basically leaves you with nothing.

If you just want to screw around, Haskell, C, and D are all interesting options. But if you are considering learning a language just to mess around and want something Java-like, give Go a look ( http://golang.org ). Pretty much all the fun stuff you'd expect from a modern language (like garbage collection) and it compiles to machine code.

With all that said, though, not compiling to machine code is *far* from Java's weakness. Heck, that wouldn't even help Java's performance much. Java's real weakness is its incredibly stupid syntax combined with terrible usage of memory which is a huge reason for its slowness. Consider something like Scala instead, which gives you plenty of reasons to pay the cost of the JVM and then some.
Did I ask for a rant? No. (Well, depends on how you see it) Did I expect one? Yes. Did it change my mind? No.

I wrote:
Right off the bat, there are a few languages that are disqualified (plus a few I don't like):

So, no, C# should be on the list, and yes, python shouldn't.
Languages to screw around in: Scheme/Lisp, SmallTalk, and Haskell. Languages that you could actually do something in: C++, Python, C#. Since you pretty much excluded the ones that I see you could work in, you might be interested in trying the ones for playing in. C# would probably be your best bet at having a Java-like syntax. Also, Go is nice, though some of the syntax is interesting (For instance, using parenthesis in places C-like languages would use curly brackets).

Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

»
» All times are UTC - 5 Hours

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum