Comments (6)
I'd vote for 1. If we provide the users with the option to pass an options object or still use arguments, it might confuse them further. The user will still have all the same questions when they see a bunch of arguments passed into a function plus now they'll also encounter some code that passes an object instead. The only thing option 2 really does is reduces the amount of code we have to change :).
If we go for option 2, we would have an argument (presumably first one) to a function that can possibly represent all remaining arguments, but doesn't have to:
function (optionsOrArg1, arg2, arg3, arg4) {
if optionsOrArg1 is an object
take the values from it
else
use all the arguments
// But what if arg1 being an object is a valid value?
// Then how to even determine if user passed the options obj?
}
IMHO, this solution won't make it easier on the users to use Tracers more than option 1. Also the complexity of coding it and handling all of its cases, plus the possible future complications it can cause, don't make it worth it.
Now I understand option 1 is to update every algorithm we have, but the updates are small, and with the nice text editors we all have today, finding and replacing is pretty easy :)
I think making a full switch to an options object is the way to go and here's a nice SO answer to back me up :)
from algorithm-visualizer.
hmm, my primary assumption was that we would never encounter a scenario where the first of the 4 arguments could be valid if it were an object. So the first arg would either be an object (which means ignore any other args) or it would be a Number (then don't ignore the other 3). In that case, something like this would've sufficed:
function f () {
if (typeof arguments [0] === 'object')
var {N, ratio, max, min} = arguments [0];
//proceed to use N min max ratio as normal..
//like you mentioned above
}
plus we could specify usage in wiki. but then again, it might be a possibility in future
But I think your argument is convincing enough, so yah 1's good!
from algorithm-visualizer.
Love this idea!
from algorithm-visualizer.
So are we going to:
- Change the API to only support object passing and make appropriate changes in all the visualizations written till now or,
- Update the API to support both passing of object & individual parameters so the previous code can continue to exist as-it-is and new code can exploit this functionality
?
(I'm in favor of the second one)
from algorithm-visualizer.
Yeah, that all makes sense, but I think our final goal should be to eliminate arguments completely and make a full switch to using an options object. Option 2 can be a temporary solution thought. We can add that so the app still works while we update all the algorithms overtime.
from algorithm-visualizer.
I recently revised the randomizers as @nem035 suggested (3 years and a day ago already!), and now they look like this:
const array2d = Randomize.Array2D({
N: 5,
M: 4,
sorted: false,
value: () => Randomize.String({ length: 4 })
});
Here is the new documentation about it.
from algorithm-visualizer.
Related Issues (20)
- Need Support for C/C++ as well HOT 2
- please make a c++
- quite wide
- Check the certificate for tracer.js HOT 1
- C language HOT 2
- Algo HOT 2
- CONTRIBUTING.md file content doesn't match its purpose HOT 1
- Will this project continue to be maintained?
- 堆排序算法的可视化不是很好,应该把树画出来
- 如果有红黑树就好了
- how to run this project on local pc HOT 2
- is it possible Support for C/C++ ,if i have set this project run on my local ubuntu 22.04
- need a API demo(or example)? HOT 2
- linux上部署不成功,有大佬部署成功的吗? HOT 5
- How to use these? HOT 3
- Update readme HOT 2
- Bro your website is not opening is saying it is no safe
- Algorithm-Visualizer HOT 2
- Support markdown? HOT 1
- buatlah program yang terdiri dari 3 combo box di dalam nya ada combo makanan minuman dan sayuran satu button dan satu text field ketika button di klik maka dari ketiga combo tersebut di tampilkan dalam satu text field HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from algorithm-visualizer.