views:

671

answers:

15

I've been learning C: it's a beautiful, well-thought-out language. However, it is so low-level that writing any sort of major project becomes tedious.

What higher-level language has the most C-like syntax—but without all the clutter that you find in something like C++. Does one exist?

+3  A: 

Probably Java and C#... Java a little more so I think.

And it's not the language - it's all about the libraries. Try out Qt (http://qt.nokia.com/). It's for C++ and I know you said C but I'm just making a point that you'll find yourself writing just as little (and perhaps even less!) code than you'd write for applications in Java or C#. Plus they're native and cross-platform.

All about the libraries.

Jake Petroules
+1 If you're used to C99, Java code at least looks nearly the same.
Helper Method
Yes, as do many naming conventions (minus Hungarian I guess).
Jake Petroules
I guess this really exercises what we mean by "like C." :)
BobbyShaftoe
+3  A: 

This is too broad a question and is best made Community wiki.

However, in my mind, the main distinguishing feature of C is it's compactness. The whole language can be described in a small book like K&R. One can remember all the syntactic details without much effort (since there are so few of them) and it doesn't try to protect it's users from themselves.

Languages like C++ are much more baroque. It's quite hard to remember all the rules and exceptions. I feel the same way about Perl and Ruby. There are lots of things to remember and lots of things to watch out for.

I feel the same sense of compactness with Python (although perhaps not as much as C). There's very little "special syntax" and all libraries and modules are operated upon in a similar fashion.

This (probably like most other comments on this question) is a personal evaluation and is by no means a final word.

Noufal Ibrahim
More things to remember - yes. More things to watch out for? Hmmm...
Konerak
Well, I distinguish between programming errors (segfaults etc.) and between rules the langauges impose that you might trip over. C is quite consistent with it's language rules.
Noufal Ibrahim
+6  A: 

D

Ignacio Vazquez-Abrams
+1 for conciseness
liori
D looks good—do you know of any major applications that use it?
aharon
I have not heard of any.
Ignacio Vazquez-Abrams
+9  A: 

Google's Go language has a similar syntax (though different enough I suppose) and semantics, though with garbage collection, polymorphism, etc., built into the language.

jer
Go looks awesome, I'm trying it out.
aharon
+1  A: 

This comparison of basic instructions gives you a good idea of what languages are similar to each other.

I would say PHP is most like C except for the $variables, if you can distinguish php the language from php the platform. Java tries in some ways, but is too strongly object oriented to be similar to C.

drawnonward
Maybe PHP is a bit _too_ highlevel, what with its lose typing.
aharon
A: 

I'd vote C#. I don't know what you mean by "clutter," but from a usability standpoint, C# is nice because it avoids some of the tedious things of C++, like having to essentially "declare" each of your class's methods twice (prototyping it in the header file, then essentially duplicating the same thing in your class's implementation). Ditching header files was nice in other ways too, like doing away with dependency conflicts in big projects or avoiding circular references. In C#, the compiler takes care of all that (although you still have to set references to other files or assemblies).

I've been doing C# for 10 years and I still miss pointers, which believe it or not, in my opinion, actually made debugging easier!

electromaggot
I don't believe it! (OK, I accept that it is your opinion ... just not that it is objectively correct ... :-) )
Stephen C
But C# *does* have pointers. (http://msdn.microsoft.com/en-us/library/y31yhkeb.aspx)
Clifford
The claim about pointers originated in Java, and it's garbage. A reference in Java/C# *is* a pointer. Just because it's hidden and doesn't support pointer arithmetic, doesn't mean it isn't a pointer. As for "declaring twice" - well, you could say the same about a book that duplicates all it's chapter and section titles on the contents page. Sadly, C++ doesn't fully separate the interface description and implementation, but at least it tries. And of course C# has the same thing in another form - you duplicate the method description in both the interface and in the class that implements it.
Steve314
A: 

If you're going to be programming often, it's good to know languages that are explicitly not like each other. It's especially useful to know high level scripting languages like python or ruby. If you can think like a programmer in C you should be fine learning either of these two. Many big projects take advantage of the rapid prototyping of higher level languages like python or ruby, but also take advantage of low overhead (fast) compiled languages like C/C++.

mangledorf
I already know Ruby—but I learned C and think, from an aesthetic point of view, is much nicer. (Odd, I know.)
aharon
A: 

hi guys... how about actionscript 3? .... its alot like java ......

james
Really? I thought it would be a lot like ECMAScript. Oh wait, it *is* ECMAScript.
Ignacio Vazquez-Abrams
action script (1,2,3 whatever) is ECMAScript? Then JavaScript is ECMAScript which is actionscript and so JavaScript is actionscript? I daresay a lot of the actionscript code can't run unmodified as JavaScript/ECMAScript, so it is something different; maybe just a bit, but nonetheless it is not fully ECMAScript-compliant
ShinTakezou
ECMAScript and JavaScript are always effectively non-standard, since when you move from one host application to another, the object model that you primarily work with is inherently different. True, you can (in principle) take your JavaScript from one browser to another, but you can't really take it with you to Photoshop for example.
Steve314
Isn't actionscript just used for flash?
aharon
yes it is used for flash. and please forgive me. its not like java but more like javascript. my bad! .. :p
james
+4  A: 

I've been learning C: it's a beautiful, well-thought-out language. However, it is so low-level that writing any sort of major project becomes tedious.

Some people would say that the second sentence proves that the assertion of the first sentence is false.

Another point is that this is pretty much unanswerable. What is a "high level" language? what are your criteria for "closeness"? Syntax, computational model, performance? And what kind of applications are you wanting to build with this hypothetical language?

And if you just want to confine yourself to languages that "look like" C, why? As someone who has lost count of the number of programming languages he has used, I can tell you that differences in programming language syntax are generally pretty unimportant. You can get used to pretty much any syntax, given time.

Stephen C
+7  A: 

The D programming language is an attempt to be what C++ should have been (not bashing on C++ at all it is my primary language) and I quote from the website, "D is a systems programming language. Its focus is on combining the power and high performance of C and C++ with the programmer productivity of modern languages like Ruby and Python. Special attention is given to the needs of quality assurance, documentation, management, portability and reliability. " The issue with D is it is relatively new compared to a lot of languages but luckily it can still use C libraries which allows it to access a large pre-existing code base. Certainly worth checking out.

Java is another option however it is notably slower than C. Syntactically it is very similar and offers a nice object orientated environment for writing code. It is also considered by most to be a safer language than C and C++. It is widely used in enterprise.

Python while syntactically not like C is a high level Object Orientated Programming Language that is very popular and can import C modules which may be very useful down the track.

Dejai
Python is very like C in spirit. The basic modules are thin shims over the OS-provided . Python trusts the programmer and gives ample amount of rope to hang yourself with. (Really!)
kaizer.se
D looks good—after I learn some Go I'll have a go at it :)
aharon
+11  A: 

In C++ you can write C code and have it compile successfully as C++ (mostly). Therefore, although I suggest that your term "clutter" is both derogatory and ambiguous, the only clutter you will have is what you choose to write yourself. You can use C++ as a bigger tool-bag without using all the tools (or clutter if you prefer).

The answer therefore is C++ whether you like it or not. Most other C-like languages add OO features, which is perhaps what you regard as clutter, but you do not get something for nothing and you need to have syntax to support the additional features. Such languages include:

  • Java
  • C#
  • Objective-C
  • D

Of these Objective-C is probably the most C-Like since it is a superset of C in the way that C++ is not quite. It is also the preferred language for OSX and iPhone/iPod Touch development, which may be attractive.

Java is ubiquitous but probably best described as superficially C-like. C# has limited cross-platform support but is the path of least resistance for Windows GUI development with excellent free development tools. C# also has a simpler but more restrictive OO implementation than C++ so may meet your requirements, but its resemblance to C/C++ can be misleading; it is fundamentally different in how it works in a similar manner to Java. D is somewhat of a niche, being developed by a single author (albeit the author of the once renowned Zortech/Symantec C++ compiler).

Regarding it being "low level" and "tedious", when embarking on a "major project", you would seldom start from scratch with only the standard library and OS API available, you would make use of third-party and in-house developed libraries to quickly develop higher level functionality. That said, an OO approach is generally much more amenable to this 'code-reuse' approach, and of course C++'s standard library and third-party libraries are more extensive (not least because it can use C libraries as well as C++ libraries). In fact I would suggest that apart form support for OO, the only thing that makes C++ higher-level is its extensibility via classes as first-class objects. It remains suitable as a systems-level language nonetheless.

Clifford
I don't understand. You claim that the basis for the answer is that you can use the language "as a bigger tool-bag without using all the tools (or clutter)", but then say that the answer is C++. Why isn't Objective C, being an actual superset of C, a more appropriate answer given this criteria?
Ken
@Ken: It could be, but Objective-C is less well supported cross-platform, and less widely used in general, so help, support, and reference material are not so ubiquotous. It is however a good answer for OSX and iPhone development.
Clifford
C# myth number 1: "C# has limited cross-platform support". http://www.mono-project.com/Main_Page
Callum Rogers
@Callum Rogers: Mono's .Net Framework support is certainly more comprehensive that last I looked, but not 100%. Probably good enough for my statement to be untrue however. I realise that C# and .NET framework are separate, but not much C# code is written that does not use the .NET framework.
Clifford
+1  A: 

Javascript has a reasonably C-like syntax, and it's a very popular language. Javascript has a lot of quirks, but it has one powerful similarity to C - it's simple. The complete Javascript specification is very short, and the language is very powerful and high-level. It would be great to clean it up from some of its ugly cruft, though.

Eli Bendersky
+1  A: 

I'll just point out that Pascal is semantically (though not so much syntactically) very similar to C, so there are options like Object Pascal, Modula 2, Ada and Oberon out there where you will be re-using most of the non-trivial part of what you already know, the trivial part being the spelling.

You're probably better off sticking with C# or Java in terms of job prospects, though.

EDIT

I'll also add that on the clutter issue, it is important to sort out which clutter is important. C has less "clutter" in it's language definition, true, but the relevant clutter is in source code. Consider the following...

//  C
struct mystruct *myvar;
myvar = (struct mystruct *) malloc (sizeof (struct mystruct));
myvar->a = 1;
myvar->b = 2;
myvar->c = 3;
call_something (myvar);
free (myvar);

//  C++
auto_ptr<mystruct> myvar (new myclass (1, 2, 3));
call_something (myvar);

The point is that the "clutter" in the language definition is there for a reason. With a little up-front work when writing libraries, a lot of work (and clutter) is avoided down the line. And even when you're writing a library, you benefit from the up-front work done by other library writers.

Steve314
First 5 lines of C example can be compacted into one line `mystruct_t myvar = mystruct_new (1,2,3);` of well written code. Conversely, badly-written C++ code can be much longer.
el.pescado
@el.pascado - you assume there's a "typedef struct", and you've missed the pointer use. Though true - a constructor is really just a function, and the typedef struct is just another form of up-front work to save clutter later. One point about that initialisation function, though, is that it'll have to do the work of the top five lines of my example anyway - not just the three member assignments. Theres still extra clutter in C - though it doesn't always have to impact the high-level library-using programmer.
Steve314
@el.pascado - actually, I had intended to say something to the effect of "a call is just a call in any language - the minor syntax differences are unimportant and even implicit dispatch mechanisms could have been implemented using an explicit dispatch-decision-making function. I don't remember whether it was this question or not, but I dropped it due to comment-length issues anyway.
Steve314
A: 

If you think that C++ is cluttered, then you just don't know how to write effective C++, because nobody forces you to use any of the advanced tools available. You could write a C++ program entirely in C plus your favourite C++ feature (like the AWESOME standard library). That's the definition of uncluttered. A cluttered language would be Java/C#, where you HAVE to put every function in a class. That's clutter.

DeadMG
It's not really the issue, but I disagree that the C++ standard library is "awesome". Take the containers. They're neither one thing nor the other. As abstractions, they are incredibly leaky, and the use of iterators is fragile. As data structure libraries, they're inflexible, hiding internals and preventing effective extension. On the whole they're usually OK - for example if iterators are always manipulated using standard library algorithms or using well known robust idioms, you won't care about the fragility, since it won't affect you. But still, I wouldn't say "awesome".
Steve314
@Steve314: You mean, as data structure libraries, they offer a great range of different complexities for different operations and different type requirements, and are extremely easy to use and incredibly fast? Or how you can extend the STL with any iterator interface, taking great use of STL-provided algorithms like sort?
DeadMG
@DeadMG - I said they're OK, but then, as data structure libraries, consider std::map. According to this standard, it's not a red-black balanced binary tree, it's an abstract key->data mapping. Still, we all know what it is in practice, and sometimes rely on that fact due to the leakiness of the abstraction. So, it shouldn't be hard to benefit from the library, but add extra summaries to each node - e.g. to allow log n time subscripting. In typical C binary tree libraries, this isn't a big deal. In the C++ standard library it's impossible.
Steve314
I've written a container library of my own. It is generally easier to use than the STL containers. The "iterators" (I call them cursors) are never invalidated by inserts or deletes, and always carry on pointing to the same item, even if it has moved in memory. And a lot of the time it outpaces the STL since it uses more cache-friendly data structures (that you don't need to know about) than the STL. It already supports efficient subscripting using additional per-node summaries, and since the data structure is a separate layer from the front-end abstract data type, you can extend it.
Steve314
I am not claiming that my library is superior to the standard library containers. It has its own disadvantages as well as advantages. If you aren't doing much sequential access, and are doing lots of inserts and deletes, the "cursor maintenance" can be a significant overhead, for instance. The point is simply that there is no reason to be in awe of the C++ standard library. It is not a work of the Gods. If you assume it is perfect in every way, you'll be in denial when you need something different. If everyone was like that, well - there'd be no Boost intrusive containers for a start.
Steve314
+6  A: 

What higher-level language has the most C-like syntax—but without all the clutter that you find in something like C++?

I'm going to answer a slightly different question:

What is a language that is like C in that it is well designed and beautifully thought out, is like C in that it is good for systems programming, allows people to program at a higher level than C, and is relatively uncluttered?

I don't think this question has a single right answer, but here are three worthy candidates (in alphabetical order):

  • D. The D language is designed essentially as a better, cleaner C++. Like C++, D is explicitly designed to incorporate a lot of features, but one hopes in a cleaner, more harmonious way than C++. A major difference that enables programmers to work at a higher level is that memory is managed automatically by the language and safety is guaranteed by the compiler (and run-time system) through garbage collection.

  • Go. Go scores very high on being well designed and beautifully thought out: Rob Pike is a master designer and has been practicing this particular craft for 25 years. Its explicit goal is to be uncluttered and to make systems programming "fun again". Go is still a new language, and Rob has learned much from Squeak, Newsqueak, Alef, and Limbo. Because Rob understands that a great design is one with no unnecessary parts, Go is clean and uncluttered. Its primary features that are higher-level than C are type safety, garbage collection, and an excellent concurrency model.

  • Java. Java has a well-designed core (see Jim Waldo's book Java: The Good Parts) but unfortunately suffers from the clutter that any mature, successful language accumulates. The features of Java that make it most suitable for higher-level programming are interfaces, garbage collection, and exceptions.

The common thread here is using garbage collection to relieve the programmer of the burden of memory management. This is a major boost to productivity.

Each of these languages has much to recommend it. My own taste is for languages that are small and simple, and I admire Rob Pike's body of work very highly, so if I had to pick one for myself, it would be Go, despite the fact that it is new and unproven.

Norman Ramsey
The biggest advantage of Java – and frankly the biggest problem too – is the sheer number of libraries available for it that do *very* interesting things. This is good because it means that there's usually something to help you do what you want, and this is bad because finding the right library (and learning to use it, though that's not strictly a Java problem of course) can be really hard.
Donal Fellows
I'm trying out Go, it looks very interesting—D looks good too. Thanks :)
aharon
@Donal: Welcome to the Reusability Curse: "Hi. I'm Santa Clause, and I have 1 billion components in my bag, and you can have any one of them. Go ahead and choose."
Ira Baxter
Java also has the issue of being at too high a level in some ways and too low in others, it's not consistent about where it it is.
Spudd86
s/Java/C# ... :)
RCIX
@RCIX aren't Java and C# basically the same? <puts on asbsestos suit>
Norman Ramsey
Nope, java is a cheap knockoff that came before :) java has all sorts of weird rules and kludged together solutions (see Java generics)
RCIX