Language to replace C

A

Antti =?iso-8859-1?Q?Syk=E4ri?=

Quite a lot of languages have been named "D", but as far as I know none has
caught on to any extent.
C++ already provides OO and, with the standard template library, garbage
collection, and has facilities to link C functions, and it is a
well-established language. "D" doubtless implements things much better, but
the advantage would have to absolutely overwhelming (or you would have to
have the marketing muscle of a big company behind you) to have any hope of
dislpacing C++ as language of choice.

D has the advantage of the having most of the advantages of C++ but not
too many of its weaknesses. In addition, it has features that make
programming just so comfortable that having to switch back to C++ makes
me cringe.

This has made D *my* language of choice when picking a language for my
hobby projects, and I don't find it at all unlikely if other people
eventually arrive at the same decision.

While D is not perfect (it's still in development and is still missing a
good part of its standard library) it's one of the best there is.

In summary, there is a gap between "good old" languages (C and C++) and
"fancy new" languages (Java and C#). The former are simple, fast, and,
to a certain degree, crude; are compiled to machine code; and have C
linkage. The latter are designed by large corporations, for large
corporations; have nice features that boost productivity; are run on a
virtual machine; and, therefore, can be perceived as having a certain
overhead.

D aims to fill that gap, and I hope it succeeds.

-Antti
 
J

James Harris

Michael Nahas said:
Antti & all interested,

The draft description of my language to replace C is available at:

http://nahas.is-a-geek.com/~mike/MyC.pdf


I am a long time C programmer (I read the old testament in 1987) and
I've tried to keep the spirit of C and make as few changes as possible.
I was mostly driven by the bloat of C++ and, now, C99. I was also
driven by the gcc extensions, which provide needed features that aren't
present in ANSI C.
(http://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html)


The things people will most hate are:
1) new keywords (fun, var)
2) changed type declarations
3) changed variable and function declarations
3) @ as the array operator, instead of []

The things people will most love are
1) multiple return values made easy
2) function pointers easier to declare and read
3) exact specifications of types
4) no forward declarations


This language doesn't add any power over C because it is designed to be
able to link to C files. It is just trying to do what C does with a
better type system and a better syntax for some things.

I know I am going to get flamed for this. I'd appreciate it if replies
contained constructive comments ("I'd rather have seen ...") rather than
destructive comments ("What you have sucks!"). Second, make sure to
mention what you like about it (if there is anything) rather than only
things that you hate. Lastly, if you think it violates the spirit of C
(a valid complaint in my mind), then try to state as clearly as you can
the principle that C embodies and then an example of how my language
violates it. E.g., "C uses minimal keywords. Your language has two new
keywords, 'fun' and 'var', all over the place."

As a final note, I have not written a replacement for the C
pre-processor yet. It's affect on C is much stronger than many people
believe. I have a few ideas floating around, but nothing solid yet.
Some involve using the [] symbols, which I would like to use for
polymorphic types, similar to C++'s templates. (Which use < and >, the
ugliest thing in C++.)

Let the flames begin...
Mike




For Torben:
I agree with most of your suggestions, but I didn't think that this
was the language for all of them. I wanted a language that was
linkable with C and didn't require anything else. I basically
wanted C with a clearer type system and a nicer interface to a few
features. Thunks, overloading, and polymorphism didn't fit.
(Although, polymorphism may come through type macros.) After I
finish the design of this language and write a compiler, I'm going
to look at designing a higher-level language. I've come to like
OCaml, but dislike a few hickups (naming especially) and it's
syntax. I think there could be a market for a type-safe language
that could easily link to C and use a conservative garbage
collector.

Mike



Subject: Re: a language to write an OS with ???
From: (e-mail address removed) (Torben Ægidius Mogensen)
Newsgroups: comp.lang.misc

Nowadays it's all too common for language designers to design high
level, garbage-collected, object-oriented, bigger-is-better like
languages (witness C++ since addition of multiple inheritance and
exception specifications, Java, C#, and now D). To strive for an
efficient, clean, and "light-weight" language -- a language that would
be just appropriate to create a modern operating system in -- doesn't
seem to be very fashionable.

I wouldn't say that there is less interest in designing such
languages, I would rater say that the "market" for such languages is
more entrenched than for higher-level languages, especially scripting
languages. One reason may be that an OS is a major undertaking and
likely to be in use for a long time. So OS writers want a language
that they know will be around for a long while and which will be
ported to a large range of platforms (allowing their OS to do the
same).
My own hobby language is about creating a better C/C++, with cleaner
syntax, more extensibility, more transparency, better metaprogramming
facilities and ultimately, the ability to go as close to the hardware
as possible when needed. (Yes, it's likely to be a long road.)

In essence, it's about taking C and evolving it in the same direction
as C++ did, emphasizing the "what you don't use, you don't pay for"
rule and paying less attention to backwards compatibility.

In designing a C replacement, I wouldn't start from C. Even without
the C++ additions etc., C is a horrible language, with highly
complicated and somewhat ambiguous syntax, underspecified semantics
and lacking in features necessary for OS writing (such as jumping
through a pointer).

What I would do was (among other things):

- Have well-defined syntax and semantics.

- Ensure that the sizes of all types are specified by the language,
so it would, e.g., be explicit if an integer or pointer is 32 or 64
bits long. Memory layout would also be explicit, so big-endian or
little-endian numbers and strings would have explicitly different
types (and both would be present).

- Make it explicit in the type of a pointer if it can be null.

- Make it explicit in the type of a value if it can be modified after
creation and initialization. Integrate creation and
initialization.

- Allow pointer-arithmetic only on pointers to arrays. Doing it on
other pointers should give type errors. You can have fields
offsets and such, and they can even be negative (a record/struct
pointer type can specify to which field the pointer points). Allow
all/several components of a record to be accessed at once, using a
kind of pattern-matching.

- Have no implicit casts, even between integer sizes.

- Have parametric polymorphism, implemented by
replication/specialization.

- Overloading via (Haskell-style) type classes, not by ad-hoc
overloading or OO-style virtual methods.

- Have type-safe closures/thunks.

- Allow programmer to specify pointer to address at which a record,
array or other structure is built. Issue compile-time warning if
the type of the pointer does not ensure sufficient space.

- Allow compile-time warnings to be supressed individually, but not
en-masse. I.e., when the programmer gets a warning, he can check
if there really is a problem, and if not insert an assertion at the
relevant place in the code to supress the warning.

- Drop macros and instead require the compiler to inline definitions
that are marked as such.

Torben
 
J

James Harris

Michael Nahas said:
What I would do was (among other things):

- Have well-defined syntax and semantics.

- Ensure that the sizes of all types are specified by the language,
so it would, e.g., be explicit if an integer or pointer is 32 or 64
bits long. Memory layout would also be explicit, so big-endian or
little-endian numbers and strings would have explicitly different
types (and both would be present).

I'm curious as to how you would handle these explicitly defined integers on a 36-bit
machine with 9-bit bytes as I'm having to deal with these questions myself. Explicit is
good in being repeatable but it is not necessarily fast. ANSI C defines arithmetic and
logical operations on integers and explicitly allows some operations to be implementation
defined. In other words all C integer operations are fast, most are the same on all
architectures (eg shifting a small positive integer), and some are to be avoided on
transportable code - at least within defined parameters.

What would you do on machines using 1's complement representation? You could put tests
around the code manipulating these but that would result in a performance hit. C avoids
this by calling shifts and suchlike on negative integers implementation defined. Have you
a fast way to avoid all such uncertainties? (To quote K&R C 2nd Ed sec 2.9, "Right
shifting a signed quantity will fill with sign bits ... on some machines and with 0-bits
.... on others.")

Also, would not explicitly stating whether an integer is to be stored as little-endian or
big-endian cause a massive performance hit on a machine for which that was not the native
format, eg. PowerPC supports both, IIRC, but Intel doesn't support big-endian. I think the
PDP architecture uses a mixed-endian representation of 4-byte ints.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,216
Latest member
topweb3twitterchannels

Latest Threads

Top