Click here to Skip to main content
15,887,175 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
Jeremy Falcon25-Sep-23 12:33
professionalJeremy Falcon25-Sep-23 12:33 
GeneralRe: The changing landscape of OOP (from class to struct) Pin
Jon McKee26-Sep-23 9:51
professionalJon McKee26-Sep-23 9:51 
GeneralRe: The changing landscape of OOP (from class to struct) Pin
Jeremy Falcon27-Sep-23 2:36
professionalJeremy Falcon27-Sep-23 2:36 
GeneralRe: The changing landscape of OOP (from class to struct) Pin
Jon McKee28-Sep-23 14:17
professionalJon McKee28-Sep-23 14:17 
GeneralRe: The changing landscape of OOP (from class to struct) Pin
Richard Deeming25-Sep-23 22:02
mveRichard Deeming25-Sep-23 22:02 
GeneralRe: The changing landscape of OOP (from class to struct) Pin
trønderen26-Sep-23 9:31
trønderen26-Sep-23 9:31 
GeneralRe: The changing landscape of OOP (from class to struct) Pin
Jeremy Falcon27-Sep-23 3:17
professionalJeremy Falcon27-Sep-23 3:17 
GeneralRe: The changing landscape of OOP (from class to struct) Pin
RainHat26-Sep-23 0:02
RainHat26-Sep-23 0:02 
He failed step 3. Angle is not very well implemented, as it does not specify what unit it uses. Either call it Radians, or specify the unit in the constructor and getter.

Ironically, this could possibly be implemented by inheritance. Angle being the base class and Degrees, Radians, Turns and Gons (optionally Longitude and Latitude) being the sub classes, although this would force it to be a class.

As implemented the client of this function could still create an angle of 90 (thinking degrees) and pass this in and get a point at 90 radians.

I agree that is is a good idea to make structs immutable. I have seen so many bugs caused by trying to alter a Point or Size but the code is altering a copy, not the original.

Is implementing structs for these a good idea? Possibly. I have implemented Angle as a class before - mainly for user display. I have also just used angleDegrees and angleRadians. Choose wisely.
The advantages are it forces the correct type to be passed in.
The disadvantages are a little bit of speed and extra code.
Would naming the angle as angleRadians be enough to eliminate most errors?
Do we need explicit casts on Radians so we can use (Radians)Math.PI?

Personally I prefer a plain double, named well, although an explicit type can be useful.
GeneralRe: The changing landscape of OOP (from class to struct) Pin
charlieg26-Sep-23 7:42
charlieg26-Sep-23 7:42 
GeneralRe: The changing landscape of OOP (from class to struct) Pin
trønderen26-Sep-23 9:47
trønderen26-Sep-23 9:47 
GeneralRe: The changing landscape of OOP (from class to struct) Pin
Nelek27-Sep-23 9:12
protectorNelek27-Sep-23 9:12 
GeneralRe: The changing landscape of OOP (from class to struct) Pin
haughtonomous26-Sep-23 21:11
haughtonomous26-Sep-23 21:11 
PraiseRe: The changing landscape of OOP (from class to struct) Pin
Jeremy Falcon27-Sep-23 4:17
professionalJeremy Falcon27-Sep-23 4:17 
GeneralRe: The changing landscape of OOP (from class to struct) Pin
Peter Adam26-Sep-23 22:20
professionalPeter Adam26-Sep-23 22:20 
GeneralRe: The changing landscape of OOP (from class to struct) Pin
Richard Deeming26-Sep-23 23:13
mveRichard Deeming26-Sep-23 23:13 
GeneralRe: The changing landscape of OOP (from class to struct) Pin
haughtonomous3-Oct-23 21:33
haughtonomous3-Oct-23 21:33 
GeneralRe: The changing landscape of OOP (from class to struct) Pin
Steve Naidamast27-Sep-23 4:19
professionalSteve Naidamast27-Sep-23 4:19 
GeneralRe: The changing landscape of OOP (from class to struct) Pin
raddevus27-Sep-23 8:51
mvaraddevus27-Sep-23 8:51 
GeneralRe: The changing landscape of OOP (from class to struct) Pin
haughtonomous3-Oct-23 21:40
haughtonomous3-Oct-23 21:40 
GeneralRe: The changing landscape of OOP (from class to struct) Pin
John Chadwell27-Sep-23 4:40
John Chadwell27-Sep-23 4:40 
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 

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.