Why not develop new language

I

Ioannis Vranos

Howard said:
Yes. The "try...finally" construct comes to mind. While we have RAII in
C++, which *may* be better, I've used the same try..finally construct
extensively in Delphi (Pascal), and found it quite useful. C++ has no such
construct. (I'm not saying it should, mind you, just answering your
question. :))




I do not know what you mean by try-finally exactly, but if you are
referring to Dispose definition, this is automatically generated by the
compiler in C++/CLI.






Regards,

Ioannis Vranos

http://www23.brinkster.com/noicys
 
I

Ioannis Vranos

Prashant said:
There are lot of dicussion on C# is much better than C++. Why there is
no language to compute C#. This way we are accepting monopoly of M$.
Why there is no group which seriously tring to develop new language
better than C#.


OK, lets shed light on this.


C# has of course less abilities than C++ under paradigm view. Also C#
has not a standard library of its own.


Also about .NET in particular here is some information.

CLI is an official standard describing a multilingual VM environment
with an API. .NET is a CLI compliant machine and there is also the
C#/CLI standard which describes C# in relevance to CLI there is not a
separate C# standard).


There is an upcoming C++/CLI standard (currently draft, official
document expected in December 2004) - and also an upcoming C#/CLI 2
standard.

C++/CLI is more powerful than C#/CLI (including the upcoming C#/CLI one).

The design ideals of C++/CLI are the following:

1) Bring C++ abilities to CLI.
2) Bring CLI additional features to C++.
3) Leave no room for a lower level language in CLI (*including IL*).


Some of the abilities provided by C++/CLI:

Reference objects with stack semantics , deterministic finalisation.

Templates used with reference objects (and producing 100% IL code).

Generics support. Generics are created at run-time while templates at
compile-time. Ability to use generics and templates in combination (e.g.
templates having a generic interface and vice versa).

Ability to pin objects so as to not be moved by the garbage collector
and converted to regular pointers.

No Dispose definition. Dispose is automatically created by the compiler.

C++: Right by default. Other languages (including C#): right by explicit
coding.


MS says that on average, C++ pure IL code is 25% faster than C#. Except
of this, now being MS specific, VC++ supports heavy optimisations not
available on VC# including the upcoming POGO optimisations (real-use
optimisation) + some other crazy stuff that I saw in a video yesterday
something like:


#pragma openmp for
for(int i=0; i<whatever;++i)
// ...


which is facilities supported from openmp: http://www.openmp.org.

The above has as a result, (in addition to the usual .NET
multi-threading facilities) to execute the loop in a separate optimised
thread).




And many others:

I have created a page explaining some of these:

http://www23.brinkster.com/noicys/cppcli.htm



And Microsoft references (be sure to check these):

http://microsoft.sitestream.com/TechEd/DEV/DEV333_files/Botto_files/DEV333_Sutte.ppt

http://www.accu.org/conference/pres...Relevant_on_Modern_Environments_(keynote).pdf




Now you may kiss C# good bye.






Regards,

Ioannis Vranos

http://www23.brinkster.com/noicys
 
H

Howard

Ioannis Vranos said:
I do not know what you mean by try-finally exactly, but if you are
referring to Dispose definition, this is automatically generated by the
compiler in C++/CLI.

Nope, that's not it.

You know how we use try { } catch() {} in C++? Well, both Delphi and C#
(which was developed with the aid of one of Delphi's main original
developers) have another construct, which is "try {} finally {}". The idea
is that no matter what else takes place, no matter whether it's a return
statement or an exception or simply dropping on out of the try block
normally, the finally clause will ALWAYS be executed. (Short of an abnormal
program termination, I would suspect.) It might be used like this, for
example (if it were available in C++):

Resource* pRes = new Resource;
try
{
// use the allocated resource somehow
}
finally
{
delete pRes;
}

This makes sure that you release a resource, close a file, or whatever, when
you're done with it, no matter what happens in the meantime. It's been
argued here that RAII is a better approach, and I won't argue that point. I
will just say that the above construct is quite easy to use, and it's easy
to read and recognize what it's doing.

-Howard
 
M

Mike Wahler

Howard said:
Nope, that's not it.

You know how we use try { } catch() {} in C++? Well, both Delphi and C#
(which was developed with the aid of one of Delphi's main original
developers) have another construct, which is "try {} finally {}". The idea
is that no matter what else takes place, no matter whether it's a return
statement or an exception or simply dropping on out of the try block
normally, the finally clause will ALWAYS be executed. (Short of an abnormal
program termination, I would suspect.) It might be used like this, for
example (if it were available in C++):

Resource* pRes = new Resource;
try
{
// use the allocated resource somehow
}
finally
{
delete pRes;
}

This makes sure that you release a resource, close a file, or whatever, when
you're done with it, no matter what happens in the meantime. It's been
argued here that RAII is a better approach, and I won't argue that point. I
will just say that the above construct is quite easy to use, and it's easy
to read and recognize what it's doing.

C++ already has this, via destructors. When 'throw' causes
a scope to be exited, all automatic objects are destroyed, and
any destructors will run. ALWAYS. So just wrap that 'new' and
'delete' in a class, create an automatic object of that type,
and you have the same mechanism.

-Mike
 
S

Shailesh Humbad

Prashant said:
There are lot of dicussion on C# is much better than C++. Why there is
no language to compute C#. This way we are accepting monopoly of M$.
Why there is no group which seriously tring to develop new language
better than C#.

You're assuming that C# is 'better' than C++ and that C# is displacing
C++, both of which are arguable. I think people don't develop a full
C++ replacement because it is very, very hard to write such a language.

Let me offer my thoughts on what makes a language successful. Beyond
its capabilities and performance is the ease-of-use of its
documentation. The documentation needs to be indexed by keyword, and
the repository should contain the entire range of topics from "hello
world" up to advanced topics like multi-threading and parallel computing.

For example, the documentation for the scripting language PHP is
easily downloadable in half a dozen formats (and over a dozen
languages). Not only does it contain the entire PHP documentation
superbly organized and indexed, but it also contains the user comments
with tons of tips and sample code. Where is the similar documentation
for C++?

In my experience, the C++ documentation is highly fragmented. STL is
here, MFC is there, ATL is here, the FAQ is there, the language
reference is only in books, and you can't even get the specification
without paying a copyright fee. Proof of this fragmentation is the
fact that so many posts in this forum get shot down for being
off-topic. Why don't the people in this forum really concerned only
about the standard make a forum like comp.lang.c++.standard? Or do
they just enjoy lording over the newbies who moth into this ng? How
welcoming and inclusive C++ must feel to those starting off knowing
little about programming, posting their question on C++ in the
comp.lang.c++ forum, and being told to go away! That attitude should
cause more fear for C++ aficionados than silly C# by M$.

Anyway, that's besides the point. My observation is that the lack of
consolidated, easy-to-use documentation makes the hurdle for learning
C++ unnecessarily higher than it ought to be. It seems that C# and
other languages will make inroads to the extent that they can function
in place of C++ with a lower learning curve. Maybe the fact that so
many people use C++ despite this obstacle is a testament to how
powerful the language really is.

--Anywhere else, this is just my two cents, but special for here, it
is just my one cent.
 
J

Johan Nilsson

Jeff said:
"Johan Nilsson" <[email protected]> wrote in message

I admire the skill and courage of the people trying to port C# and
.Net to Linux, but strategically speaking, it only re-enforces
Microsoft's dominance. Even if the mono project got to the point of
100% compatibility, which would be an unprecedented feat, it would
only confirm that Microsoft has developed a really great system.

And if they have, what's wrong with confirming that? I won't trash a good
product just because of who came up with the idea, or the opposite way
around.
Everyone working on alternatives to M$ products would be better served
to develop something totally different from M$, and preferably
something better. Invent a new language. Or promote and polish some
other language like Python or Haskell.

<off-topic/>
This isn't meant as personal criticism, but each time I see someone use the
acronym "M$" or "windoze" that person loses a bit of credibility in my eyes
(equally applies to "lunix" etc). By using that kind of acronyms, people
clearly show that they have unnecessarily chosen one side and refuse to use
anything from the other "side", when all would benefit from taking the best
of both (or more) worlds.

Yes, I'm probably a bit biased as I mostly work in the Windows world, but I
do use open source software and also occasionally develop under linux as
well as VMS(sic). Even so, I try to keep an unbiased view on technology.
</off-topic>

Just my 0.02 EUR.

// Johan
 
P

Peter Koch Larsen

Howard said:
Yes. The "try...finally" construct comes to mind. While we have RAII in
C++, which *may* be better, I've used the same try..finally construct
extensively in Delphi (Pascal), and found it quite useful. C++ has no such
construct. (I'm not saying it should, mind you, just answering your
question. :))

-Howard

try finally is useless in C++ - I have never seen a valid usage of it (and i
have seen it used in a C++-dialect that supported finally).

But yes - it is something supported in C# for a good reason (no RAII).

/Peter
 
C

Casper B.

It has base class libraries, separated into 3 (Standard, Kernel &
Compact) CLI (Common Language Infrastructure) categories which have all
been submitted for standardization to the ECMA - C# Unleased (SAMS).

JAVA however, has no standard library which is why I hate it...
confusing, deprecated and inconsistant and NOT submitted to any standard
association (they tried with ISO but ISO did not accept SUN's restrictions).

/Casper
 
R

Rolf Magnus

Mike said:
C++ already has this, via destructors. When 'throw' causes
a scope to be exited, all automatic objects are destroyed, and
any destructors will run. ALWAYS. So just wrap that 'new' and
'delete' in a class,

Or use std::auto_ptr. RAII is the only place where it's really useful.
create an automatic object of that type, and you have the same mechanism.

I guess Howard knows that. See the marked line.
 
I

Ioannis Vranos

Casper said:
It has base class libraries, separated into 3 (Standard, Kernel &
Compact) CLI (Common Language Infrastructure) categories which have all
been submitted for standardization to the ECMA - C# Unleased (SAMS).



All libraries available to C# in every CLI platform are available to all
languages in the platform, and not to C# only. C# has not any library of
its own.






Regards,

Ioannis Vranos

http://www23.brinkster.com/noicys
 
I

Ioannis Vranos

Shailesh Humbad wrote:

For example, the documentation for the scripting language PHP is easily
downloadable in half a dozen formats (and over a dozen languages). Not
only does it contain the entire PHP documentation superbly organized and
indexed, but it also contains the user comments with tons of tips and
sample code. Where is the similar documentation for C++?


Is PHP standardised and not copyrighted, or does it belong to an individual?


In my experience, the C++ documentation is highly fragmented. STL is
here,


STL is a subset (the most part of the standard library).


MFC is there, ATL is here,


These are system extensions.




the FAQ is there, the language
reference is only in books, and you can't even get the specification
without paying a copyright fee. Proof of this fragmentation is the fact
that so many posts in this forum get shot down for being off-topic.


This happens because C++ is a general purpose programming language used
in many diverse fields and in all systems (from small embedded devices
to large mainframes and supercomputers).


We can't discuss all APIs and extensions in a newsgroup, but only the
language itself.

On the other hand, PHP is a special purpose language whose
implementation is probably written in C++. :)



Why
don't the people in this forum really concerned only about the standard
make a forum like comp.lang.c++.standard? Or do they just enjoy lording
over the newbies who moth into this ng? How welcoming and inclusive C++
must feel to those starting off knowing little about programming,
posting their question on C++ in the comp.lang.c++ forum, and being told
to go away!


Probably you miss the fact how widespread C++ is and how many third
party APIs and libraries exist out there.

Given that, there are other newsgroups for most of them out there (for
example MS VC++ .net newsgroups).



That attitude should cause more fear for C++ aficionados
than silly C# by M$.

Anyway, that's besides the point. My observation is that the lack of
consolidated, easy-to-use documentation makes the hurdle for learning
C++ unnecessarily higher than it ought to be. It seems that C# and
other languages will make inroads to the extent that they can function
in place of C++ with a lower learning curve. Maybe the fact that so
many people use C++ despite this obstacle is a testament to how powerful
the language really is.


Yes. Also one does not need to learn the whole C++ to write useful
applications. Also check this and especially the "silver bullet" stuff.
And consider what C# is becoming after the addition of generics etc:


http://www.itworld.com/AppDev/710/lw-02-stroustrup/page_1.html






Regards,

Ioannis Vranos

http://www23.brinkster.com/noicys
 
S

Stewart Gordon

tom_usenet said:
Right. Did you misread "similar" as "superior"?

No. But I think I got a bit mixed up by the use of "compute", and to
some extent misread "C# is much better than C++" as "C#, which is much
better than C++".
For that matter, there is a freestanding C++ implementation (Managed
C++) that can be compiled to bytecode.

I'd've thought that any implementation could be compiled to just about
anything, given a suitable implementation to compile it with.
Yes, I suppose I should have said a "runtime efficient language".
That is, one designed with priniciples such as "what you don't use
you don't pay for" and where speed is not traded for safety at a
language feature level (although obviously libraries should be able
to make such design choices if they wish).

Are you allowing languages where trading of speed for safety at a
language feature level is a compile-time option, like D and (typically)
Fortran?
Basically, a language suitable for games programming and systems
programming as well as server and applications programming.

I doubt there are many languages out there in which a game has never
been written. But yes, that consideration makes sense.

Stewart.
 
H

Howard

Peter Koch Larsen said:
try finally is useless in C++ - I have never seen a valid usage of it (and i
have seen it used in a C++-dialect that supported finally).

But yes - it is something supported in C# for a good reason (no RAII).

I never suggested that C++ ought to have it! I merely answered the question
"Is there any C# construct that is not supported by C++?" Nothing was asked
about whether it *should* be supported by C++, and I specifically pointed
out the RAII method as our (possibly better) alternative.

As for a "valid" usage of it, what would be your criteria? I often used it
in Delphi, especially for making sure I closed handles, files, etc., which I
had opened and had to be sure to close. It's a heck of a lot quicker (and
more obvious, to me anyway) to simply say open..try..do
stuff..finally..close than to declare a new class instance to handle that
simple open/close pairing, especially when you need that "do stuff" part to
interact with *this* class.

But again, I'm NOT advocating its use in C++!!!

-Howard
 
I

Ioannis Vranos

Howard said:
I never suggested that C++ ought to have it! I merely answered the question
"Is there any C# construct that is not supported by C++?" Nothing was asked
about whether it *should* be supported by C++, and I specifically pointed
out the RAII method as our (possibly better) alternative.

As for a "valid" usage of it, what would be your criteria? I often used it
in Delphi, especially for making sure I closed handles, files, etc., which I
had opened and had to be sure to close. It's a heck of a lot quicker (and
more obvious, to me anyway) to simply say open..try..do
stuff..finally..close than to declare a new class instance to handle that
simple open/close pairing, especially when you need that "do stuff" part to
interact with *this* class.

But again, I'm NOT advocating its use in C++!!!


I need some more explanation for this feature. Lets assume we allocate
100 IP objects in the free store and when doing some stuff a "whatever"
exception is throw. How do you delete that memory using try-finally and
receiving the exception in the same or an outer block?



try
{
IPConn *IPConnArray=new IPConn;
// ...
// A whatever exception is thrown
}


finally
{
delete[] IPConnArray;
}

// Where "whatever is caught?






Regards,

Ioannis Vranos

http://www23.brinkster.com/noicys
 
S

Shailesh Humbad

Ioannis said:
Shailesh Humbad wrote:





Is PHP standardised and not copyrighted, or does it belong to an
individual?

According to the PHP site, the code is copyright to "The PHP Group",
so it doesn't belong to an individual. I don't think there is a PHP
standard in the sense of something ratified by an SSO (standards
setting organization). Also, PHP and most of its extensions are
written in C.
 
H

Howard

Ioannis Vranos said:
Howard said:
I never suggested that C++ ought to have it! I merely answered the question
"Is there any C# construct that is not supported by C++?" Nothing was asked
about whether it *should* be supported by C++, and I specifically pointed
out the RAII method as our (possibly better) alternative.

As for a "valid" usage of it, what would be your criteria? I often used it
in Delphi, especially for making sure I closed handles, files, etc., which I
had opened and had to be sure to close. It's a heck of a lot quicker (and
more obvious, to me anyway) to simply say open..try..do
stuff..finally..close than to declare a new class instance to handle that
simple open/close pairing, especially when you need that "do stuff" part to
interact with *this* class.

But again, I'm NOT advocating its use in C++!!!


I need some more explanation for this feature. Lets assume we allocate
100 IP objects in the free store and when doing some stuff a "whatever"
exception is throw. How do you delete that memory using try-finally and
receiving the exception in the same or an outer block?



try
{
IPConn *IPConnArray=new IPConn;
// ...
// A whatever exception is thrown
}


finally
{
delete[] IPConnArray;
}

// Where "whatever is caught?

I'm a bit confused about what you're trying to do. You use new, but later
delete[]. I'll assume you meant new IPConn[100]?

But it's important that you enter the try block AFTER acquiring your
resource, because you only want to call the delete (or whatever clean-up is
needed for the given case) if you've already succeeded in acquiring that
resource. (That's important for things like opening files, where opening
the file may fail. In that case, you only want to enter the try..finally
block if the file open succeeded.)

One thing that makes finally work with exceptions is that it will
automatically re-throw any exception that causes the finally to be entered.
So, here's an example of one way you might use finally as well as catch,
assuming you need to handle any exception thrown:

try
{
IPConn* IPConnArray = new IPConn[100];
try
{
for (i = 0; i < 100; ++i)
{
// do something with each item,
// possibly throwing at some point due to an error condition
}
}
finally
{
delete [] IPConnArray;
}
}
catch(...)
{
// handle exception
}

The exception will be caught in the finally block, which will delete the
array. Then that exception will be re-thrown, and caught in the outer catch
block. (If no exception were thrown, then the finally block would exit
normally instead of throwing.)

(BTW, If I recall, in Delphi, if the constructor throws an exception, its
destructor is called automatically, cleaning up any partially-created
objects.)

I've also had try..catch blocks *inside* the try clause of my try..finally,
in order to *decide* if an error needed propogating out at that point in
time, or if I just needed to log it or whatever.

-Howard
 
I

Ioannis Vranos

Howard said:
I'm a bit confused about what you're trying to do. You use new, but later
delete[]. I'll assume you meant new IPConn[100]?


Yes, my mistake. :)


But it's important that you enter the try block AFTER acquiring your
resource, because you only want to call the delete (or whatever clean-up is
needed for the given case) if you've already succeeded in acquiring that
resource. (That's important for things like opening files, where opening
the file may fail. In that case, you only want to enter the try..finally
block if the file open succeeded.)

One thing that makes finally work with exceptions is that it will
automatically re-throw any exception that causes the finally to be entered.
So, here's an example of one way you might use finally as well as catch,
assuming you need to handle any exception thrown:

try
{
IPConn* IPConnArray = new IPConn[100];
try
{
for (i = 0; i < 100; ++i)
{
// do something with each item,
// possibly throwing at some point due to an error condition
}
}
finally
{
delete [] IPConnArray;
}
}
catch(...)
{
// handle exception
}

The exception will be caught in the finally block, which will delete the
array. Then that exception will be re-thrown, and caught in the outer catch
block. (If no exception were thrown, then the finally block would exit
normally instead of throwing.)


Yes, OK I understand, however in C++the best way would be to use
vector<IPConn> instead of the explicit array on the free store, which
cleans up itself automatically when an exception is thrown (RAII).



(BTW, If I recall, in Delphi, if the constructor throws an exception, its
destructor is called automatically, cleaning up any partially-created
objects.)



This is the case of C++ too.


I've also had try..catch blocks *inside* the try clause of my try..finally,
in order to *decide* if an error needed propogating out at that point in
time, or if I just needed to log it or whatever.



Well try-finally is not a badly needed feature and essentially is not
part of any paradigm in particular (for example OO).


Also check one of the links I provided in another message, especially
the PDF:

http://www.accu.org/conference/pres...Relevant_on_Modern_Environments_(keynote).pdf



It says (about C++/CLI):


Cleanup in C++: Less Code, More Control


The CLR state of the art is great for memory.
It’s not great for other resource types:

• Finalizers usually run too late (e.g., files, database
connections, locks). Having lots of finalizers doesn’t scale.

• The Dispose pattern (try-finally, or C# “using”) tries to
address this, but is fragile, error-prone, and requires the
user to write more code.


Instead of writing try-finally or using blocks:

• Users can leverage a destructor. The C++ compiler
generates all the Dispose code automatically, including
chaining calls to Dispose. (There is no Dispose pattern.)

• Types authored in C++ are naturally usable in other
languages, and vice versa.

• C++: Correctness by default.
Other languages: Correctness by explicit coding.




There are manby other interesting stuff in this PDF and the following
powerpoint presentation:


http://microsoft.sitestream.com/TechEd/DEV/DEV333_files/Botto_files/DEV333_Sutte.ppt






Regards,

Ioannis Vranos

http://www23.brinkster.com/noicys
 
I

Ioannis Vranos

Shailesh said:
According to the PHP site, the code is copyright to "The PHP Group", so
it doesn't belong to an individual. I don't think there is a PHP
standard in the sense of something ratified by an SSO (standards setting
organization). Also, PHP and most of its extensions are written in C.


Thanks for the info. Well C is another language where in its newsgroup
comp.lang.c only ISO C things are discussed, and not everything.






Regards,

Ioannis Vranos

http://www23.brinkster.com/noicys
 
P

Peter Koch Larsen

Howard said:
there (and

I never suggested that C++ ought to have it! I merely answered the question
"Is there any C# construct that is not supported by C++?" Nothing was asked
about whether it *should* be supported by C++, and I specifically pointed
out the RAII method as our (possibly better) alternative.

As for a "valid" usage of it, what would be your criteria? I often used it
in Delphi, especially for making sure I closed handles, files, etc., which I
had opened and had to be sure to close. It's a heck of a lot quicker (and
more obvious, to me anyway) to simply say open..try..do
stuff..finally..close than to declare a new class instance to handle that
simple open/close pairing, especially when you need that "do stuff" part to
interact with *this* class.

I just meant that is see no valid use for it in C++. Delphi might be another
matter - no templates and/or destructors not automatically called at
destruction could be a reason to have "finally".
But again, I'm NOT advocating its use in C++!!!

I realise this! ;_)


/Peter
 
H

Herb Sutter

Actually, you just wrote valid C++/CLI code -- C++/CLI also supports
finally with exactly that syntax. This is described in the current draft
spec available via:
http://www.msdn.microsoft.com/visualc/homepageheadlines/ecma/default.aspx
.. See section 16.4, and search for "finally" throughout (there are other
spots that specify how it interacts with other language features like
goto).

This is in addition to destructors -- as Mike points out, you can also get
a similar effect with destructors:
C++ already has this, via destructors. When 'throw' causes
a scope to be exited, all automatic objects are destroyed, and
any destructors will run. ALWAYS. So just wrap that 'new' and
'delete' in a class, create an automatic object of that type,
and you have the same mechanism.

One advantage of finally is visual locality of reference -- the code is
right there in the function instead of off in a different place (a
destructor definition). One advantage of destructors is that RAII objects
encapsulate and automatically manage ownership. In your example above, I
would prefer to use a destructor (by writing auto_ptr<Resource> instead of
Resource*, you don't need a finally at all). You can use either facility,
of course.

Herb

---
Herb Sutter (www.gotw.ca)

Convener, ISO WG21 (C++ standards committee) (www.gotw.ca/iso)
Contributing editor, C/C++ Users Journal (www.gotw.ca/cuj)
Visual C++ architect, Microsoft (www.gotw.ca/microsoft)
 

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,769
Messages
2,569,582
Members
45,059
Latest member
cryptoseoagencies

Latest Threads

Top