miscon:programming.objects.constructor-returns-object · draft · trust low · v0.1.1 · kind overgeneralization
A constructor must return the object
A constructor creates the object and has to return it at the end, so a constructor without a return statement produces nothing.
- Stable URI
- https://open-misconceptions.github.io/miscon-data/m/programming.objects.constructor-returns-object
- UUID
82998d6e-dc24-425a-984e-e60d6a3b1de6- Domain
programming.objects- Level band
- secondary, undergraduate
- Locale
- en
- About
- https://open-misconceptions.github.io/miscon-data/c/programming.objects.constructor (Miscon)
Evidence patterns
Pattern 0: write a constructor
adds return this (or return self) at the end, or a return type to the constructor header
Write a constructor for Point that stores x and y.Point(int x, int y) { this.x = x; this.y = y; }Point Point(int x, int y) { this.x = x; this.y = y; return this; }Discriminators
vs a slip. A slip is a stray return removed when noticed. The belief is stated ('otherwise you don't get the object back') and the learner also expects new Point(1, 2) to be 'empty' without it.
Relations
conflicts_with- A constructor initialises an object the runtime has already created (external)
resolved_by- A constructor initialises an object the runtime has already created (external)
Alignments
- progmiscon Java/ConstructorReturnsObject (close-match)
- progmiscon Python/InitReturnsObject (close-match)
Provenance
Origin: llm-drafted
- Chiodini, L., Moreno Santos, I., Gallidabino, A., Tafliovich, A., Santos, A. L., & Hauswirth, M. (2021). A curated inventory of programming language misconceptions. In Proceedings of the 26th ACM Conference on Innovation and Technology in Computer Science Education (ITiCSE '21), 380-386. doi:10.1145/3430665.3456343
Inventory consulted for the misconception name and scope only; progmiscon publishes no licence for its text, so Open Misconceptions' statements and examples are written independently. - Ragonis, N., & Ben-Ari, M. (2005). A long-term investigation of the comprehension of OOP concepts by novices. Computer Science Education, 15(3), 203-221. doi:10.1080/08993400500224310
Novice comprehension of constructors and object creation.
Drafted from the cited literature for the Open Misconceptions seed pack; statement, examples and discriminators are original text. Awaiting maintainer review.
Review status
Status draft, trust low (computed from the reviews below against the reviewer registry).
No reviews yet.
Formats
- Raw JSON
- CASE 1.1 package (CFItem
82998d6e-dc24-425a-984e-e60d6a3b1de6) - Source on GitHub
Cite
miscon:programming.objects.constructor-returns-object
https://open-misconceptions.github.io/miscon-data/m/programming.objects.constructor-returns-object