Skip to main content
added 261 characters in body
Source Link
freakish
  • 3.1k
  • 1
  • 11
  • 16

With this encapsulation, if something goes wrong you can be sure that the only place to search for a window related bug is the (hopefuly tiny) Window class. Not hundreds of thousands of lines of code that can potentially (mis)use it.

I'm sorry, but that's naive. Or maybe it depends on what you mean by "intentionally". But remember this: noone makes mistakes intentionally right? Yet, the number of bugs in the world is just overwhelming, even in most important projects like linux or openssl, which are developed by really skilled devs. 

You cannot trust yourself more than you can trust the others. Do you think you will remember in 3 months how exactly this API is supposed to be used? The bigger the project is, the harder it is to remember all the nuanced relationships between pieces of code. And more importantly: why would you even want to remember such things, considering that you can properly express that in the language you are using?

I'm sorry, but that's naive. You cannot trust yourself more than you can trust the others. Do you think you will remember in 3 months how exactly this API is supposed to be used? The bigger the project is, the harder it is to remember all the nuanced relationships between pieces of code. And more importantly: why would you even want to remember such things, considering that you can properly express that in the language you are using?

With this encapsulation, if something goes wrong you can be sure that the only place to search for a window related bug is the (hopefuly tiny) Window class. Not hundreds of thousands of lines of code that can potentially (mis)use it.

I'm sorry, but that's naive. Or maybe it depends on what you mean by "intentionally". But remember this: noone makes mistakes intentionally right? Yet, the number of bugs in the world is just overwhelming, even in most important projects like linux or openssl, which are developed by really skilled devs. 

You cannot trust yourself more than you can trust the others. Do you think you will remember in 3 months how exactly this API is supposed to be used? The bigger the project is, the harder it is to remember all the nuanced relationships between pieces of code. And more importantly: why would you even want to remember such things, considering that you can properly express that in the language you are using?

added 7 characters in body
Source Link
freakish
  • 3.1k
  • 1
  • 11
  • 16

Then you can be sure that youran instance of class Window encapsulates a valid pointer (because that is the only way to create it cannot be created otherwise). As long as you keep that invariant, you don't have to do nullptr checks anywhere else inside Window.

Then you can be sure that your class Window encapsulates a valid pointer (because it cannot be created otherwise). As long as you keep that invariant, you don't have to do nullptr checks anywhere else inside Window.

Then you can be sure that an instance of Window encapsulates a valid pointer (because that is the only way to create it). As long as you keep that invariant, you don't have to do nullptr checks anywhere else inside Window.

added 15 characters in body
Source Link
freakish
  • 3.1k
  • 1
  • 11
  • 16

I'm sorry, but that's naive. You cannot trust yourself more than you can trust the others. Do you think you will remember in 3 months how exactly this API is supposed to be used? The bigger the project is, the harder it is to remember all the nuanced relationships between pieces of code. And more importantly: why would you even want to remember such things, considering that you can properly express that in the language you are using?

The bigger the project is, the harder it is to understand how things interact with each other. So why don't you actually use C++ features to enforce (some) safety instead?

I'm sorry, but that's naive. You cannot trust yourself more than you can trust the others. Do you think you will remember in 3 months how exactly this API is supposed to be used? And more importantly: why would you even want to remember such things, considering that you can properly express that in the language you are using?

The bigger the project is, the harder it is to understand how things interact with each other. So why don't you actually use C++ features to enforce (some) safety instead?

I'm sorry, but that's naive. You cannot trust yourself more than you can trust the others. Do you think you will remember in 3 months how exactly this API is supposed to be used? The bigger the project is, the harder it is to remember all the nuanced relationships between pieces of code. And more importantly: why would you even want to remember such things, considering that you can properly express that in the language you are using?

added 15 characters in body
Source Link
freakish
  • 3.1k
  • 1
  • 11
  • 16
Loading
added 172 characters in body
Source Link
freakish
  • 3.1k
  • 1
  • 11
  • 16
Loading
added 97 characters in body
Source Link
freakish
  • 3.1k
  • 1
  • 11
  • 16
Loading
added 97 characters in body
Source Link
freakish
  • 3.1k
  • 1
  • 11
  • 16
Loading
added 97 characters in body
Source Link
freakish
  • 3.1k
  • 1
  • 11
  • 16
Loading
added 474 characters in body
Source Link
freakish
  • 3.1k
  • 1
  • 11
  • 16
Loading
added 474 characters in body
Source Link
freakish
  • 3.1k
  • 1
  • 11
  • 16
Loading
added 211 characters in body
Source Link
freakish
  • 3.1k
  • 1
  • 11
  • 16
Loading
Source Link
freakish
  • 3.1k
  • 1
  • 11
  • 16
Loading