Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

goals and style in user-facing code #22

Open
kybr opened this issue Mar 5, 2019 · 3 comments
Open

goals and style in user-facing code #22

kybr opened this issue Mar 5, 2019 · 3 comments

Comments

@kybr
Copy link
Member

kybr commented Mar 5, 2019

i would like to start a conversation about our goals and style in user-facing code (i.e., examples). i've sketched out some of my position in the comments of this refactored example:

https://github.com/AlloSphere-Research-Group/allolib/blob/style_opinions/examples/ui/dynamic_scene.cpp

@grrrwaaa
Copy link
Member

grrrwaaa commented Mar 5, 2019

I'm lurking, but can I just say that I entirely agree with these comments and the rationales.

@mantaraya36
Copy link
Contributor

mantaraya36 commented Mar 5, 2019 via email

@kybr kybr closed this as completed Mar 20, 2019
@kybr
Copy link
Member Author

kybr commented Mar 20, 2019

sorry. i sent that before it was done.

while students have not complained about this usage of <<, they do struggle with << and >> generally.

in c++ >> and << mean "shift bits right" and "shift bits left". they also mean "pull from stream" and "append to stream" respectively. neither of these usages have any basis is math where they mean "much greater than" and "much less than". this last meaning would make some sense to a person new to programming.

c++ "stream" i/o makes use of << and >>. that's the usage that new students come across (and struggle with) first. IMHO, c++ stream i/o is awful. take a poll of nearby c++ users and see how many favor printf! it's atomic, well-documented, and ubiquitous. i avoid using the >> and << operators for anything other than bitshifting. IMHO it is a mistake that our OSC implementation uses >> (e.g., Message m; float f; m >> f;) New students struggle with >> and << when used in the traditional c++ contexts: stream i/o and bit-shifting. so let's not introduce a new meaning and usage for >> and << in user code.

in this use, << is put forward as a shortcut for adding parameters to a gui. +=, +, or .reg() (with chaining) would work just as well. there is nothing in << that suggests it is natural or obvious to use it to add a parameter to a gui. any operator in this case would be less readable (IMHO) than a method such as .reg or .add. if the point is to save typing, we could use variadic template function to allow something like .add(p1, p2, p3, p4, p5).

let's please leave << and >> for bit shifting and stream operations.

@kybr kybr reopened this Mar 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants