Page 1 of 1

Small idea - class/method placeholders

PostPosted: Wed Mar 05, 2014 4:47 am
by hopscc
Just noted that building the compiler selfhosting (use it to build itself) generates 142 warnings for
Code: Select all
 warning: Encountered "pass" in a class that already has declared members.


This is due a warning on use of "pass" in a class that already has some box members defined
(CobraParser.cobra .classPass)
as in
class X is partial
pass
where class X is already declared something like

class X
def foo
print 'foo.'

def main is shared
x = X()
x.foo



This use seems to indicate a worthwhile doc mechanism so seems it might be worthwhile to allow this without warning if the class is declared partial which would allow the use of an explicit specification of a partial class as a placeholder for effort to be done later
i.e a placeholder/reminder for new named methods and fields to be implemented in the future
e.g.
class X is partial
pass # must implement the variant foo methods eventually


(ticket:367)

An alternative option would be to introduce a 'todo' or 'tobeimplemented' keyword that could be placed in such classes (same as pass) to note such use as temp placeholders with perhaps some trailing text ..
extend this for methods as well??

e.g.
class X is partial
todo : Implement variant foo methods and supporting fields
# 'todo keyword indicates class is placeholder, no code generated for it
# : precedes trailing text comment/doc following (aesthetic only)

class Y
def baz
pass
# empty method baz

def bar
todo
# placeholder for method bar - no code generated

def bar1
todo : needs to adjust for froz on goober
# placeholder for method bar1 - no code generated, additional trailing note


??

Re: Small idea - class/method placeholders

PostPosted: Sat Mar 08, 2014 9:39 pm
by Charles
Like other "partial" problems, such as being stuck with the "use" directives of the first "partial" type declaration, this is likely to be the outcome of Cobra implementing the partial types incorrectly. I have some progress on this, but have not sealed the deal due to some collateral damage around the treatment of method overloads.

Regarding the "todo" idea, I don't follow your idea of no code being generated for "bar1". What happens if bar1 is invoked somewhere? Error, warning, ...?

But most importantly there are many situations where you might be a "to-do" or other comment, and I'm not convinced there's value for adding this as language feature in some places.

Re: Small idea - class/method placeholders

PostPosted: Sun Mar 09, 2014 4:52 am
by hopscc
no code generated

For a method/class - no code for the contents ( same as pass is now as described earlier)

Effectively it looks like we are already using a combination of pass and possibly optional comment to do this already..
This is just to hoist that idea to make the use/idea obvious and explicit...

Its also possible/easier to extract classes methods so marked rather than a search on a notation convention in a comment

Re: Small idea - class/method placeholders

PostPosted: Sun Mar 09, 2014 11:02 am
by Charles
For annotating declarations, .NET attributes come to mind.

Re: Small idea - class/method placeholders

PostPosted: Tue Mar 11, 2014 4:05 am
by hopscc
Which more clearly communicates items to be implemented ??

class X is partial
todo : Implement variant foo methods and supporting fields

class Y has Humpty('wall')
def baz
pass

def bar has Dumpty('fall')
todo


vs

class X is partial has ToDo('Implement variant foo methods and supporting fields')

class Y has Humpty('wall')
def baz
pass

def bar has ToDo, Dumpty('fall')
pass

Re: Small idea - class/method placeholders

PostPosted: Tue Mar 11, 2014 9:35 am
by Charles
To compare them, I would add use the same formatting. Also, were you really planning that what follows the 'todo' would be bare characters instead of a string?

class X is partial
todo : 'Implement variant foo methods and supporting fields'

class X is partial
has ToDo('Implement variant foo methods and supporting fields')


Also, I know how to use reflection to get the info from the 2nd one if I want it programmatically. It's not clear how one would/could do so with the first.

Re: Small idea - class/method placeholders

PostPosted: Wed Mar 12, 2014 2:46 am
by hopscc
String or chars - either works

Why would you want to get Todo info from an executable ?.... Its a coding/Implementation thing.

Re: Small idea - class/method placeholders

PostPosted: Wed Mar 12, 2014 2:52 am
by hopscc
I would add use the same formatting


Even so, spot the additional cruft
What does 'has Todo' mean anyway....