www.digitalmars.com         C & C++   DMDScript  

D - Downside of the absence of headers

reply Mik Mifflin <mik42 NOadelphiaSPAM.net> writes:
Many programmers loathe to document their code.  When looking at
undocumented C++ code, it's easy enough to open up a header file to get a
good idea of what a class does and how it works.  Though, it's not so easy
in D.  Sun Java (which also has no header files, for the Java impaired) has
the javap program, which allows you to take a peek into classes, and is a
handy way to get the interface and even private methods and variables.

Has anyone written a parser to dump the interface of a D class?

-- 
 - Mik Mifflin
Feb 21 2004
next sibling parent reply SpookyET <not4_u hotmail.com> writes:
In .net is even better, assemblies (.exe, .dll) have metadata about the  
types (including comments about those properties/methods (xml  
documentation)) (just like in mp3s). And you can look at those super easy,  
there are apps for that.

On Sat, 21 Feb 2004 19:56:19 -0500, Mik Mifflin <mik42 NOadelphiaSPAM.net>  
wrote:

 Many programmers loathe to document their code.  When looking at
 undocumented C++ code, it's easy enough to open up a header file to get a
 good idea of what a class does and how it works.  Though, it's not so  
 easy
 in D.  Sun Java (which also has no header files, for the Java impaired)  
 has
 the javap program, which allows you to take a peek into classes, and is a
 handy way to get the interface and even private methods and variables.

 Has anyone written a parser to dump the interface of a D class?
-- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Feb 21 2004
parent reply Mik Mifflin <mik42 NOadelphiaSPAM.net> writes:
SpookyET wrote:

 In .net is even better, assemblies (.exe, .dll) have metadata about the
 types (including comments about those properties/methods (xml
 documentation)) (just like in mp3s). And you can look at those super easy,
 there are apps for that.
 
 On Sat, 21 Feb 2004 19:56:19 -0500, Mik Mifflin <mik42 NOadelphiaSPAM.net>
 wrote:
 
 Many programmers loathe to document their code.  When looking at
 undocumented C++ code, it's easy enough to open up a header file to get a
 good idea of what a class does and how it works.  Though, it's not so
 easy
 in D.  Sun Java (which also has no header files, for the Java impaired)
 has
 the javap program, which allows you to take a peek into classes, and is a
 handy way to get the interface and even private methods and variables.

 Has anyone written a parser to dump the interface of a D class?
I thought we just went over this... D is not .net -- - Mik Mifflin
Feb 21 2004
parent reply SpookyET <not4_u hotmail.com> writes:

closed minded.


On Sat, 21 Feb 2004 20:19:11 -0500, Mik Mifflin <mik42 NOadelphiaSPAM.net>  
wrote:

 SpookyET wrote:

 In .net is even better, assemblies (.exe, .dll) have metadata about the
 types (including comments about those properties/methods (xml
 documentation)) (just like in mp3s). And you can look at those super  
 easy,
 there are apps for that.

 On Sat, 21 Feb 2004 19:56:19 -0500, Mik Mifflin  
 <mik42 NOadelphiaSPAM.net>
 wrote:

 Many programmers loathe to document their code.  When looking at
 undocumented C++ code, it's easy enough to open up a header file to  
 get a
 good idea of what a class does and how it works.  Though, it's not so
 easy
 in D.  Sun Java (which also has no header files, for the Java impaired)
 has
 the javap program, which allows you to take a peek into classes, and  
 is a
 handy way to get the interface and even private methods and variables.

 Has anyone written a parser to dump the interface of a D class?
I thought we just went over this... D is not .net
-- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Feb 21 2004
parent "KTC" <me here.com> writes:
"SpookyET" wrote...

be
 closed minded.
At the same time, one could easily argued you're the one who's closed minded here... One has to consider what's good and bad about a feature and it's implication on the rest of the language before one decide to include it. Otherwise, you'll just end up with something unusable even if all the indivual features have its merit. KTC -- Experience is a good school but the fees are high. - Heinrich Heine
Feb 22 2004
prev sibling next sibling parent reply "Ben Hinkle" <bhinkle4 juno.com> writes:
"Mik Mifflin" <mik42 NOadelphiaSPAM.net> wrote in message
news:c18unj$7fq$1 digitaldaemon.com...
| Many programmers loathe to document their code.  When looking at
| undocumented C++ code, it's easy enough to open up a header file to get a
| good idea of what a class does and how it works.  Though, it's not so easy
| in D.  Sun Java (which also has no header files, for the Java impaired) has
| the javap program, which allows you to take a peek into classes, and is a
| handy way to get the interface and even private methods and variables.
|
| Has anyone written a parser to dump the interface of a D class?

I don't think so. This would be a good spot to have a D grammar available.
At least one that could parse declarations.

Note javap works on class files, not source files, so I'm not too clear
on what you are asking for: to strip out declarations from D source or to
disassemble some compiled code to get the original D source.

While programmers might be loathe to document code they sure should
document APIs - otherwise no-one will want to use it.

-Ben
Feb 21 2004
next sibling parent reply "Walter" <walter digitalmars.com> writes:
"Ben Hinkle" <bhinkle4 juno.com> wrote in message
news:c191js$dsn$1 digitaldaemon.com...
 "Mik Mifflin" <mik42 NOadelphiaSPAM.net> wrote in message
 news:c18unj$7fq$1 digitaldaemon.com...
 | Many programmers loathe to document their code.  When looking at
 | undocumented C++ code, it's easy enough to open up a header file to get
a
 | good idea of what a class does and how it works.  Though, it's not so
easy
 | in D.  Sun Java (which also has no header files, for the Java impaired)
has
 | the javap program, which allows you to take a peek into classes, and is
a
 | handy way to get the interface and even private methods and variables.
 |
 | Has anyone written a parser to dump the interface of a D class?

 I don't think so. This would be a good spot to have a D grammar available.
 At least one that could parse declarations.

 Note javap works on class files, not source files, so I'm not too clear
 on what you are asking for: to strip out declarations from D source or to
 disassemble some compiled code to get the original D source.

 While programmers might be loathe to document code they sure should
 document APIs - otherwise no-one will want to use it.
There's no practical way to disassemble object files into declarations. But have - Design by Contract. For example, instead of: // Input: s is 'a' or 'b' void foo(char s); we have: void foo(char s) in { assert(s == 'a' || s == 'b'); } This works better because comments are invariably out of date, wrong, incomplete, or missing. There's no ambiguity in the contract, and since it gets executed, it is guaranteed correct.
Feb 21 2004
parent "Matthew" <matthew.hat stlsoft.dot.org> writes:
 "Ben Hinkle" <bhinkle4 juno.com> wrote in message
 news:c191js$dsn$1 digitaldaemon.com...
 "Mik Mifflin" <mik42 NOadelphiaSPAM.net> wrote in message
 news:c18unj$7fq$1 digitaldaemon.com...
 | Many programmers loathe to document their code.  When looking at
 | undocumented C++ code, it's easy enough to open up a header file to
get
 a
 | good idea of what a class does and how it works.  Though, it's not so
easy
 | in D.  Sun Java (which also has no header files, for the Java
impaired)
 has
 | the javap program, which allows you to take a peek into classes, and
is
 a
 | handy way to get the interface and even private methods and variables.
 |
 | Has anyone written a parser to dump the interface of a D class?

 I don't think so. This would be a good spot to have a D grammar
available.
 At least one that could parse declarations.

 Note javap works on class files, not source files, so I'm not too clear
 on what you are asking for: to strip out declarations from D source or
to
 disassemble some compiled code to get the original D source.

 While programmers might be loathe to document code they sure should
 document APIs - otherwise no-one will want to use it.
There's no practical way to disassemble object files into declarations.
But

 have - Design by Contract. For example, instead of:

     // Input: s is 'a' or 'b'
     void foo(char s);

 we have:

     void foo(char s) in { assert(s == 'a' || s == 'b'); }

 This works better because comments are invariably out of date, wrong,
 incomplete, or missing. There's no ambiguity in the contract, and since it
 gets executed, it is guaranteed correct.
This is true as far as it goes, but it's not that far. You still need documentation. (As I'm sure you know ...)
Feb 21 2004
prev sibling next sibling parent reply Mik Mifflin <mik42 NOadelphiaSPAM.net> writes:
Ben Hinkle wrote:
 Note javap works on class files, not source files, so I'm not too clear
 on what you are asking for: to strip out declarations from D source or to
 disassemble some compiled code to get the original D source.
 
 While programmers might be loathe to document code they sure should
 document APIs - otherwise no-one will want to use it.
 
 -Ben
Sorry, I should have made myself more clear. I was looking for a program to parse d source and dump out the public methods and variables of classes. I haven't written a parser in a long while, but to write a small parser to recognize classes and public identifiers wouldn't be too difficult, if I understand correctly. So.. I take it no program exists yet? -- - Mik Mifflin
Feb 21 2004
next sibling parent reply J C Calvarese <jcc7 cox.net> writes:
Mik Mifflin wrote:
 Ben Hinkle wrote:
 
Note javap works on class files, not source files, so I'm not too clear
on what you are asking for: to strip out declarations from D source or to
disassemble some compiled code to get the original D source.

While programmers might be loathe to document code they sure should
document APIs - otherwise no-one will want to use it.

-Ben
Sorry, I should have made myself more clear. I was looking for a program to parse d source and dump out the public methods and variables of classes. I haven't written a parser in a long while, but to write a small parser to recognize classes and public identifiers wouldn't be too difficult, if I understand correctly. So.. I take it no program exists yet?
I'm not sure that someone has written quite what you're looking for, but you may be able to benefit from some similar projects: *** dig (http://groups.yahoo.com/group/d_lab/) *** net\BurtonRadons\digc\dfiler.d I think this file is supposed to make a .d file DOxygen friendly net\BurtonRadons\digc\strip.d This file is susposed to remove whitespace and function bodies. It mostly works, but it does seem let some parts of the function seep through. It may be easy to fix, but I haven't dug into it to fix it. *** d2html *** Turns a .d source code into syntax-highlighed .html file. http://jcc_7.tripod.com/d/ *** Dependency Checker *** http://www.wikiservice.at/d/wiki.cgi?LarsIvarIgesund *** \dmd\src\dmd\ *** Since Walter has released the source to the DMD front-end, you may be able to find some help there. It's written in C++, but Walter didn't try to obfuscate it. -- Justin http://jcc_7.tripod.com/d/
Feb 22 2004
parent reply "Walter" <walter digitalmars.com> writes:
"J C Calvarese" <jcc7 cox.net> wrote in message
news:c1b0fb$13pq$1 digitaldaemon.com...
 Since Walter has released the source to the DMD front-end, you may be
 able to find some help there. It's written in C++, but Walter didn't try
 to obfuscate it.
Some have argued that I don't need to try <g>.
Feb 22 2004
parent J C Calvarese <jcc7 cox.net> writes:
Walter wrote:
 "J C Calvarese" <jcc7 cox.net> wrote in message
 news:c1b0fb$13pq$1 digitaldaemon.com...
 
Since Walter has released the source to the DMD front-end, you may be
able to find some help there. It's written in C++, but Walter didn't try
to obfuscate it.
Some have argued that I don't need to try <g>.
LOL! I guess I shouldn't even have mentioned that. Obviously, I meant that the code seems clear to me (not that I pretend to program in C++). -- Justin http://jcc_7.tripod.com/d/
Feb 22 2004
prev sibling parent C <dont respond.com> writes:
You can use dtags , it comes with DIDE but its standalone.  It doesnt =

recognize templates but I can give you the source, its just a matter of =

adding a TEMPLATE type and handling it in the analyseParens function.

The flags I use are

-u --fields=3D+SainKm --language-force=3Dd

C

On Sat, 21 Feb 2004 21:56:12 -0500, Mik Mifflin <mik42 NOadelphiaSPAM.ne=
t> =

wrote:

 Ben Hinkle wrote:
 Note javap works on class files, not source files, so I'm not too cle=
ar
 on what you are asking for: to strip out declarations from D source o=
r =
 to
 disassemble some compiled code to get the original D source.

 While programmers might be loathe to document code they sure should
 document APIs - otherwise no-one will want to use it.

 -Ben
Sorry, I should have made myself more clear. I was looking for a =
 program to
 parse d source and dump out the public methods and variables of =
 classes.  I
 haven't written a parser in a long while, but to write a small parser =
to
 recognize classes and public identifiers wouldn't be too difficult, if=
I
 understand correctly.  So..  I take it no program exists yet?
-- = Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Feb 22 2004
prev sibling parent "Matthew" <matthew.hat stlsoft.dot.org> writes:
"Ben Hinkle" <bhinkle4 juno.com> wrote in message
news:c191js$dsn$1 digitaldaemon.com...
 "Mik Mifflin" <mik42 NOadelphiaSPAM.net> wrote in message
 news:c18unj$7fq$1 digitaldaemon.com...
 | Many programmers loathe to document their code.  When looking at
 | undocumented C++ code, it's easy enough to open up a header file to get
a
 | good idea of what a class does and how it works.  Though, it's not so
easy
 | in D.  Sun Java (which also has no header files, for the Java impaired)
has
 | the javap program, which allows you to take a peek into classes, and is
a
 | handy way to get the interface and even private methods and variables.
 |
 | Has anyone written a parser to dump the interface of a D class?

 I don't think so. This would be a good spot to have a D grammar available.
 At least one that could parse declarations.

 Note javap works on class files, not source files, so I'm not too clear
 on what you are asking for: to strip out declarations from D source or to
 disassemble some compiled code to get the original D source.

 While programmers might be loathe to document code they sure should
 document APIs - otherwise no-one will want to use it.
Quite true. If the code itself doesn't have the minimum - a la Doxygen or JavaDoc - then it's not worth using. QED
Feb 21 2004
prev sibling parent J Anderson <REMOVEanderson badmama.com.au> writes:
Mik Mifflin wrote:

Many programmers loathe to document their code.  When looking at
undocumented C++ code, it's easy enough to open up a header file to get a
good idea of what a class does and how it works.  Though, it's not so easy
in D.  Sun Java (which also has no header files, for the Java impaired) has
the javap program, which allows you to take a peek into classes, and is a
handy way to get the interface and even private methods and variables.

Has anyone written a parser to dump the interface of a D class?

  
What about doxygen? -- -Anderson: http://badmama.com.au/~anderson/
Feb 21 2004