What should convention be regarding methods which take no arguments. To keep things simple my suggestion is that all methods with no arguments leave the parens off always:
**
** Return the next token in the buffer.
**
TokenVal next()
{
while (true)
{
TokenVal tok := find
if (tok == null) continue
return tok
}
return null
}
**
** Find the next token or return null.
**
private TokenVal find()
{
// skip whitespace
if (cur.isSpace) { consume; return null }
// alpha means keyword or identifier
if (cur.isAlpha || cur === '_') return word
// number or .number (note that + and - are handled as unary operator)
if (cur.isDigit) return number
if (cur === '.' && peek.isDigit) return number
// str literal
if (cur === '"') return str
if (cur === '\'') return ch
// comments
if (cur === '*' && peek === '*') return docComment
if (cur === '/' && peek === '/') return skipCommentSL
if (cur === '/' && peek === '*') return skipCommentML
// symbols
return symbol
}
andyTue 23 May 2006
I agree. The only time you would use parens is if you are explicitly calling a getter() from inside the class - which is something we may always want to comment to make that clear?
brianSun 28 May 2006
I changed my mind. I think if you are calling a method with no target (implicit this or static on my own class) then you should include the parens. You can leave the parens off if chaining via the dot operator.
consume()
tokenizer.consume
Still not sure what I like best, but I don't think I like leaving them off when there is no dot operator - plus it ends up requiring a semicolon right now the way I have the grammar structured.
andySun 28 May 2006
I think I still lean toward the original way, so in that case neither would have parens.
brian Tue 23 May 2006
What should convention be regarding methods which take no arguments. To keep things simple my suggestion is that all methods with no arguments leave the parens off always:
andy Tue 23 May 2006
I agree. The only time you would use parens is if you are explicitly calling a getter() from inside the class - which is something we may always want to comment to make that clear?
brian Sun 28 May 2006
I changed my mind. I think if you are calling a method with no target (implicit this or static on my own class) then you should include the parens. You can leave the parens off if chaining via the dot operator.
Still not sure what I like best, but I don't think I like leaving them off when there is no dot operator - plus it ends up requiring a semicolon right now the way I have the grammar structured.
andy Sun 28 May 2006
I think I still lean toward the original way, so in that case neither would have parens.