|
WilliamSauron wrote: Visual Studio editor had the same black color
Tools|Options|Environment|Fonts and Colors|Text Editor|Identifier
VS doesn't discriminate between these identifiers, but I could write an editor that does. (I'll stick with Edit.)
P.S. I finally got around to installing Leppie's xacc.ide -- it displays constructor identifiers in the greenish color.
modified on Friday, November 28, 2008 1:07 PM
|
|
|
|
|
WilliamSauron wrote: This brings the second question: as the compiler internally creates a method named "Item" as the implementation of the default indexer, does it really impose an unbearable burden on the creativity of programmers?
No, they provide an easy way around it. See IndexerNameAttribute .
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 beta 1 - out now! ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
There is no need to have a way around it through an attribute. If a class has an indexer, then it is a collection of some other things; "Item" is therefore not a good name for that class. It is a Coding Horror. Give the class an appropriate name, and you don't need the attribute...
-- Quidquid latine dictum sit, altum sonatur.
http://streambolics.flimbase.com
S. L.
|
|
|
|
|
WilliamSauron wrote: "Item" is therefore not a good name for that class.
No, it's simply your opinion.
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 beta 1 - out now! ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
Okay, your mission, should you choose to accept it, is to provide one single example where "Item" is an appropriate name for a collection class If you get caught or killed, the moderator will disavow any knowledge of this thread (which will self destruct in five seconds anyway)
-- Quidquid latine dictum sit, altum sonatur.
http://streambolics.flimbase.com
S. L.
|
|
|
|
|
First of all thanks for your reply it was really interesting to read it, especially:
WilliamSauron wrote: but please don't say the compiler is restricting your creativity
WilliamSauron wrote: On the other hand, now we know where the coding horror is
I have a lot to say, but Midterm is next week so I can't write a lot now.
BYE
Best wishes,
Redwan Al-Bougha
|
|
|
|
|
Try this:
public class Item
{
[IndexerName("IRDUM")]
public int this[int y]
{
get
{
return 0;
}
}
}
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 beta 1 - out now! ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
Thanks leppie,
Rob Graham already told me about IndexerNameAttribute .
But thanks for your interest
Best wishes,
Redwan Al-Bougha
|
|
|
|
|
That's right, imagine this:
class Dog
{
public string Dog
{
get
{
return "Fido";
}
}
}
The only member names that can be the same as their enclosing type are constructors. In your case the indexer, named Item, is named like its enclosing type and is not a constructor, so, that's where your problem is coming from.
To fix this, change The name of the class
|
|
|
|
|
Thanks Camilo,
I already know that, but I post this since it has some taste of horror.
Best wishes,
Redwan Al-Bougha
|
|
|
|
|
I cam across this C++ gem today in some code that a co-worker wrote. In his defense, the bulk of his programming experience is in OS/390 Assembler.
char *ShowDrive( TAPEDRIVE *DRV, char *out ) {
int status;
char *msg;
status = 0x2D2D;
if ( DRV->stat & POWERON ) status = 0x4E4F;
if ( DRV->stat & MOUNTED ) status = 0x544D;
if ( DRV->stat & STARTED ) status = 0x5453;
if ( DRV->stat & INTREQD ) status = 0x5249;
sprintf_s( out, 80,"%2d %4.4s %4.4s %2.2s %6.6s %8.8s %8.8s\n ",
DRV->slot, DRV->host, DRV->name, &status, DRV->vols, DRV->msg1, DRV->msg2 );
msg = out + strlen( out );
sprintf_s( msg, 80," Block=%d\n", DRV->blockID );
return out + strlen( out );
}
Where do I begin? I especially like the int status variable that he uses in the sprintf_s with a format specifier of "%2.2s". It took me a while to realize that since he used "&status" as the argument, he was forcing sprintf_s to use it as a char pointer, and that the value of the int was two ASCII characters (reversed, because of Little Endianness).
I also like the return of the char pointer that points to the middle of the constructed string. (In his code the return value was ignored.) I'm not wild about the way it plays willy-nilly with the char pointers, etc. Too much horrible crap to even go into it all. My head hurts.
WE ARE DYSLEXIC OF BORG. Refutance is systile. Your a$$ will be laminated.
There are 10 kinds of people in the world: People who know binary and people who don't.
|
|
|
|
|
Tom Delany wrote: I also like the return of the char pointer that points to the middle of the constructed string.
Tom Delany wrote: return out + strlen( out );
I'd have thought that would return a pointer to the character after the constructed string. Could be excusable if he's intending to add further text to the buffer , although judging by your comments that isn't the case.
|
|
|
|
|
|
PIEBALDconsult wrote: To avoid the Shlemiel the painter's algorithm[^] problem.
As noted, it is often useful to have functions that append to strings return either a count of the number of bytes written or a pointer to the end of the new data. While C-style string handling is often dangerous because of a general lack of bounds checking, suitable coding techniques can at least make it efficient.
BTW, the painter's problem could be adjusted to give whatever performance dropoff is desired between day #2 and day #3 by specifying that the paint dries out with time. When the painter makes shorter trips, he can use up all the paint on his brush before it dries out. After a certain point, however, drying will become a factor. Depending upon whether the paint is useful until it dries out and then becomes useless, or whether painting becomes slower as the paint gets drier, different performance characteristics may be achieved.
|
|
|
|
|
supercat9 wrote: the painter's problem could be adjusted to give whatever performance dropoff is desired between day #2 and day #3 by specifying that the paint dries out with time. When the painter makes shorter trips, he can use up all the paint on his brush before it dries out. After a certain point, however, drying will become a factor. Depending upon whether the paint is useful until it dries out and then becomes useless, or whether painting becomes slower as the paint gets drier, different performance characteristics may be achieved.
I imagine an optimalization task based on that in an exam of computers' architecture (+ a bunch of extra triple integrals to do).
Greetings - Gajatko
Portable.NET is part of DotGNU, a project to build a complete Free Software replacement for .NET - a system that truly belongs to the developers.
|
|
|
|
|
Rob Grainger wrote: I'd have thought that would return a pointer to the character after the constructed string.
You're right. My head was hurting so much from the rest that I misread it.
WE ARE DYSLEXIC OF BORG. Refutance is systile. Your a$$ will be laminated.
|
|
|
|
|
Quite understandable - I think returning the pointer to the next character is the only redeeming factor I could spot
|
|
|
|
|
Looks like a C gem to me.
|
|
|
|
|
Yeah. He gave the file a .CPP extension, but there was nothing really C++ about it.
WE ARE DYSLEXIC OF BORG. Refutance is systile. Your a$$ will be laminated.
|
|
|
|
|
Tom Delany wrote: He gave the file a .CPP extension, but there was nothing really C++ about it.
That actually makes sense sometimes. If he really knows C, but wants to make use of a C++ stricter type system and catches more errors at compile time, that is a way to go.
|
|
|
|
|
C is infamous for pointer abuse. I think this would've been pretty standard C code 10 - 15 years ago.
|
|
|
|
|
The code works, so this is not a coding horror? I don't see any problem here. Maybe it's just your head. You should get a new one and then look at the code again.
Tom Delany wrote: he was forcing sprintf_s
This does not mean that he was "forcing" anything.
|
|
|
|
|
DECLARE p_cursor CURSOR FOR
SELECT TOP 1 SortDateStart AS DateStart, SortDateEnd AS DateEnd
...
This code was in a trigger...
|
|
|
|
|
What especially are you considering to be a horror?
1. Using a database trigger at all (this is IMHO the true horror here ) ?
2. Using TOP 1 without being explicit about it ?
Regards
Thomas
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Programmer - an organism that turns coffee into software.
|
|
|
|
|
Well, I am ok with triggers so far you make a sensible use of them (which is not the case for the database where I found this).
You should avoid the use of cursors with SQL Server, that is not good but most people would not call that an horror.
The point is: Why on earth would someone open a cursor on a 1 row set????
In this case it is far more simple and efficient to type: SELECT TOP 1 @A=Column1, @B=Column2.... instead of declaring a cursor, fetch the data and close it.
|
|
|
|