

- TOO LEGIT TOO LEGIT TO QUIT LOOP ANDROID
- TOO LEGIT TOO LEGIT TO QUIT LOOP SOFTWARE
- TOO LEGIT TOO LEGIT TO QUIT LOOP CODE
In C# do not execute extended or never-ending logic within constructors because. If you do not intend to use the object that you are "constructing" then what is the point of instantiating the object in the first place? Having a while(true) loop in a constructor effectively means you never intend for it to complete.Ĭ# is a very rich object oriented language with many different constructs and paradigms for you to explore, know your tools and when to use them, bottom line: You construct this object instance because it as a container that encapsulates a set of properties and functionality that you wish to call from the rest of your application logic.
TOO LEGIT TOO LEGIT TO QUIT LOOP CODE
If you feel the need to do this sort of code pattern, please use static methods on the class instead.Ī constructor exists to provide the initialisation logic when an object is instantiated from a class definition. +1 For least astonishment, but this is a hard concept to articulate to new devs.Īt a pragmatic level, it is hard to debug exceptions raised within constructors, if the object fails to initialise it will not exist for you to inspect the state of or log from outside of that constructor. And all the other reasons mentioned above.
TOO LEGIT TOO LEGIT TO QUIT LOOP ANDROID

What is wrong with the first approach? It returns 4 after a reasonably short amount of time it is correct. $sum_a = $sum_a + 0 # force it to be a number in case some non-digit characters managed to sneak in To finish with an analogy (another programming language, here the problem at hand is to calculate 2+2): $sum_a = `bash -c "echo $((2+2)) 2>/dev/null"` # calculate

Unfortunately, you regularly will meet programmers which are completely ignorant of all this. All of this is circumvented by stuff like this, where code is placed randomly because it "works".
TOO LEGIT TOO LEGIT TO QUIT LOOP SOFTWARE
Many/most modern improvements in software development methods are done specifically to make the actual process of writing/testing/debugging/maintaining software easier. But it will likely incur huge secondary costs (relative to the cost of writing the code initially) in the long run by making the code harder to maintain (i.e., hard to add tests, hard to reuse, hard to debug, hard to extend etc.). Nothing of this is a "bug" in the sense that your code does not work. It is certainly not well maintainable, future programmers will spend a lot of time trying to understand what is going on, and trying to guess reasons why it was done that way. It breaks the method contract (a constructor has a defined job and is not just some random method). It violates modern concepts of class design (cohesion, coupling).

It is unneccessary, unexpected, useless, unelegant. Is there something more obviously bad or devious with such an approach? Deriving from such a class is impossible or at least very complicated due to the fact that the base constructor never returns.The constructor actually never finishes, so what happens with GC here? Is this object already in Gen 0?.Technically such a class has no public members except the constructor, which makes it harder to understand (especially for languages where no implementation is available).The end of the loop (game end) is then conceptually the time where the constructor finishes, which is also odd.Unit tests are harder as you cannot create this class or inject it as it never exits the loop.like the principle of least astonishment, the user does not expect the constructor to behave like this.There are some concepts that are broken by this: Why (or is it at all?) regarded as bad design to let a constructor of a class start a never ending loop (i.e. Somebody asked me an interesting question which was for me not easily answered. Albeit a general question my scope is rather C# as I am aware that languages like C++ have different semantics regarding constructor execution, memory management, undefined behaviour, etc.
