Click here to Skip to main content
15,917,328 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Glade I'm taking a couple days off .. Pin
Mark_Wallace1-Apr-15 10:43
Mark_Wallace1-Apr-15 10:43 
GeneralRe: Glad I'm taking a couple days off .. Pin
Richard Deeming1-Apr-15 9:20
mveRichard Deeming1-Apr-15 9:20 
GeneralRe: Glade I'm taking a couple days off .. Pin
kmoorevs1-Apr-15 9:21
kmoorevs1-Apr-15 9:21 
GeneralRe: Glade I'm taking a couple days off .. Pin
Pete O'Hanlon1-Apr-15 9:50
mvePete O'Hanlon1-Apr-15 9:50 
GeneralRe: Glade I'm taking a couple days off .. Pin
Mark_Wallace1-Apr-15 10:44
Mark_Wallace1-Apr-15 10:44 
GeneralRe: Glade I'm taking a couple days off .. Pin
Mark_Wallace1-Apr-15 11:07
Mark_Wallace1-Apr-15 11:07 
GeneralRe: Glad I'm taking a couple days off .. Pin
Richard MacCutchan1-Apr-15 21:31
mveRichard MacCutchan1-Apr-15 21:31 
GeneralWhere does it end? Pin
Sander Rossel1-Apr-15 8:03
professionalSander Rossel1-Apr-15 8:03 
* DISCLAIMER *
This isn't a programming question, because I've solved the programming problem myself.
Rather, I'm interested in your opinion regarding the solution, clever or 'clever'?

So today I had a nice little challenge.
My application has a grid which can be sorted on various columns, asc and desc.
Now the sorting isn't applied by clicking the column header, but by selecting a value from a drop down (Name, Name (descending), Title, Title (descending) etc.).

I was thinking I could just have a switch statement where I check which ordering the user chose (which would make me extend the switch for each new ordering), or... I could abstract this away.
Of course I went for the second option. Now to make this work (and it works nicely, adding a new ordering is a piece of cake) I had to write the following function:
C#
SomeFunction(string caption, Func<IQueryable<TElement>, Expression<Func<TElement, TKey>>, IQueryable<TElement>> linqFunction, Expression<Func<TElement, TKey>> expression) { ... }
Since this is a WinForms application though, and WinForms and generics don't go well together I'm more or less forced to use a dynamic later on as it's quite impossible to get the values of TElement and TKey from object.

I'm thinking this isn't ideal in terms of complexity and readability, but it is pretty neat because adding a new ordering is really simple (one line of simple code) and guaranteed to work on the first try (you'll never forget to change that switch statement again).

And the solution is even re-usable for the filter functionality I need as well (which, of course, becomes a breeze as well)!

So judging from that, clever or 'clever'?
And where do you draw the line for cleverness vs. readability/simplicity?
Visit my blog at Sander's bits - Writing the code you need.
Or read my articles at my CodeProject profile.
Simplicity is prerequisite for reliability.
— Edsger W. Dijkstra
Regards,
Sander

GeneralRe: Where does it end? Pin
PIEBALDconsult1-Apr-15 8:42
mvePIEBALDconsult1-Apr-15 8:42 
GeneralRe: Where does it end? Pin
Sander Rossel1-Apr-15 8:59
professionalSander Rossel1-Apr-15 8:59 
GeneralRe: Where does it end? Pin
PIEBALDconsult1-Apr-15 9:20
mvePIEBALDconsult1-Apr-15 9:20 
GeneralRe: Where does it end? Pin
Sander Rossel1-Apr-15 9:31
professionalSander Rossel1-Apr-15 9:31 
GeneralRe: Where does it end? Pin
RASPeter6-Apr-15 11:39
professionalRASPeter6-Apr-15 11:39 
GeneralRe: Where does it end? Pin
Sander Rossel6-Apr-15 12:14
professionalSander Rossel6-Apr-15 12:14 
GeneralRe: Where does it end? Pin
Eddy Vluggen1-Apr-15 8:58
professionalEddy Vluggen1-Apr-15 8:58 
GeneralRe: Where does it end? Pin
Sander Rossel1-Apr-15 9:06
professionalSander Rossel1-Apr-15 9:06 
GeneralRe: Where does it end? Pin
Eddy Vluggen1-Apr-15 9:21
professionalEddy Vluggen1-Apr-15 9:21 
GeneralRe: Where does it end? Pin
Sander Rossel1-Apr-15 9:29
professionalSander Rossel1-Apr-15 9:29 
GeneralRe: Where does it end? Pin
Eddy Vluggen1-Apr-15 9:49
professionalEddy Vluggen1-Apr-15 9:49 
GeneralRe: Where does it end? Pin
Sander Rossel1-Apr-15 10:00
professionalSander Rossel1-Apr-15 10:00 
GeneralRe: Where does it end? Pin
Sascha Lefèvre1-Apr-15 8:59
professionalSascha Lefèvre1-Apr-15 8:59 
GeneralRe: Where does it end? Pin
Sander Rossel1-Apr-15 9:14
professionalSander Rossel1-Apr-15 9:14 
GeneralRe: Where does it end? Pin
Sascha Lefèvre1-Apr-15 9:36
professionalSascha Lefèvre1-Apr-15 9:36 
GeneralRe: Where does it end? Pin
Sander Rossel1-Apr-15 9:45
professionalSander Rossel1-Apr-15 9:45 
GeneralRe: Where does it end? Pin
Sander Rossel2-Apr-15 5:52
professionalSander Rossel2-Apr-15 5:52 

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.