Code Monkey home page Code Monkey logo

Comments (6)

nem035 avatar nem035 commented on May 4, 2024 1

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.

duaraghav8 avatar duaraghav8 commented on May 4, 2024 1

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.

64json avatar 64json commented on May 4, 2024

Love this idea!

from algorithm-visualizer.

duaraghav8 avatar duaraghav8 commented on May 4, 2024

So are we going to:

  1. Change the API to only support object passing and make appropriate changes in all the visualizations written till now or,
  2. 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.

nem035 avatar nem035 commented on May 4, 2024

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.

64json avatar 64json commented on May 4, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.