Home AMX User Forum NetLinx Studio

To paren, or not to paren, that is the question

I’m reading thru someone else’s code and I see a bunch of functions that require no parameters that are defined like this:
DEFINE_FUNCTION aFunction 
{
}

I’ve always done it this way regardless of the existence of parameters:
DEFINE_FUNCTION aFunction()
{
}

I didn’t know the parens were optional. Do you drop the parens if you declare a function with no parameters? It just looks wrong to me but maybe it’s just me. Curious what the standard is…

Comments

  • viningvining Posts: 4,368
    Hmmm, never came across that either and I agree it just looks wrong. I would stay with ().
  • mpullinmpullin Posts: 949
    When code goes bad that's the first question that always gets asked. "Where were the parens?"
  • ericmedleyericmedley Posts: 4,177
    That doesn't work in any if the other development environments I'm aware of. But heck, Axcess used to let you get away with murder. I'm probably the other end of the spectrum. I use more parentheses and curly braces than necessary. It just helps me visually
  • DHawthorneDHawthorne Posts: 4,584
    If only for clarity reading it later, I would include the empty parentheses.
  • ericmedleyericmedley Posts: 4,177
    This would be nice...

    define_function beHappy:){

    }
  • a_riot42a_riot42 Posts: 1,624
    ericmedley wrote: »
    That doesn't work in any if the other development environments I'm aware of. But heck, Axcess used to let you get away with murder. I'm probably the other end of the spectrum. I use more parentheses and curly braces than necessary. It just helps me visually

    In PERL you can either have them or not as well. I think if you use empty parentheses, it says that you thought about the parameters, and decided there should be none. Without them, you don't know if they should be no parameters or the programmer just forgot. Plus if you use them and then need to add parameters later, a find and replace is easy from () to (integer idx). Otherwise its impossible and would have to be done by hand.
    Paul
Sign In or Register to comment.