Lusito / box2d.ts

Full blown Box2D Ecosystem for the web, written in TypeScript
https://lusito.github.io/box2d.ts
60 stars 6 forks source link

[Proposal] Remove `b2` prefix from all user-facing APIs #3

Closed DanielHZhang closed 1 year ago

DanielHZhang commented 3 years ago

I don't see a benefit of prefixing classes/methods/properties with b2, other than making the API more idiomatic to the original C++ implementation. If a user wants to prefix, they can choose to use a default/namespace import instead of named imports.

This would result in a less verbose, cleaner looking API:

With prefixing:

const gravity = new b2Vec2(0, 0);
const world = b2World.Create(gravity);
// or default import
const gravity = new Box2D.b2Vec2(0, 0);
const world = Box2D.b2World.Create(gravity);

Without prefixing:

const gravity = new Vec2(0, 0);
const world = World.Create(gravity);
// or default import
const gravity = new Box2D.Vec2(0, 0);
const world = Box2D.World.Create(gravity);

Using camelCase for class methods and property names would make the code even more idiomatic to Typescript, but that can be its own discussion.

Lusito commented 3 years ago

flyover seems to do something similar in his current master branch, removing the b2 prefixes.

I see your points, but that will also make the learning curve steeper and create more work when porting existing code.

Still undecided on both of these, but leaning towards a yes.

Lusito commented 3 years ago

I've created a new branch naming-convention, where I'm trying out these naming changes. Feel free to take a look and make suggestions.

What I've done so far:

I've focused mainly on the core project, so there are some leftovers in the other libs, where I haven't done the above yet.

It's in a branch, as I'm not entirely sure yet if this should be done. While this does look a lot nicer to work with, it will ultimately create lots of work on the documentation part, since we can't just reference the original documentation and say "This is the original documentation, check this page for differences".

Next up:

Lusito commented 3 years ago

Renamed methods to lowerCamelCase. That was a huge change and looking at how much work it was to port the testbed, I'm afraid this will prevent people from migrating from another js/ts box2d to this one, as it involves a lot of work.

ErikSom commented 2 years ago

My personal recommendation would be to keep it as close as possible to the original Box2D API, especially because the documentation is great and has been out their for a really long time. As a long time Box2D user it would be tedious to rethink casing and prefixing all the time.