Click here to Skip to main content
15,894,017 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: would you rather? Pin
honey the codewitch29-Jul-19 1:36
mvahoney the codewitch29-Jul-19 1:36 
GeneralRe: would you rather? Pin
Mycroft Holmes28-Jul-19 11:45
professionalMycroft Holmes28-Jul-19 11:45 
GeneralRe: would you rather? Pin
honey the codewitch28-Jul-19 11:54
mvahoney the codewitch28-Jul-19 11:54 
GeneralRe: would you rather? Pin
BillWoodruff28-Jul-19 13:52
professionalBillWoodruff28-Jul-19 13:52 
GeneralRe: would you rather? Pin
Super Lloyd28-Jul-19 16:29
Super Lloyd28-Jul-19 16:29 
GeneralRe: would you rather? Pin
honey the codewitch28-Jul-19 18:41
mvahoney the codewitch28-Jul-19 18:41 
GeneralRe: would you rather? Pin
Sander Rossel28-Jul-19 21:31
professionalSander Rossel28-Jul-19 21:31 
GeneralRe: would you rather? Pin
NeverJustHere28-Jul-19 21:47
NeverJustHere28-Jul-19 21:47 
Personally, I'm a fan of generating code.

Think about a set of stored procs in a database that I want an application to be able to call. I have three alternatives:
1. I can write a common CallProc method, that calls any proc with an array of arguments
2. I can generate a single method for each one using the database metadata including typed arguments.
3. I can hand write number 2.

Clearly, option 3 is inefficient, from a developers time, the riskiest for defects.
Option 2 is the most extensible - no additional work is required to add a new proc to the system.
Option 1 presents the programmer calling procs with the nicest API. It is also likely to be the most performant (any performance tweaks coded in the others can be included in the generation templates)

Option 1 will be the largest code footprint, and an extra code generation step is required to generate the code, so ease of use depends on the level of support for this in the development environment

Hence I vote for 1.

It's almost a clarification to the DRY principle - Don't repeat yourself, have a code generator repeat yourself.
However for generation to be viable, the generated code must never be edited. This is why partial classes in c# and similar are almost essential.

The second part of the question, is if generation is to be used, what should the model be: DB source or code or external model.

Here we stumble into the classic 'impedance mismatch', The ideal database model does not correlate with the ideal code class structure. This mismatch is why people will hate code generation. Too many ORMs are simply mapping 1 table to 1 class. When generated from the code, the database structure is often sub-optimal and likewise the other way around.

There are parts of a code model difficult to express in a database model.

Hence I prefer external models, particularly in web development. I can define a data model, an api (with validation) and generate the database schema, the javascript/typescript side of the code, the server side of the code (in multiple languages).

What you end up with is essentially an independent development environment, so it can be taken too far.

I haven't done much with generating UI code yet - the partial class constraint tends to keep me from exploring this in detail..
GeneralRe: would you rather? Pin
honey the codewitch29-Jul-19 1:35
mvahoney the codewitch29-Jul-19 1:35 
GeneralRe: would you rather? Pin
lmoelleb28-Jul-19 22:07
lmoelleb28-Jul-19 22:07 
GeneralRe: would you rather? Pin
pkfox29-Jul-19 0:21
professionalpkfox29-Jul-19 0:21 
GeneralRe: would you rather? Pin
Marc Clifton29-Jul-19 2:53
mvaMarc Clifton29-Jul-19 2:53 
GeneralRe: would you rather? Pin
honey the codewitch29-Jul-19 3:03
mvahoney the codewitch29-Jul-19 3:03 
GeneralRe: would you rather? Pin
Mark_Wallace29-Jul-19 9:51
Mark_Wallace29-Jul-19 9:51 
GeneralRe: would you rather? Pin
honey the codewitch29-Jul-19 9:53
mvahoney the codewitch29-Jul-19 9:53 
GeneralRe: would you rather? Pin
Mark_Wallace29-Jul-19 11:35
Mark_Wallace29-Jul-19 11:35 
GeneralRe: would you rather? Pin
honey the codewitch29-Jul-19 11:44
mvahoney the codewitch29-Jul-19 11:44 
GeneralRe: would you rather? Pin
Mark_Wallace29-Jul-19 12:18
Mark_Wallace29-Jul-19 12:18 
GeneralRe: would you rather? Pin
honey the codewitch29-Jul-19 12:22
mvahoney the codewitch29-Jul-19 12:22 
GeneralRe: would you rather? Pin
Mark_Wallace29-Jul-19 12:26
Mark_Wallace29-Jul-19 12:26 
GeneralRe: would you rather? Pin
honey the codewitch29-Jul-19 12:29
mvahoney the codewitch29-Jul-19 12:29 
GeneralRe: would you rather? Pin
Mark_Wallace29-Jul-19 12:34
Mark_Wallace29-Jul-19 12:34 
GeneralC#: Can I trade var for typedef please? Pin
honey the codewitch28-Jul-19 9:31
mvahoney the codewitch28-Jul-19 9:31 
GeneralRe: C#: Can I trade var for typedef please? Pin
Mycroft Holmes28-Jul-19 11:48
professionalMycroft Holmes28-Jul-19 11:48 
GeneralRe: C#: Can I trade var for typedef please? Pin
honey the codewitch28-Jul-19 11:49
mvahoney the codewitch28-Jul-19 11:49 

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.