473,399 Members | 3,038 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

What are the arguments against this

hi All,
I am working on a different language called System Verilog which is
trying to support classes as a construct,

Now our compiler allows something like the following

class C
{
void print();
}

main(){
C c1;

print(c1);

}
Now in the example above we are allowing the method to be called
independently. Is it too much to ask for to get the method depending
on the argument.
-Parag

Oct 31 '07 #1
9 1471

<pa********@hotmail.comwrote in message
news:11**********************@k35g2000prh.googlegr oups.com...
hi All,
I am working on a different language called System Verilog which is
trying to support classes as a construct,

Now our compiler allows something like the following

class C
{
void print();
}

main(){
C c1;

print(c1);

}

Now in the example above we are allowing the method to be called
independently. Is it too much to ask for to get the method depending
on the argument.
As I understand it, you are working on designing a language called System
Verilog and have a question about how something should be done. I could be
wrong, but that's how I read your question. I think a better place to ask
this question would be in comp.programming as it has nothing to do with C++
but programming in general.
Oct 31 '07 #2
On 2007-10-31 16:47, pa********@hotmail.com wrote:
hi All,
I am working on a different language called System Verilog which is
trying to support classes as a construct,

Now our compiler allows something like the following

class C
{
void print();
}

main(){
C c1;

print(c1);

}
Now in the example above we are allowing the method to be called
independently. Is it too much to ask for to get the method depending
on the argument.
Questions regarding System Verilog is better answered in a group
discussing that language, perhaps comp.lang.verilog might do?

--
Erik Wikström
Oct 31 '07 #3
Actually
I wanted to know why C++ is not alowing some thing like this so that
I can use your arguments to strengthen my view.

I dont want this to be adopted in this new language. Let me see what
the C++ experts think about the scope of doing this,

Oct 31 '07 #4
"pa********@hotmail.com" <pa********@hotmail.comwrites:
hi All,
I am working on a different language called System Verilog which is
trying to support classes as a construct,

Now our compiler allows something like the following

class C
{
void print();
}

main(){
C c1;

print(c1);

}
Now in the example above we are allowing the method to be called
independently. Is it too much to ask for to get the method depending
on the argument.
Are you asking if the above *is* OK in C++, or if it *should* be OK in
your new language?

If you're asking the first, no, it's not OK in C++.

If you're asking the second, you should ask in a language design group,
or maybe a general programming group.

sherm--

--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
Oct 31 '07 #5
On 31 Oct, 15:47, "parag_p...@hotmail.com" <parag_p...@hotmail.com>
wrote:
hi All,
I am working on a different language called System Verilog which is
trying to support classes as a construct,

Now our compiler allows something like the following

class C
{
void print();
}

main(){
C c1;

print(c1);

}

Now in the example above we are allowing the method to be called
independently. Is it too much to ask for to get the method depending
on the argument.
-Parag
Well you can do this - perhaps this is what
you meant ?

class C {/*...*/};
class D {/*...*/};
void print(C& c) { std::cout << "print a C"; }
void print(D& d) { std::cout << "print a D"; }
int main(){
C c1;
D d1;
print(c1);
print(d1);
}

Oct 31 '07 #6
I am asking the forum to show me the reasons and arguments that might
have been around when C++ did not implement it. My language has
implemented classes to a great extent and now this does not look like
a good feature,

I want to use the C++ arguments against this to vindicate me.
-Parag

Oct 31 '07 #7
On Oct 31, 4:47 pm, "parag_p...@hotmail.com" <parag_p...@hotmail.com>
wrote:
I am working on a different language called System Verilog which is
trying to support classes as a construct,
Now our compiler allows something like the following
class C
{
void print();
}
main(){
C c1;
print(c1);
}
Now in the example above we are allowing the method to be called
independently.
No you don't. You still require an argument of type C. All
you've changed is the syntax.
Is it too much to ask for to get the method depending
on the argument.
Adding it to C++ today would cause some additional confusion,
for very little benefit (although perhaps in templates...).
Originally, of course, it's an arbitrary choice between two
syntaxes; presumably, Stroustrup wanted to highlight the
privileged role of the first argument. In the case of virtual
functions, too, it's a lot clearer on which argument the dynamic
resolution depends. (In a language which supports multiple
dispatch, of course, the argument swings in the other sense: if
dispatch can depend on any or all of the arguments, it's
deceptive to privilege one in the syntax.)

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Nov 1 '07 #8
<pa********@hotmail.comwrote in message
news:11**********************@e34g2000pro.googlegr oups.com...
>I am asking the forum to show me the reasons and arguments that might
have been around when C++ did not implement it. My language has
implemented classes to a great extent and now this does not look like
a good feature,

I want to use the C++ arguments against this to vindicate me.
Your original code:

class C
{
void print();
}

main(){
C c1;

print(c1);

}

I think I finally understand. Instead of c1.print() you are doing
print(c1); Consider though.

class C
{
virtual void print();
virtual void print(int x);
};

class D
{
void print();
void print(int x);
operator int() { return 1; }
};

class E: public C
{
void print();
void print(int x);
};

void print( C c )
{
}

void print( int x )
{
}

int main()
{
C c1;
D d1;
E e1;

print(c1); // Which one does this call and why?
print(d1); // Which one does this call and why?
print(e1); // Which one does this call and why?
}

There are a lot of other scenarios I could come up with where it would be
arbitrary which print was called. So you'd have to come up with complicated
rules as to which one is called and why and it would just become a nightmare
as code wouldn't work as expected. Also, there may be print() declared in
other places. c1.print() states explicitly which print is to be called.
There is already some confusion with polymorphism, why add another layer
into the pot? I don't know the original reason this wasn't allowed, but I'm
glad it wasn't.
Nov 1 '07 #9
On Nov 1, 10:54 pm, "Jim Langston" <tazmas...@rocketmail.comwrote:
<parag_p...@hotmail.comwrote in message
news:11**********************@e34g2000pro.googlegr oups.com...
I am asking the forum to show me the reasons and arguments
that might have been around when C++ did not implement it. My
language has implemented classes to a great extent and now
this does not look like a good feature,
[...]
I think I finally understand. Instead of c1.print() you are doing
print(c1); Consider though.
[...]
There are a lot of other scenarios I could come up with where
it would be arbitrary which print was called. So you'd have
to come up with complicated rules as to which one is called
and why and it would just become a nightmare as code wouldn't
work as expected.
Not really. The difference is purely syntactic. Formally, one
could define the language so that f(a) and a.f() were synonyms;
one could even go further, and allow things like f(a, b) to be
written (a, b).f().

C++ doesn't do this, because it wants to stress the difference
between member functions and other functions. Ada 95 only
supports the f(a) notation---and f(a) in Ada 95 works exactly
like a.f() in C++.
Also, there may be print() declared in other places.
c1.print() states explicitly which print is to be called.
No more so that print(c1). In both cases, it depends on the
type of c1. And there's nothing fundamental which would prevent
it from depending on the dynamic type, although C++ doesn't
support it.

The real difference in C++ is that when I write c1.print(), the
print function can be resolved on the dynamic type of c1, and
can access private data. Other mechanisms can be conceived of
for both; Ada 95 doesn't have the c1.print() syntax, but
supports both virtual functions and private data.
There is already some confusion with polymorphism, why add
another layer into the pot? I don't know the original reason
this wasn't allowed, but I'm glad it wasn't.
There are arguments both ways. Is it normal that I have to use
a.f(), but g(a), when both f and g manipulate a, just because
f() is a member (and has access to private data), but g() isn't.
Or for a more complete example: is it normal that I have to
write someString.append( "abcd" ), but toUpper( someString )?
And what implications does this have for templates?

Having said that, I, too, find it more explicit to set the
"owning" argument off by putting it in front of the function, a
la C++.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Nov 2 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Jonathan Fine | last post by:
Giudo has suggested adding optional static typing to Python. (I hope suggested is the correct word.) http://www.artima.com/weblogs/viewpost.jsp?thread=85551 An example of the syntax he proposes...
112
by: Andy | last post by:
Hi All! We are doing new development for SQL Server 2000 and also moving from SQL 7.0 to SQL Server 2000. What are cons and pros for using IDENTITY property as PK in SQL SERVER 2000? Please,...
125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
24
by: Steven T. Hatton | last post by:
If I understand correctly, I have no assurance that I can determine the type of a simple class instance thrown as an exception unless I explicitly catch it by name. (non-derived classes having no...
12
by: shya | last post by:
hi there! I just wrote a function that reverse a string. It seems all ok to me, but the program goes on segmentation fault on *s = *t_str. Here's the code: #include <stdio.h> #include...
18
by: Marchello | last post by:
I write 2-dimensional array's wrapper class. And how I can access to the one element through the operator ? I need something like this: CMyArray<int> A(4, 4); // array "int A"; int value = A; ...
89
by: Tubular Technician | last post by:
Hello, World! Reading this group for some time I came to the conclusion that people here are split into several fractions regarding size_t, including, but not limited to, * size_t is the...
33
by: James H. Newman | last post by:
I have a portion of code along the following lines: volatile unsigned char x ; unsigned int f(unsigned char *y) ; When I do unsigned int z = f(&x) ;
34
by: Jorge | last post by:
Why is it listed here : http://www.crockford.com/javascript/recommend.html under "deprecation" ? Without it, how is an anonymous function() going to call itself (recursively) ? I use to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.