T
Timo Stamm
Mishagam said:SourceForge is very non random selection, not very representative of all
language usages.
I know my english isn't perfect, but did you even read what you replied to?
Timo
Mishagam said:SourceForge is very non random selection, not very representative of all
language usages.
I meant that not only SourceForge doesn't represent all programmers, itTimo said:I know my english isn't perfect, but did you even read what you replied to?
Timo said:Getters and Setters are another good example. Sure, the IDE can generate
them. But C#s properties are a lot more elegant.
Phlip said:A good design that doesn't need them at all is slightly more elegant
there. ;-)
Timo said:That's the point.
The following link explains it better than I did
http://cephas.net/blog/2004/02/16/c_public_properties_vs_java_getx_and_setx.html
Noah said:...
C++ pointers and references have completely different purposes.
'purpose' is what language designers imagined references would be used
for. Functionaly, as I understand, difference between references and
pointers is little syntax sugar [ -> replaced with . ] + what values
they can hold - references cannot hold null or objects allocated by new.
But you CAN have reference to destructed object out of scope (or field
in deleted object allocated on heap). Also references syntax resembles
value objects enough that is is difficult to distinguish what you are
using now. It is one more way where C++ loses C clarity.
What I meant is difference with pointer is too small to justify
existence of references for well designed language. I think that
designers of C++ just hated C pointers too much to think rationally.
By the way, I have little problem. I Wiki about C++ reference types I read:
"Once a reference is created, it cannot be later made to reference
another object; we say it cannot be reseated. This is often done with
pointers."
But in my VS 2003 C++ compiler you can easily put new value to
reference, like code sample below. Do you know who is correct here?
(assuming #include said:int main() {
int aa = 25;
int & ra = aa;
int bb = 323;
ra = bb;
printf("ra= %d\n", ra);
int *ii = new int;
*ii = 999;
ra = *ii;
printf("ra= %d\n", ra);
ii = NULL;
ra = *ii;
.....
THis code compiled and run OK on VS 2003
The said:Then VS2003's generated code may have a problem.
It segfaults on my machine, as expected.
movl -8(%ebp), %edx ; get ra's location (still aa)
; into %EDX
Phlip said:Followups set to non-Java groups.
No it isn't.
The more elegant design follows "the hollywood principle". That means "tell
don't ask". (Specifically it means "don't call us we'll call you", but with
slightly greater odds of getting called!)
In the more elegant design, clients tell classes what to do. Clients don't
Get variables (regardless of whatever syntactic sugar is available), then
change data, then call Set variables to push the data back in. Clients
should send messages to servant classes, and these should perform whatever
secret manipulations are required to obey these commands.
Put another way, classes should obey both the physical and logical meaning
of the rule "no public data". Yes, a Get method is slightly more
encapsulated that raw public data. But it's still not fully encapsulated.
I can recall an MS situation where *NULL contained a 0ul in each address
space. That's because so many NULLs were causing problems that MS decided to
make *NULL bizarrely temporarily useful. (char*)0 would appear to be "", for
example.
I could be wrong; all this is both undefined behavior and off-topic, etc...
props!
The said:In comp.lang.java.advocacy, Noah Roberts
<[email protected]>
wrote
Pointers are a means to an end (well, so is everything else in
a computer language, really). Exactly what is it that Java can't
do in this space?
I can't say Java's, "everything is a reference except when it is not,"
is a move up from having explicit value, reference, and pointer
semantics that operate in a uniform manner.
It would help if "uniform" = "consistent with type declaration".
int a[5];
int * b = a;
just isn't quite kosher to those schooled in Pascal, convenient as it
might be otherwise; it should be:
int a[5];
int * b = &a[0];
(I don't remember the actual Pascal offhand. It's been too long,
and in any event standard Pascal didn't have an addr() method.)
I'm also not all that sure of the usefulness of such things as
const char * p = "A rainy day in Georgia";
const char * q = p + 15; // q="Georgia"
unless q is an index variable stepping through p's string,
usually in a for or while loop:
for(q = p; *q; q++) { ... }
And of course there are the problems with such things as punning:
char * p = "Another rainy day in Georgia";
void routine(const char * p, char * q)
{
for(;*p;p++, q++) *q = (*p) + 1;
}
routine(p,p);
which could confuse maintainers of routine() -- especially
if routine() for some reason frees its arguments without
checking them first.
For its part Java has its own problems with arrays:
int[] s = new int[]{1,2,3};
Timo Stamm said:No. But maybe it could have looked like this:
class Foo : List
"public" is made default, ":" replaces "implements" (extends could be
replaced by "<").
A better example for superfluous verbosity:
ArrayList<Entry<String, Integer, Object>> l = new
ArrayList<Entry<String, Integer, Object>>();
Wouldn't it be nice to have local type inference here?
def l = new ArrayList<Entry<String, Integer, Object>>();
Getters and Setters are another good example. Sure, the IDE can generate
them. But C#s properties are a lot more elegant. You can start with simple
public members and introduce getters and setters later without any need to
change the clients of the class.
Timo said:No. But maybe it could have looked like this:
class Foo : List
"public" is made default, ":" replaces "implements" (extends could be
replaced by "<").
A better example for superfluous verbosity:
ArrayList<Entry<String, Integer, Object>> l = new
ArrayList<Entry<String, Integer, Object>>();
Wouldn't it be nice to have local type inference here?
def l = new ArrayList<Entry<String, Integer, Object>>();
Getters and Setters are another good example. Sure, the IDE can generate
them. But C#s properties are a lot more elegant. You can start with
simple public members and introduce getters and setters later without
any need to change the clients of the class.
Noah Roberts said:Well that function is bad for numerous reasons, not the least of which
is its use of char* instead of string. There are numerous ambiguities
that need be established that can only be so by looking at that code.
For one, who owns q?
Also, even a java programmer should see that it blows up. If you are
familiar with pointers enough to even know what that does you can see
that it doesn't work.
Oliver said:I think to grok the above code, you have to know certain things that you
might never learn if you programmed only in Java, such as the idea that char
strings are terminated by 0.
For its part Java has its own problems with arrays:
int[] s = new int[]{1,2,3};
Ick, and you say C++ has ugly syntax.
int s[] = {1, 2, 3};
Noah said:You mean like this?:
typedef ArrayList<Entry<String, Integer, Object> > AL;
AL l1;
AL l2;
VERY commonly done.
I wonder if someday we will have a language that lets you write like
Ruby, but that does all kinds of inferencing to tell you additional
info like types, potential bounds etc. but only when you want to see
it.
Don't know if you meant to imply that C++ works that way but it
doesn't. "public" is not the default inheritance mode, private is.
Getters and Setters are just poor design indicating that perhapse a
class is not the best data type to represent your data or that your
classes are lazy.
However, I have no idea what
{
std::ifstream ifs1("pathname");
std::ifstream ifs2(ifs1);
doSomething(ifs1);
doSomething(ifs2);
}
or
{
std::ifstream ifs1("pathname");
std::ifstream ifs2("path2");
ifs1 = ifs2;
doSomething(ifs1);
doSomething(ifs2);
}
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.