digitalmars.D - Feature request: function prototypes
- Robert Fraser (7/7) Feb 08 2008 This may seem like a pretty stupid request, but since I use a lot of
- Christopher Wright (6/13) Feb 08 2008 Have a unittest? To satisfy your purposes, it just needs to call each
- Ary Borenszweig (26/41) Feb 08 2008 But unittests are run with specific version flags.
- Jesse Phillips (3/52) Feb 08 2008 If that is the case I would much rather have the prototype leave off the...
- BCS (5/25) Feb 08 2008 To get the full advantage of this you would need to be able to run the
- Jarrett Billingsley (6/13) Feb 08 2008 Would it be possible to put the version statement inside the function
- Robert Fraser (5/19) Feb 08 2008 That's what I'm mostly doing now, but I'd rather be able to group stuff
- Bruce Adams (9/27) Feb 09 2008 Would it be overkill to use interfaces and several separate implementati...
- Russell Lewis (4/11) Feb 08 2008 This sounds to me like a pretty compelling argument for function prototy...
This may seem like a pretty stupid request, but since I use a lot of version() statements in my code; it'd be really cool to have something like function signatures at the top of my file. When I declare my versioned functions, I'd love to be able to have them checked against prototypes declared above their use, as a first line of defense (so I don't need to r-test it on different OSes and libraries if I make an obvious change to one of the signatures or something).
Feb 08 2008
Robert Fraser wrote:This may seem like a pretty stupid request, but since I use a lot of version() statements in my code; it'd be really cool to have something like function signatures at the top of my file. When I declare my versioned functions, I'd love to be able to have them checked against prototypes declared above their use, as a first line of defense (so I don't need to r-test it on different OSes and libraries if I make an obvious change to one of the signatures or something).Have a unittest? To satisfy your purposes, it just needs to call each function, even with invalid input. Then if everything compiles with -unittest, you're golden, even if that crashes. Satisfies your requirements, anyway, and in any situation, you'd be duplicating the signature three times.
Feb 08 2008
Christopher Wright wrote:Robert Fraser wrote:But unittests are run with specific version flags. I think he means something like this: --- prototype { int someFunc(float, bool); } version(one) { int someFunc(float f, bool b) { // ... } } else { int someFunc(float f, bool b) { // ... } } --- Now, if you change the signature of someFunc inside of version(one) you'll get a compiler error, because the prototype "int someFunc(float, bool)" would not be found if version is "one". Alternatively, if you change the prototype inside the "prototype { }", you'll get two compiler errors: in "one" the prototype doesn't exist, neither in the "else". That way you can maintain synchronized the two version blocks. The problem is, how to implement this? The compiler would need to check all possible combinations of versions, debugs, static ifs, etc. By the way, this will also allow tools to provide good refactoring support.This may seem like a pretty stupid request, but since I use a lot of version() statements in my code; it'd be really cool to have something like function signatures at the top of my file. When I declare my versioned functions, I'd love to be able to have them checked against prototypes declared above their use, as a first line of defense (so I don't need to r-test it on different OSes and libraries if I make an obvious change to one of the signatures or something).Have a unittest? To satisfy your purposes, it just needs to call each function, even with invalid input. Then if everything compiles with -unittest, you're golden, even if that crashes. Satisfies your requirements, anyway, and in any situation, you'd be duplicating the signature three times.
Feb 08 2008
On Fri, 08 Feb 2008 12:44:04 -0200, Ary Borenszweig wrote:Christopher Wright wrote:If that is the case I would much rather have the prototype leave off the parameter-list and only require all declarations to be the same.Robert Fraser wrote:But unittests are run with specific version flags. I think he means something like this: --- prototype { int someFunc(float, bool); } version(one) { int someFunc(float f, bool b) { // ... } } else { int someFunc(float f, bool b) { // ... } } --- Now, if you change the signature of someFunc inside of version(one) you'll get a compiler error, because the prototype "int someFunc(float, bool)" would not be found if version is "one". Alternatively, if you change the prototype inside the "prototype { }", you'll get two compiler errors: in "one" the prototype doesn't exist, neither in the "else". That way you can maintain synchronized the two version blocks. The problem is, how to implement this? The compiler would need to check all possible combinations of versions, debugs, static ifs, etc. By the way, this will also allow tools to provide good refactoring support.This may seem like a pretty stupid request, but since I use a lot of version() statements in my code; it'd be really cool to have something like function signatures at the top of my file. When I declare my versioned functions, I'd love to be able to have them checked against prototypes declared above their use, as a first line of defense (so I don't need to r-test it on different OSes and libraries if I make an obvious change to one of the signatures or something).Have a unittest? To satisfy your purposes, it just needs to call each function, even with invalid input. Then if everything compiles with -unittest, you're golden, even if that crashes. Satisfies your requirements, anyway, and in any situation, you'd be duplicating the signature three times.
Feb 08 2008
Ary Borenszweig wrote:But unittests are run with specific version flags. I think he means something like this: --- prototype { int someFunc(float, bool); } version(one) { int someFunc(float f, bool b) { // ... } } else { int someFunc(float f, bool b) { // ... } } ---To get the full advantage of this you would need to be able to run the compiler with "wrong" versions. e.g. on windows, run the compile up to the code generation phase with the Linux versions set. This in and of it's self might be handy.
Feb 08 2008
"Robert Fraser" <fraserofthenight gmail.com> wrote in message news:fohlg3$acr$1 digitalmars.com...This may seem like a pretty stupid request, but since I use a lot of version() statements in my code; it'd be really cool to have something like function signatures at the top of my file. When I declare my versioned functions, I'd love to be able to have them checked against prototypes declared above their use, as a first line of defense (so I don't need to r-test it on different OSes and libraries if I make an obvious change to one of the signatures or something).Would it be possible to put the version statement inside the function bodies? Yes, it's somewhat more typing, but it means you only have to actually declare each function once (and write ddoc for them once, as a bonus).
Feb 08 2008
Jarrett Billingsley wrote:"Robert Fraser" <fraserofthenight gmail.com> wrote in message news:fohlg3$acr$1 digitalmars.com...That's what I'm mostly doing now, but I'd rather be able to group stuff together (i.e. "here's the Tango functions, here's the Phobos ones), and Ddoc the stuff up with the prototypes at the top. But maybe it's not a big enough deal to justify a language change.This may seem like a pretty stupid request, but since I use a lot of version() statements in my code; it'd be really cool to have something like function signatures at the top of my file. When I declare my versioned functions, I'd love to be able to have them checked against prototypes declared above their use, as a first line of defense (so I don't need to r-test it on different OSes and libraries if I make an obvious change to one of the signatures or something).Would it be possible to put the version statement inside the function bodies? Yes, it's somewhat more typing, but it means you only have to actually declare each function once (and write ddoc for them once, as a bonus).
Feb 08 2008
On Fri, 08 Feb 2008 18:58:14 -0000, Robert Fraser <fraserofthenight gmail.com> wrote:Jarrett Billingsley wrote:Would it be overkill to use interfaces and several separate implementation classes instead? That is what polymorphism is about after all. Also you would be able to refactor any common code which is hard to do with version statements all over the place. Bruce."Robert Fraser" <fraserofthenight gmail.com> wrote in message news:fohlg3$acr$1 digitalmars.com...That's what I'm mostly doing now, but I'd rather be able to group stuff together (i.e. "here's the Tango functions, here's the Phobos ones), and Ddoc the stuff up with the prototypes at the top. But maybe it's not a big enough deal to justify a language change.This may seem like a pretty stupid request, but since I use a lot of version() statements in my code; it'd be really cool to have something like function signatures at the top of my file. When I declare my versioned functions, I'd love to be able to have them checked against prototypes declared above their use, as a first line of defense (so I don't need to r-test it on different OSes and libraries if I make an obvious change to one of the signatures or something).Would it be possible to put the version statement inside the function bodies? Yes, it's somewhat more typing, but it means you only have to actually declare each function once (and write ddoc for them once, as a bonus).
Feb 09 2008
Robert Fraser wrote:This may seem like a pretty stupid request, but since I use a lot of version() statements in my code; it'd be really cool to have something like function signatures at the top of my file. When I declare my versioned functions, I'd love to be able to have them checked against prototypes declared above their use, as a first line of defense (so I don't need to r-test it on different OSes and libraries if I make an obvious change to one of the signatures or something).This sounds to me like a pretty compelling argument for function prototypes. An ugly but workable solution to this would be static asserts which verified the type of each function.
Feb 08 2008