Click here to Skip to main content
15,887,027 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: NotImplementedException not implemented PinPopular
Gary Wheeler1-Sep-16 1:49
Gary Wheeler1-Sep-16 1:49 
GeneralRe: NotImplementedException not implemented Pin
OriginalGriff1-Sep-16 3:55
mveOriginalGriff1-Sep-16 3:55 
GeneralRe: NotImplementedException not implemented Pin
obermd1-Sep-16 18:50
obermd1-Sep-16 18:50 
GeneralRe: NotImplementedException not implemented Pin
obermd1-Sep-16 18:49
obermd1-Sep-16 18:49 
GeneralRe: NotImplementedException not implemented Pin
Middle Manager1-Sep-16 3:55
Middle Manager1-Sep-16 3:55 
GeneralRe: NotImplementedException not implemented Pin
Brisingr Aerowing1-Sep-16 4:29
professionalBrisingr Aerowing1-Sep-16 4:29 
GeneralRe: NotImplementedException not implemented Pin
Snorri Kristjansson2-Sep-16 1:17
professionalSnorri Kristjansson2-Sep-16 1:17 
GeneralWhy? Pin
Matt U.18-Aug-16 6:47
Matt U.18-Aug-16 6:47 
The project I'm currently working on has been developed by four people, including myself, over the course of the past two years. While looking through some code yesterday, I saw many instances like this:

C#
var someInt = model.SomeIntProperty;

SomeMethod(param1, param2, someInt != null && someInt.HasValue ? someInt.Value : (int?)null);


Why? Is that really necessary, to check the value, pass the Value if it has one, and otherwise pass 'null' cast as a nullable int?

This project also utilizes Entity Framework for the data access layer. The same contractor (contract was not renewed, for several obvious reasons) also wrote some data access code at one point. No, he didn't use EF with LINQ - he called "context.Database.ExecuteSqlQuery" methods, using const string variables for the queries. The majority of them are pretty basic select statements.

C#
private const string SomeSqlQuery = "select * from table1 where field1 = {0} and field2 = {1}";

// Somewhere in the Repository class:
var field1 = model.SomeField;
var field2 = model.SomeOtherField;

context.Database.ExecuteSqlQuery<SomeType>(SomeSqlQuery, field1, field2);


The problem? We discovered, by chance that the "format string" construct for the SQL query is supported - until SQL Server 2008 R2. If the target DB is ever upgraded from SQL Server '08 to '08 R2, this application would not work in several cases. We had to convert all of these so that they take "@field1" type parameters, and then pass SqlParameter objects to the ExecuteSqlQuery methods. But I don't understand why he didn't use EF with LINQ queries, as the rest of the data access code does?
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.

GeneralRe: Why? Pin
Bernhard Hiller18-Aug-16 21:52
Bernhard Hiller18-Aug-16 21:52 
GeneralRe: Why? Pin
Matt U.19-Aug-16 2:20
Matt U.19-Aug-16 2:20 
GeneralRe: Why? Pin
Brisingr Aerowing19-Aug-16 2:20
professionalBrisingr Aerowing19-Aug-16 2:20 
GeneralRe: Why? Pin
User 991608019-Aug-16 3:56
professionalUser 991608019-Aug-16 3:56 
GeneralRe: Why? Pin
Brisingr Aerowing19-Aug-16 4:33
professionalBrisingr Aerowing19-Aug-16 4:33 
GeneralRe: Why? Pin
Matt U.19-Aug-16 5:10
Matt U.19-Aug-16 5:10 
GeneralRe: Why? Pin
User 991608019-Aug-16 5:41
professionalUser 991608019-Aug-16 5:41 
GeneralRe: Why? Pin
Basildane22-Aug-16 4:37
Basildane22-Aug-16 4:37 
GeneralRe: Why? Pin
CDP180223-Aug-16 21:35
CDP180223-Aug-16 21:35 
GeneralRe: Why? Pin
Matt U.24-Aug-16 10:04
Matt U.24-Aug-16 10:04 
GeneralRe: Why? Pin
mbb017-Sep-16 22:27
mbb017-Sep-16 22:27 
GeneralRe: Why? Pin
User 99160808-Sep-16 5:01
professionalUser 99160808-Sep-16 5:01 
GeneralRe: Why? Pin
Member 942483515-Sep-16 10:57
Member 942483515-Sep-16 10:57 
GeneralRe: Why? Pin
Richard Deeming16-Sep-16 3:02
mveRichard Deeming16-Sep-16 3:02 
GeneralPostgreSQL RAISE Pin
Indivara18-Aug-16 4:09
professionalIndivara18-Aug-16 4:09 
GeneralRe: PostgreSQL RAISE Pin
Rob Grainger24-Aug-16 4:58
Rob Grainger24-Aug-16 4:58 
RantDid I miss a memo? Pin
Duncan Edwards Jones9-Aug-16 0:23
professionalDuncan Edwards Jones9-Aug-16 0:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.