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

Prefix all declared function parameter list identifiers with a #264

Closed
Martii opened this issue Jul 14, 2014 · 19 comments
Closed

Prefix all declared function parameter list identifiers with a #264

Martii opened this issue Jul 14, 2014 · 19 comments
Labels
CODE Some other Code related issue and it should clearly describe what it is affecting in a comment. migration Use this to indicate that it may apply to an existing or announced migration.
Milestone

Comments

@Martii
Copy link
Member

Martii commented Jul 14, 2014

Applies to #262

@Martii Martii self-assigned this Jul 14, 2014
@Zren
Copy link
Contributor

Zren commented Jul 14, 2014

Wait, we're now using hungarian notation?

@Martii
Copy link
Member Author

Martii commented Jul 14, 2014

Not familiar with that term but this will clear up coding issues especially in between object names and identifiers. Stands for argument btw... similar to our r requirement for regular expressions.


This is a perfect example right where I'm at too:

strat: aStrat.name,

vs. what we have been doing of:

strat: strat.name,

The latter can confuse anything.

@sizzlemctwizzle
Copy link
Member

We're only prefixing function parameter names. Nothing else.
On Jul 14, 2014 4:09 PM, "Chris Holland" notifications@github.com wrote:

Wait, we're now using hungarian notation?


Reply to this email directly or view it on GitHub
#264 (comment)
.

@Martii
Copy link
Member Author

Martii commented Jul 14, 2014

We're only prefixing function parameter names. Nothing else.

Correct.

@Martii Martii changed the title Prefix all parameter lists with a Prefix all function parameter lists with a Jul 14, 2014
@Martii Martii changed the title Prefix all function parameter lists with a Prefix all declared function parameter list identifiers with a Jul 14, 2014
@Zren
Copy link
Contributor

Zren commented Jul 14, 2014

Oh, it's a strategy not array strategy. Hungarian notation prefixes the data type. Where a represents array.

In javascript, { key: value } key isn't executed. You have to use obj[keyName] to get/set using a variable. You could be more explicit about it by wrapping the key in quotes though. 'strat': strat.name

Martii pushed a commit to Martii/OpenUserJS.org that referenced this issue Jul 14, 2014
* Normalize `callback` and `cb` to `aCb`

Not finished yet but shown for @Zren to see what I'm doing

Applies to OpenUserJS#264
@Martii
Copy link
Member Author

Martii commented Jul 14, 2014

You have to use obj[keyName] to get/set using a variable

The main reason is for human readability... e.g. not having to figure out if it's a parm or an intermediate.

You could be more explicit about it by wrapping the key in quotes though.

That's probably something that could go into the STYLEGUIDE.md for sure.

@Zren
Copy link
Contributor

Zren commented Jul 14, 2014

That's probably something that could go into the STYLEGUIDE for sure.

If the key name is the same as a variable in the current scope or always?

@Zren
Copy link
Contributor

Zren commented Jul 14, 2014

This issue... has the sounds of the need to use an editor that you can set the color of parameters differently.

Martii pushed a commit to Martii/OpenUserJS.org that referenced this issue Jul 14, 2014
Applies to OpenUserJS#264 and d7465a3#commitcomment-7004333

> You don't use short forms (cb = callback) with verbose varible name standards.

Not explicitly declared the STYLEGUIDE** but can be used to accomodate those who don't know what the short term of a callback is... been debating on making a minimum length too. e.g. not one letter identfiers with a potential prefix.
@Martii
Copy link
Member Author

Martii commented Jul 14, 2014

or always?

Always... if this goes in there. Let me finish with this issue and we can discuss that change in another one.

This... has the sounds of the need to use an editor that you can set the color of parameters differently.

I won't be distracted from this issue by debating what editor is better than another. Thanks though.

@Zren
Copy link
Contributor

Zren commented Jul 14, 2014

My point was that it makes it harder to read these variables, rather than easier. Using a different syntax colour for parameters is the least intrusive on the codebase. Too many variables are using shortforms that using this style will break the point of using the shortform and force to be renamed.

Point me to another javascript codebase that does this.

@Martii
Copy link
Member Author

Martii commented Jul 14, 2014

Your point is exactly to compare editor highlighting capabilities and that is off topic.

I've made my share of not catching STYLEGUIDE.md mistakes and you and sizzle have as well... part of the issue mentioned yesterday (that you didn't comment on but you did comment (albeit in the wrong issue ticket) ) ... is that the code is unreadable both human and logically. A simple a prefix requirement is inherently more readable and will discover other mistakes in our code... I think I found one a few days ago and don't feel like digging it up to cite... because this issue needs to get done.

@Zren
Copy link
Contributor

Zren commented Jul 14, 2014

but you did comment

Didn't read the entire thread, I only skimmed it. It was about removing old code and existing consistency. Not new styleguide standards or so I thought.

inherently more readable

...

harder to read these variables

@Martii
Copy link
Member Author

Martii commented Jul 14, 2014

Didn't read the entire thread.

That's something for you to improve upon. I reread every comment every day on current issues... sometimes even the old ones to see what has changed.

can no longer use shortforms in parameters.

In relation to what? What are you talking about? There is no logic removal with this.

I think you need to ask yourself why are you fighting a standard naming change that many projects already have in place. It's not that difficult to ignore the a unless it's needed to determine bugs... in this case it is. Every point you've brought up is moot... we all need to know if there's a global being passed versus and intermediate. Anyways you've put in your vague vote, albeit late... I'm finishing this up and not going to get into this further.

@Zren
Copy link
Contributor

Zren commented Jul 14, 2014

many projects already have in place.

Name 1

@Martii
Copy link
Member Author

Martii commented Jul 14, 2014

... improve overall consistency

Not new styleguide standards or so I thought.

Name 1

The entirety of Mozilla (a few thousand or so). I'm done having you argue incessantly on this... I am more than willing to accommodate reasonable change given there is sufficient proof... which you haven't given at all for this.

@cletusc
Copy link
Contributor

cletusc commented Jul 15, 2014

Name 1

Greasemonkey, to name just one (for below, bolded is for arguments, italicized are points of interest):

Function and variable naming

Unless otherwise specified, use camelCasedNames.
Constants should be in UPPER_CASE.
Use InterCaps and capitalize the first letter of constructors.
Do not pollute the global namespace. Global (chrome window scoped) definitions should be avoided, but at least use a GM_ name prefix.
Global state variables should be prefixed with the letter g, e.g. gFormatToolbar.
Arguments (parameter names) should be prefixed with the letter a.
_Private members should start with _, e.g. internalFunction. They should not be accessed except by the class they are a member of.
Event handler functions should be prefixed with the word on, in particular try to use the names onLoad, onDialogAccept, onDialogCancel, etc., where this is unambiguous.
Function names, local variables, and object members have no prefix.
Try to declare local variables as near to their use as possible; initialize every variable.
Only declare a variable once in each scope.

Basically:

  • Arguments start with a
  • Privates start with _
  • Globals start with g
  • Event handlers start with on

It isn't System Hungarian notation, which is what you are thinking, but Apps Hungarian notation (System vs Apps Hungarian notation). Not everyone has a code editor that stylizes arguments different from other variables, nor should they be required. For example, Sublime doesn't know the difference between the two:

I am +0. Just quit spamming my inbox with petty arguments.

@Zren
Copy link
Contributor

Zren commented Jul 15, 2014

Apps Hungarian

Ah. The only ever project I've seen (system) hungarian is jQuery.DataTables, and they're moving away from it.

Proof

While our site is for userscript browser extensions like Greasemonkey, our site doesn't depend on it. They depend on us. The technologies we use don't use it.

Mozilla's style guide also has to deal with C++, and it makes sense for them to have a consistent style guide... I guess.

  • Looks Ugly

aErr, aCb, aRes, aRep, aNext

Short forms are now capitilzed and they look terrible.

  • Reads off as "a error" rather than "an error". Sure a = argument, but I shouldn't need to know that to read the code
  • Most functions should be small enough for you to see the function definition. If not, you should know the name of the function and it's arguments anyways.
  • Variable name that goes in != name defined for the argument.

Sublime doesn't know the difference between the two:

Your theme doesn't do it. It's possible to do as the scope is defined. Most themes don't do it as you don't normally need to treat arguments special.

Martii referenced this issue in Martii/OpenUserJS.org Jul 15, 2014
…ve libs to do.

* Changed "WARNING" on login page to "CAUTION"... a little too assertive... some users may want their email addy in there.
* Notated some STYLEGUIDE conformance needs
* Notated very short function name(s)
* At least one undefined identifier
Martii pushed a commit to Martii/OpenUserJS.org that referenced this issue Jul 15, 2014
@Martii
Copy link
Member Author

Martii commented Jul 15, 2014

Nearing completion.

A few areas are marked as Ambiguous because it is unclear on how to convert them because historically the STYLEGUIDE was not followed regarding unique identifier naming sequences. This is reason No. 1 for doing this... as a few of you haven't been paying attention to this much.

A few areas are also not in compliance with naming standards of not using $ ... some of those are notated.

Duplicate code for searching is historically present.

Have to run this through some final checks to see what is and isn't busted.

Known TODO:

  • Unflag script returns 404
    • EDIT: OH MY this is present on current pro too and should be a separate issue.
  • Still some aCb code in there... wasn't entirely sure if the nested async'd callbacks needed inner and outer designations.
    • EDIT: Going to do on separate issue.
  • One parm of flags is unclear to migrate... notated on line notes and ES comment
  • One parm of convert is unclear to migrate... notated on line notes and ES comment
    • EDIT: Not sure if this one is correct since original identifier was reused many times... can find by searching for Ambiguous in a comment.
  • All sizzles points regarding POST instead of GETs and moving things around.
  • Anything else missed.

@sizzlemctwizzle
Inconsistencies found:

  • Non unique naming of identifiers
  • Too simple of naming of identifiers sometimes.
  • No clear method of adding options to any part of any of the code... sometimes it's declared locally (as options) other times it is passed (as aOptions now), and sometimes it's just there... this is vague.
  • Usage of restricted characters such as $ for identifiers
  • Quite a bit of duplicated code... possibly dead code too... huge blocks of commented out code.
  • I saw a couple, as in very few, intermediates to abstract the function parms... this is probably okay but not consistent across the board. Notated some of them with // Intermediates.
  • Some future strict mode conflicts with inline functions not near the top of their parent function object. Not an issue right now but could throw an exception during future development. Didn't fix most of them. Needed for symmetry though especially for newer contributors.
  • Possible globals found.
  • Inconsistent naming of global identifiers between modules when using require()

@cletusc
Sorry for the noise. Thanks for linking/posting the GM guidelines. Adopting some more of that would be beneficial I think regardless of the acrimony shown towards the user.js engine standard from a comment from another collaborator. GM has done very nicely at keeping up to date over the past few years and having clearly readable code with checks in place is probably a contribution to its continued success.

Martii referenced this issue in Martii/OpenUserJS.org Jul 16, 2014
* At least 1 redundant/unreachable statement found

Applies to OpenUserJS#262

Also some uncaught OpenUserJS#255 because no code was executed before... but not doing all of these yet.
Martii pushed a commit to Martii/OpenUserJS.org that referenced this issue Jul 16, 2014
* Change/Add some more comments in for Ambiguous
* Remove some comments added as it appears they have been identified.
* Unified what comments I found that I added for 264.

Applies to OpenUserJS#264 as well
@Martii Martii added this to the #262 milestone Jul 16, 2014
Martii pushed a commit to Martii/OpenUserJS.org that referenced this issue Jul 16, 2014
@Martii
Copy link
Member Author

Martii commented Jul 24, 2014

Closed by #267

@Martii Martii closed this as completed Jul 24, 2014
@Martii Martii removed their assignment Jul 24, 2014
Martii pushed a commit to Martii/OpenUserJS.org that referenced this issue Jul 24, 2014
PLEASE TEST THOROUGHLY!

Applies to OpenUserJS#264
Martii pushed a commit to Martii/OpenUserJS.org that referenced this issue Nov 4, 2014
* Currently pro returns a 502 and dev returns the error when trying to submit a change to an OUJS collaboration... this *should* fix that... works on dev.

Refs:
* OpenUserJS#273
* OpenUserJS#264
Martii pushed a commit to Martii/OpenUserJS.org that referenced this issue Jan 25, 2015
* Missed Apps Hungarian notation from OpenUserJS#264
* Curly braces with newlines
Martii pushed a commit to Martii/OpenUserJS.org that referenced this issue Jan 30, 2015
* Basic statusCodePage for those users who are accidentally/intentionally putting in blank comments... applies to OpenUserJS#37
* Some missed Apps Hungarian from OpenUserJS#264 ... there's probably more. ;)
* Some STYLEGUIDE.md conformance with braces, newlines and indention
* Stray trailing comma fix
* Flip Cancel and Reply buttons... this may be some of the accidents with empty comments. Most likely when someone is going full screen they might be clicking reply on touch screens... favor canceling instead of replying if that's the case
Martii pushed a commit to Martii/OpenUserJS.org that referenced this issue Feb 17, 2016
* `a`Modelname indicates "live" Object document vs `a`ModelnameData indicates that `toObject()` is applied for plain JavaScript Object and is EXPECTED... the "old style" was due to lack of Hungarian Apps notation See OpenUserJS#264. There is inconsistency noted in the individual parsers here but leaving until further testing can be done
* Line length max 100 excluding TODO/NOTE/BUG comments as those should eventually go away
* Added some issue pounds to what needs to be done in these files
* More STYLEGUIDE.md conformance with newlines
* Top header style conformance previously done in controllers
* `var` hoisting as per STYLEGUIDE.md for ES5 coding

**NOTES**
* All of this should be a parallel change e.g. no logic changes
* Some *mu2* *(mustache)* `option`s appear unused... followup

Applies to OpenUserJS#819 and OpenUserJS#262... treads on OpenUserJS#262 (comment)
@OpenUserJS OpenUserJS locked as resolved and limited conversation to collaborators Apr 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
CODE Some other Code related issue and it should clearly describe what it is affecting in a comment. migration Use this to indicate that it may apply to an existing or announced migration.
Development

No branches or pull requests

4 participants