4 ms·
"On the other hand, I find such code painful to look at." It also pains me to see the opening bracket in its own line. (Being from a field where I don't get to
by mschuetz 6y ago
"On the other hand, I find such code painful to look at."
It also pains me to see the opening bracket in its own line. (Being from a field where I don't get to use C# or SQL, I don't understand what the author is referring to)
- deleted 6y ago[deleted]
- blackbear_ 6y agoCode is vulnerable to SQL injection. And yes the opening bracket on a new line hurts.
- imstate 6y agoThe opening bracket in a new line is very common for C/C++ and C#. Obviously Standards change, but that's what we learned when I went to school. The only thing that should matter with style is consistency.
- throwaway3neu94 6y agoAgree. It hasn't changed, it's still what Microsofts C# style guide recommends. https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/inside-a-program/coding-conventions https://docs.microsoft.com/en-us/dotnet/csharp/programming-g... It's also what VS Code autoformats even C++ to by default. Also I wonder if the other commenters reflexively saying "SQL injection" realize that is just the symptom; the underlying problem is that LINQ is not used. Even if the SQL injection was fixed, a literal SQL query is usually not the right tool in C#.
- znpy 6y agoIIRC some old unix book recommended splitting type declaration, prototype and body on different lines, like this: int myFunc(char *str, int strlen) { <body> } with the rationale being that grepping for ^myFunc (or searching for it in vi) would have found the function declaration immediately. Not sure I like that, anyway.
- deleted 6y ago[deleted]
- dataflow 6y agoRe: braces on their own lines, one practical advantage of doing so (leaving aside subjective anesthetics like symmetry) is that source control (at least got) will be able to automatically distinguish and merge changes to the header and the body independently, since they're no longer adjacent.
- Smaug123 6y agoEven if the ID variable is an integer (and therefore you're immune to injection), it's still inefficient. If you use the command "select * from Customer where ID=@id" and you set ID as a parameter instead, then caching can happen behind the scenes ("prepared statements"). See the justifications at https://www.npgsql.org/doc/basic-usage.html#parameters https://www.npgsql.org/doc/basic-usage.html#parameters, for example. My experience is only with Postgres, but I imagine they translate.