Click here to Skip to main content
15,886,919 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: The changing landscape of OOP (from class to struct) Pin
raddevus27-Sep-23 8:54
mvaraddevus27-Sep-23 8:54 
GeneralRe: The changing landscape of OOP (from class to struct) Pin
Choroid27-Sep-23 5:51
Choroid27-Sep-23 5:51 
GeneralRe: The changing landscape of OOP (from class to struct) Pin
Leonardo Pessoa27-Sep-23 8:19
Leonardo Pessoa27-Sep-23 8:19 
GeneralRe: The changing landscape of OOP (from class to struct) Pin
raddevus27-Sep-23 9:02
mvaraddevus27-Sep-23 9:02 
GeneralRe: The changing landscape of OOP (from class to struct) Pin
Juan Pablo Reyes Altamirano27-Sep-23 8:31
Juan Pablo Reyes Altamirano27-Sep-23 8:31 
GeneralRe: The changing landscape of OOP (from class to struct) Pin
raddevus27-Sep-23 9:08
mvaraddevus27-Sep-23 9:08 
GeneralRe: The changing landscape of OOP (from class to struct) Pin
Nelek27-Sep-23 9:26
protectorNelek27-Sep-23 9:26 
GeneralRe: The changing landscape of OOP (from class to struct) Pin
ChristianLavigne29-Sep-23 2:33
professionalChristianLavigne29-Sep-23 2:33 
I would not say it's a new concept, DDD introduced the concept of value objects a while back. Strong typing a value is how many implement value objects in C#.

The logical continuation for this concept should be:

1- Add validation, what is the specific range of value that are acceptable to your function. In your example, should you accept a speed of 62123.25?

2- Add units, is it always the same unit, or should you convert from different units?

3- Displacement, Angle, Speed are very vague, are we talking about vehicles on a public road? or a spacecraft? Maybe we should use VehicleSpeed instead?

4- Maybe VehicleSpeed should derive from a base Speed class so you don't repeat units and conversions all the time? But you could add validation of acceptable speed value for a vehicle?

And we're back to the good old OOP. Should you calculate the Displacement in the VehicleSpeed class? I don't think so, this should be composition, but the encapsulation of the speed value, it's units and validation into a class is definitely desirable.

It is a question of perspective. We tend to work with good enough, but if you want accuracy, I would debate that those are the things you NEED to do.

The reasons why most of us don't go the Value Object route are: That's a lot of work. It takes time, we're in a hurry, it makes code base bigger, some would say more complex (I disagree).

Is Primitive Obsession a code smell? I say YES! But are we willing and able to do everything that is required to REALLY fix it?
Christian

GeneralRe: The changing landscape of OOP (from class to struct) Pin
raddevus29-Sep-23 10:15
mvaraddevus29-Sep-23 10:15 
GeneralRe: The changing landscape of OOP (from class to struct) Pin
PIEBALDconsult29-Sep-23 9:33
mvePIEBALDconsult29-Sep-23 9:33 
GeneralRe: The changing landscape of OOP (from class to struct) Pin
honey the codewitch4-Oct-23 4:56
mvahoney the codewitch4-Oct-23 4:56 
RantThe Day I Learned to Deal With the BOM Pin
kmoorevs15-Sep-23 9:21
kmoorevs15-Sep-23 9:21 
GeneralRe: The Day I Learned to Hate the BOM Pin
trønderen15-Sep-23 9:53
trønderen15-Sep-23 9:53 
GeneralRe: The Day I Learned to Hate the BOM Pin
kmoorevs17-Sep-23 12:25
kmoorevs17-Sep-23 12:25 
GeneralRe: The Day I Learned to Hate the BOM Pin
PIEBALDconsult20-Sep-23 12:20
mvePIEBALDconsult20-Sep-23 12:20 
GeneralRe: The Day I Learned to Deal With the BOM Pin
Richard MacCutchan17-Sep-23 22:03
mveRichard MacCutchan17-Sep-23 22:03 
GeneralRe: The Day I Learned to Deal With the BOM Pin
PIEBALDconsult20-Sep-23 12:18
mvePIEBALDconsult20-Sep-23 12:18 
GeneralRe: The Day I Learned to Deal With the BOM Pin
honey the codewitch4-Oct-23 4:59
mvahoney the codewitch4-Oct-23 4:59 
Generaljsfiddle nightmare: Schrodinger's lost code Pin
raddevus4-Aug-23 4:45
mvaraddevus4-Aug-23 4:45 
GeneralRe: jsfiddle nightmare: Schrodinger's lost code Pin
Richard Deeming4-Aug-23 4:49
mveRichard Deeming4-Aug-23 4:49 
GeneralRe: jsfiddle nightmare: Schrodinger's lost code Pin
raddevus4-Aug-23 4:59
mvaraddevus4-Aug-23 4:59 
PraiseRe: jsfiddle nightmare: Schrodinger's lost code Pin
Slacker00729-Aug-23 6:43
professionalSlacker00729-Aug-23 6:43 
GeneralRe: jsfiddle nightmare: Schrodinger's lost code Pin
Gary R. Wheeler7-Sep-23 13:01
Gary R. Wheeler7-Sep-23 13:01 
JokeRe: jsfiddle nightmare: Schrodinger's lost code Pin
Peter_in_27807-Sep-23 13:15
professionalPeter_in_27807-Sep-23 13:15 
GeneralRe: jsfiddle nightmare: Schrodinger's lost code Pin
Richard Deeming7-Sep-23 21:32
mveRichard Deeming7-Sep-23 21:32 

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.