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

cleaned up address.js and util.js #96

Merged
merged 1 commit into from
Mar 28, 2014
Merged

cleaned up address.js and util.js #96

merged 1 commit into from
Mar 28, 2014

Conversation

ralphtheninja
Copy link
Contributor

Two space indentation, got rid of semi colons and some refactoring. Tests pass. Are you people ok with this format?

}

/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abrkn thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ralphtheninja I agree. I think I moved it out of HD because I was used somewhere else at some point. Any suggestion for a better name?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ralphtheninja Could you remove the comments on this function? I don't want to put opinions into the code, I think this is better as a github issue or pull request. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! I'll remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a better name for it. Need to read some more code and look at how it's used to have an opinion. I'll add a PR on it later.

@symaxian
Copy link
Contributor

Has it been decided to not use semicolons? I would expect the opposite.

@kyledrake
Copy link
Contributor

@symaxian It has been decided to not use semicolons, correct.

@symaxian
Copy link
Contributor

I was under the assumption that they're highly highly recommended, especially for what needs to be "hardened" software. Is there a discussion of this posted on Github or somewhere else?

@kyledrake
Copy link
Contributor

They're not highly recommended, they are almost always unnecessary.

http://mislav.uniqpath.com/2010/05/semicolons/
http://blog.izs.me/post/2353458699/an-open-letter-to-javascript-leaders-regarding
https://twitter.com/substack/status/259296905807417344

I've been given the green light by the other commiters to set a style for bitcoinjs-lib and I have decided that we will not use them. If there's an fringe semicolon issue it will almost certainly be caught by the tests (in node.js or the browsers with testling). You will find a lot of mission-critical software in node.js that do not have semicolons. Removing them is quickly becoming a standard in the JS community.


Address.getVersion = function(string) {
return base58.decode(string)[0];
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of the empty comment area?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for symmetry :) I can remove it if you wish.

@ralphtheninja
Copy link
Contributor Author

Updated. Also rebased it against the latest master, so no multiple rail road tracks in the git history :)

  1. Moved the Hmac thingie back to hdwallet
  2. Added comments for empty comment areas.
  3. Changed some parameters from 'string' to 'address' for clarity.

Just noticed the tests are up to 130 now. Nice work! I'm gonna go through some code and see if there are any methods that needs testing.

@ralphtheninja
Copy link
Contributor Author

Note that this changes the api, since we no longer export the HmacFromBytesToBytes. I hope this doesn't cause any trouble.

: bytes.length <= 40 ? convert.hexToBytes(bytes)
: util.error('invalid or unrecognized input');
/**
* Address constructor. Call it with new, or don't.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove this comment? After that I think we're golden. Thanks!

@ralphtheninja
Copy link
Contributor Author

Actually. How about changing the 'bytes' parameter to 'address'? Because that's what it is.

@weilu
Copy link
Contributor

weilu commented Mar 28, 2014

The address constructor is overloaded -- it accepts bytes, Address and string. I'd like to move away from overloaded constructors and instead towards empty(or bytes arguments) for constructors, and turn the other forms into separate class methods. An example where this is implemented is hdwallet.js https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/src/hdwallet.js#L39-L45

weilu added a commit that referenced this pull request Mar 28, 2014
cleaned up address.js and util.js
@weilu weilu merged commit 0ce14a7 into bitcoinjs:master Mar 28, 2014
@dcousens
Copy link
Contributor

@weilu completely agree with removing the overloaded constructors.

@dcousens dcousens mentioned this pull request Mar 28, 2014
@ralphtheninja
Copy link
Contributor Author

+1 for removing overloaded constructors. It makes the code much harder to understand if a parameter can be many different things.

@symaxian
Copy link
Contributor

I agree as to the overloaded constructors, the explicit instance methods would result in more readable code.

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

Successfully merging this pull request may close these issues.

None yet

5 participants