|
No, I don't use const s for SQL.
|
|
|
|
|
PIEBALDconsult wrote:
No, I don't use const s for
SQL.
Then we have a term definition problem because I responded to what you said...
"And I [PIEBALDconsult] write it as ...private const string SQL"
|
|
|
|
|
|
PIEBALDconsult wrote: I meant "that".
No idea what that means.
|
|
|
|
|
Looks pretty damned neat to me. I always write out my SQL with each identifier or keyword on its own line. Much easier to read and diagnose.
|
|
|
|
|
Brady Kelly wrote: Looks pretty damned neat to me.
I don't know what you are referring to.
I have no problem with multi-line SQL constructs.
|
|
|
|
|
PIEBALDconsult wrote: so it prints out nice in error messages. If that is where you want it printed out nicely, you could use:
...= "\nSELECT ID\n, NAME\n, BIRTHDAY\nFROM TABLE\nWHERE NAME LIKE @PARAM\n";
The thing I don't like about @"... is that intellesense puts in indents you don't want, while most of the time, intellesense is so handy, I don't like working without it. Of course, you might be one of those people who like readable code too.
|
|
|
|
|
The "Best Practice" is not to use string concatenation in a loop. The reason is that under the hood when concatinating two strings, a third string will be created large enough to bold both source strings. The source strings will be copied to that new string, the original string destroyed, then recreated and the contents of the temporary string copied into it, then the temporary string destroyed. The concatination that you are showing should be fine, unless it is being performed in a loop.
|
|
|
|
|
You are talking about the real Best Practice.
But the "Best Practice" is to replace any string concatenation, even in consts, by a StringBuilder.
|
|
|
|
|
const string sql = "select stuff "+
"from table";
|
|
|
|
|
KRucker wrote: The "Best Practice" is not to use string concatenation in a loop.
It still depends on what the "string" is.
And it also depends on the impact of the code under use. Most of the time a builder is pointless because it does nothing but obfuscate the code.
|
|
|
|
|
KRucker wrote: The concatination(sic) that you are showing should be fine, unless it is being performed in a loop. How many const declarations run in a loop? Unless you are instantiating a class in a loop... which indicates the const field should also be static.
You should really read posts more clearly, he wasn't complaining about the use of concatenations, but about people spouting off about best practices where the practices clearly don't apply. Makes those people look like they are doing things by rote without thinking about what they are saying or if what they say makes sense.
Of course I have been guilty of that, I shouldn't throw stones when I live in a house with glass all around it.
You forgot to mention each of those string parts get stuck in the intern table until the GC gets around to cleaning it up.
PS "that" I am guilty of includes: misreading items, not thinking things out, and saying inappropriate things.
PPS Edited my post because Preview clearly showed your statement. On checking why posting didn't show, I missed some HTML tags that removed it from post.
|
|
|
|
|
Well, best practices are not always the best...
|
|
|
|
|
"Best practices" are "at best" someone's opinion. In some cases that opinion may be shared by many, but that doesn't always make it right. After all, at one time, how many people had the opinion the world was flat and the best practice was not to sail too far out?
While some things that are considered a best practice I do see reason to use over alternatives, I really don't like the idea of having an arbitrary list of "do these things for best results". They (you know, the "they" that killed Kenny) might as well call it "'boxes to use and not think outside of' practices" instead of "best practices".
|
|
|
|
|
Chad3F wrote: After all, at one time, how many people had the opinion the world was flat and
the best practice was not to sail too far out?
At the time when people did in fact think the world was flat then in fact is was foolhardy to sail too far out because one was very likely to not return. Which was a loss both in lives and commerce.
|
|
|
|
|
Yes, those that sailed too far likely had a greater chance of something going wrong (per voyage).. but statistically over all, I expect out of all ships/lives lost that only a small percentage were from those sailing out too far. Most had no reason to try (unless they were explorers), so most of the risk was while in known waters (so why not have a best practice of never sailing period). This would be like most people not routinely driving more than 1000 miles (or kilometers) from their home (unless it was required of their job).. hence the [paraphrased] expression of "most [driving] accidents occur within X distance of ones home", simply because that is where the are [on the road] most of the time.
In the end, just because something is done for the wrong reasons (i.e. to not fall off the end of the world) and happens to be useful (i.e. less lost lives/cargo), doesn't justify the basis (a variation of "the ends don't justify the means" I suppose). As an example, if a parent tells a young child not to talk to strangers, "just because", but not why explain why (since the child would unlikely be capable of comprehending why anyway), then that may work on the short term.. but, if left at that, in the long term it could be disastrous. Imagine if that child follows that directive to the letter "just because" their parent said so and one day there is a house fire, firefighters come and surround the house with the kid still inside. Now the child sees all these strangers and has to make a choice.. does he go outside, where all these strangers are, and break the rule.. or does he stay inside (or even hide, since several strangers are entering the house for some reason) to avoid them? A slightly contrived scenario (but not impossible) that illustrates how blindly following a "rule" without understanding why can [eventually] lead to a worse outcome than what the rule was indented to avoid. In some cases, like a young child's limited comprehension, you have to try and account for exceptions when stating the rule.. but when comprehension is possible, ignorant, "just because" logic is never an acceptable reason to do something. One should know _why_ something is better to use than another, in which case they shouldn't _need_ to be told to what [specifically] to do for the best, as it is the automatic choice (including _when_ to break the default choice). If I know a wood chipper chops up materials you put in it, and I know one is [potentially] running, then I implicitly choose not to put my hand in it.. I don't need to be told NOT to do that as a best practice. Yes, they still put that warning sign on it.. I guess because some [adult] people are ignorant of how a chipper works (which in itself is inexcusable).
I think the fact that [so-called] "best practices" exists is in some ways related to how people are taught.. far too much rote learning and not enough understanding. Rote is fine for forming a basic foundation before enough knowledge can be amassed to achieve understanding, but becomes a hindrance after that. In other words.. Teach someone 10 facts, without understanding, and that person knows 10 things. Teach that same person 10 concepts, with understanding, and now they know 100's or even 1000's of things (i.e. the meaningful combinations of those 10 concepts).
|
|
|
|
|
Chad3F wrote: and happens to be useful (i.e. less lost lives/cargo), doesn't justify the basis
Yes as a matter of a fact it does.
Most software development exists to fulfill a need, often either an explicitly or even implicitly commercial.
Just as sailing a ship did. Exploring might be 'fun' or 'cool' but the rate of return is very low. Whereas staying with the known routes provided a known rate of return. And that is what businesses want. They don't want fun/cool. They want money.
Chad3F wrote: Teach that same person 10 concepts, with understanding, and now they know 100's or even 1000's of things (i.e. the meaningful combinations of those 10 concepts)
Of course that is what one wants. But one also wants every one to be a multi-talented genius as well and it just doesn't happen.
|
|
|
|
|
I know the show that kills Kenny, because of an article I read that talks about it. (At least if I see the show's name, I'll also remember it kills Kenny) The article didn't say why they kill Kenny and I've only watched about 40 seconds tops to see if I wanted to watch it. Is it some group mindset that causes them to want to kill Kenny? Of course the writers put it in because it is funny to constantly kill the same person over and over and... (Which is why I could stand about 40 seconds of their humor.)
What a scalawag that Columbus was, eh? I also like your alternative definition of best practices.
|
|
|
|
|
The "Kenny" reference was to indicate that the "They" context I was using was not a specific, or even tangible, group (such as an official standards body, like IETF, ISO, IEEE, ANSI, etc..). But instead was the unknown and mysterious "powers that be" (in the context of defining so-called "best" anything) that define "best practice" lists.
As for the origin behind the actual killing of Kenny.. I guess it started out as some form of joke in the show (e.g. this poor kid Kenny just can't catch a break), and just kept on going from there. Eventually they stopped doing it [regularly] (maybe they ran out of "interesting" ways for Kenny to die). I'm sure there is probably an official response from Trey Parker and/or Matt Stone (its creators) about the subject on some fan site/FAQ/forum out there.
|
|
|
|
|
It's best to avoid "best practices".
|
|
|
|
|
Unless you're talking about a really old (.NET 1) version of the compiler, this is translated internally into the following il:
.field private static literal string SQL = string('SELECT ID, NAME, BIRTHDAY FROM TABLE WHERE NAME LIKE @PARAM') As you can see, there's no concatenation in there at all.
|
|
|
|
|
I know there is no concatenation. Any const must be resolved at compile time.
When I said that I "think it optimizes" I put the because it is obvious.
|
|
|
|
|
That was meant for you to beat them round the head with, rather than for your benefit.
|
|
|
|
|
Didn't even the 1.0 compiler do that with string constants?
|
|
|
|
|
BobJanova wrote: Didn't even the 1.0 compiler do that I, too, was surprised by that, however I learned C# around 2.3 or later so I bought it even though it seemed odd with a const declaration.
|
|
|
|