openframeworks / openframeworks/openFrameworks

Constructors in openFrameworks

Open
#1,562 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

code-review core development-strategy
Dominant language
C++
Stars
10.4k
Forks
2.6k
Avg merge
1d 21h
Merged PRs (30d)
9

Description

We need a standardized approach to constructors.

The hardline answer is that there are only two types of constructors:

  • default constructors
  • copy constructors

This means that ofBuffer(const string) shouldn't exist, only ofBuffer::load(const string). That's kind of reasonable.

But it also means that ofRectangle(x,y,w,h) shouldn't exist, and that's unreasonable.

I think a good guideline is that if anything would be called load, init or setup, then it should be in a method, not a constructor. If something would be called set (simple data container) then it's ok to have a constructor.

What does everyone think? Should ofFile(string filename) exist? How about ofFile(string filename, bool binary)? How about ofImage(string filename)?

Code is cheap, but having more alternatives can make things harder to explain and more difficult to maintain, even when they're simple wrappers.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No files or tests are identified in the issue. Review the constructor examples for ofBuffer, ofRectangle, ofFile, and ofImage, then determine whether a consistent project-wide guideline can be agreed on; done means the API policy and its scope are documented or the issue is resolved.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend-api-design
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.