Skip to main content
September 12, 2013
Question

Function value arguements vs struct arguement

  • September 12, 2013
  • 1 reply
  • 1035 views

In a function is it better to define 4 arguements of type string, or one single arguement of type struct that contains these values?

    This topic has been closed for replies.

    1 reply

    Participating Frequently
    September 12, 2013

    That depends really on your requirements.  There's no de facto standard in ColdFusion AFAIK.  Does the data make more sense as a single structure, or are they 4 independent strings that should be on their own?  e.g. if it was something like a customer record, it might make sense as a structure:

    doStuff(

      customer = {

        firstname: "Joe",

        lastname: "Bloggs",

        title: "Sir",

        greeting: "Hi "

      }

    );

    Whereas you might have 4 values that aren't really all about one thing, e.g.

    doStuff(

      pageTitle= "Hello World",

      cssFile= "/path/to/file.css",

      customerEmail= "info@example.com",

      today= dateFormat(now())

    );

    Which would also be fine (apart from the wisdom of having a function requiring such disparate arguments)

    September 12, 2013

    I am talking from a speed and performance. Because I am going to be doing this a lot of times for a lot of users.

    Inspiring
    September 12, 2013

    It will not make a performance difference. Aim for what is semantically the best code.

    As Duncan said... are the strings in any way related? SHould they be perhaps properties of an object, not individual values, or even a struct.  EG: if two of them are firstName and lastName, they perhaps would be better as a single object name.

    If you really do need to pass four separate arguments to a function... there's a a chance your function is doing too much. What's an example of the function being called? (ie: show us the code).

    --

    Adam