|
TClarke wrote: private static final String SQL = ""
+ " SELECT "
+ " nvl( vss.structure_address, "
+ " ifsapp.serial_structure_template_api.get_pos(top_part_no,"
etc...
Without the "" on the first line, you couldn't start the second line with a +
hence the indentation might be at risk, i.e. the third and following lines might not
align with the second one; this may become very important when the code is worthwhile
and is likely be published on one or more forums.
BTW: the code itself is OK, the compiler does the concatenation for you.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/AllLanguages/General
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
If it had just been down to him being a format obsessive I would have let it slide but he claimed it was not possible to start a string with a space unless you concatenated it to a blank string. Which is of course complete bollocks
Also this SQL was just going off to run in a database, it wouldn't be seen by anyone but developers on the team, none of which would be any less capable of reading the code if it wasn't aligned like that
Luc Pattyn wrote: BTW: the code itself is OK, the compiler does the concatenation for you.
Sure. The byte code comes out the same, he didn't know that though
|
|
|
|
|
Luc Pattyn wrote: the code itself is OK, the compiler does the concatenation for you.
But the string concatenation that has been used is pretty costly right?
|
|
|
|
|
Compilers are smart enough to understand that the concatenation of two literals
yields a bigger literal. They don't generate run-time code to get that done.
Also -- not applicable in this case -- the CLR compilers are known to use a StringBuilder
if your code is performing complex concatenation involving not just literals, even
when the source does not call for a StringBuilder explicitly.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/AllLanguages/General
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Oh nice! I didn't know that…
Now I can write sloppy string concatenation code without worrying about the performance penalty! ^_^
Does this feature count as encouraging bad coding practices?
ROFLOLMFAO
|
|
|
|
|
Ri Qen-Sin wrote: Does this feature count as encouraging bad coding practices?
Most people dont need to be encouraged in the wrong direction.
Compiler optimizations typically improve the simple cases, and seldom drastically improve
the complex cases (where most could be gained!). So staying vigilent would pay off
frequently.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Indentation-wise, I find that this works well:
string query
= "SELECT [foo], [bar] "
+ "FROM [f] "
+ "WHERE [id] = @id";
|
|
|
|
|
That's fine by me, the only risk is you might omit a space somewhere, which you
would notice more easily if everything were on one line.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
This reminds me of a consultancy developer who wrote all of his SQL statements like this:
"SELECT field1, \r\n" +
" field2, \r\n" +
" field3 \r\n" +
"FROM \r\n" +
" myTable \r\n"; It still makes me shudder.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
what are those \r characters doing there?
|
|
|
|
|
Isn't that the Cariage Return code
Like '\n' is the new line feed code.
codito ergo sum
|
|
|
|
|
Certainly is. He put them in to format them so they would appear nice if ever they were printed out from code.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Environment.NewLine is rather really environment-friendly right?
|
|
|
|
|
It is, but don't tell him that. The real WTF is formatting this out the way he did though.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
I would do that as:
@"
SELECT field1,
field2,
field3
FROM
mytable
";
It still puts the newlines in the string for when I dump a CommandText to a log.
|
|
|
|
|
That makes sense sometimes, especially if you're debugging [or logging rather] the actual SQL code sent to the DBMS.
--
Smell-o-vision users, insert nostril tubes now
|
|
|
|
|
To be honest, the time it takes you to do this is wasted time - especially, as I noted in the OP, when you are a consultant and thus billing by the hour.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
no joke...this is from a code generator developed by an earlier employee.
SQL = "INSERT INTO Orders (" & _<br />
" OrderID, " & _<br />
" CustomerID, " & _<br />
" EmployeeID, " & _<br />
" OrderDate, " & _<br />
" RequiredDate, " & _<br />
" ShippedDate, " & _<br />
" ShipVia, " & _<br />
" Freight, " & _<br />
" ShipName, " & _<br />
" ShipAddress, " & _<br />
" ShipCity, " & _<br />
" ShipRegion, " & _<br />
" ShipPostalCode, " & _<br />
" ShipCountry " & _<br />
" )" & _<br />
"VALUES (" & _<br />
"'" & Orders.OrderID & "', " & _<br />
"'" & Orders.CustomerID & "', " & _<br />
"'" & Orders.EmployeeID & "', " & _<br />
DataCommonFunctions.SQLDate(Orders.OrderDate) & ", " & _<br />
DataCommonFunctions.SQLDate(Orders.RequiredDate) & ", " & _<br />
DataCommonFunctions.SQLDate(Orders.ShippedDate) & ", " & _<br />
"'" & Orders.ShipVia & "', " & _<br />
"'" & Orders.Freight & "', " & _<br />
"'" & Orders.ShipName & "', " & _<br />
"'" & Orders.ShipAddress & "', " & _<br />
"'" & Orders.ShipCity & "', " & _<br />
"'" & Orders.ShipRegion & "', " & _<br />
"'" & Orders.ShipPostalCode & "', " & _<br />
"'" & Orders.ShipCountry & "') "
Sql Injection anyone?!?
Whenever I put sql in code it's always on one line and I'm using parameters!
|
|
|
|
|
the coder wants readable code, so it isnt such a horror.
Greetings from Germany
|
|
|
|
|
But a horror for the compiler.
|
|
|
|
|
compilers don't have feelings. they cannot be horrified.
|
|
|
|
|
I bet it was comments like this that led to SkyNet waging war on man....
|
|
|
|
|
The compiler makes one string of it all and so the empty string is "Over the hills".
I like readable code so much, that I often write a little more code and comments and think about value and class names up to 10 minutes. It helps me to make a 'master architecture' for my work. It has often paid off, because I can easy reuse code. I have to maintain 6 projects in which a lot of code is reused. The changes and enhancements for Vista I wrote 1 time and use it 6 times.
Greetings from Germany
|
|
|
|
|
This is why I like the @"string" literal operator in C#.
private static final String SQL = @"SELECT
nvl( vss.structure_address,
ifsapp.serial_structure_template_api.get_pos(top_part_no, ...";
|
|
|
|
|
Wait... don't answer that.
So at work I'm doing up a quick and dirty ASP.NET application that uses a TreeView . I'm still a bit of a beginner to programming for the web so I've been through the installed MSDN docs quite a bit for the past couple of weeks but I just ran across something that utterly blew my mind.
Anybody who has worked with TreeView knows it's got a few quirks, namely dealing with the fact that it's biased towards hierarchical data (why else would you use it?). I haven't had a lot of experience using .NET collections for a lot of things so combine that fact with the fun hierarchical nature of TreeView nodes and I have a lot of help doc reading to catch up on.
So I'm trying to find some sort of way to get at a TreeNodeCollection index without having to loop through an IEnumerator like so:
'enumerate through the nodes on this level and find out what the currently selected
'node's index is
Dim nodeEnumerator As IEnumerator
If selectedNode.Parent Is Nothing Then
nodeEnumerator = trvTasks.Nodes.GetEnumerator
Else
nodeEnumerator = selectedNode.Parent.ChildNodes.GetEnumerator
End If
'Counter code goes here
I'm hitting random members and I happen to land on the RemoveAt page. No big deal, right? There's no good information here on finding an index or anything...
Whiskey.
Tango.
Foxtrot.
From the integrated VS2005 help:
C++
void button2_Click( Object^ , EventArgs^ )
{
if ( this->treeView1->Nodes[ 0 ]->Text->Equals( "Node0" ) )
{
this->treeView1->Nodes->RemoveAt( 0 );
}
}
Now I've dabbled in C++, and I've even done a little MFC in school, but is this really what you have to do in Managed C++? If C# is supposed to be all the best things about C++ then this looks like all the worst... No wonder nobody wants to touch the stuff.
|
|
|
|