JoshOrndorff / LearnRholangByExample

Teaches rholang to beginners and intermediate programmers through hands-on examples and experimentation.
67 stars 32 forks source link

Use of new print(`rho:io:stdout`) is a poor suggested usage #19

Closed glenbraun closed 5 years ago

glenbraun commented 6 years ago

The code "new print(rho:io:stdout)" is a poor suggestion for usage. It creates another name for the same thing. A better pattern is: "new stdout(rho:io:stdout)"

Presumably, the pattern of rho:io:XYZ means that there will be more names at XYZ. Even the special prefix of "rho:io:" indicates there will be many more possible URI's. Creating a new name for each of these things is not a good practice.

I understand this is not technically wrong, the name that is mapped to the URI can be anything, but, if one were to have a program with tens of these names mapped (or if one used a library someday that used many tens of these), it would be much nicer to have a convention where the name used in the "new" is the same as at least the final portion of the URI. The usage of "new print(rho:io:stdout)" forces the user to understand two names: "stdout" (which is the real name of the functionality), and "print", something made up by this example. It implies that "print" is some system capability which it is not. One could imagine example code where "print" is used all over the code. Does the code mean some other name which happens to be called "print" or, is it really "rho:io:stdout".

I suggest changing the example to: "new stdout(rho:io:stdout)" and sticking with this pattern.

JoshOrndorff commented 6 years ago

Stylistic point well taken. Although I have seen this in code examples from the pyrofex people as well.

I think it's at least worth learners understanding that the assigned name can be arbitrary even if the best practice is to use stdout.

Anyone have thoughts on this suggestion? @dckc @pmoorman @zsluedem

JoshOrndorff commented 5 years ago

Resolved in 2257d7aab49e574.

I decided to keep a single case where I used a non-standard name to illustrate that it can be done, but added a note that it isn't always a good idea.