NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
a comment after variable declaration specifiying the type


Joined: 31 Aug 2005
Posts: 2
Reply with quote
Basically. Would like to have a feature, where a developer can specify something alike
var $myvar; // @PHPED:TYPE: MyOtherClass

and later editor's code insight knows a bit better how to resolve code insights for variables
(maybe also giving possible subclass lists the variable can be of)

---
why?

i have heavy OOP project here. Where there are several base classes. So when i refer to something like
$this->core->... there will be no code insight. Even worse $this->core->user->props-> ..

In those cases, code insight seems to be of no use, although it works a lot better than in 3.3 Smile
View user's profileFind all posts by cdgSend private message


Joined: 15 Aug 2003
Posts: 44
Reply with quote
I thought a lot about the problems of code insight and syntax highlighting when it comes to objects. The way I see it there are basicly two options: The user helps PHPEd to determine the class of a certain variable/property, or PHPEd tries to semi-evaluate the code itself to determine the class.

Both options are very problematic. I think the problems with semi-evaluation are obvious (includes, conditions, startup values/arguments, etc). When it comes to the user helping out, it's also a bit of a problem.

First off I don't think "extending" the language is a good idea if it's not done in coordination with other extensions, which might prove to be somewhat of a hassle for nusphere.

Second, it also creates a bit of a hassle for the user himself. You need to remember to update your comment hints if you change you code, you need to declare these variables, eventough one of PHP's advantages is not needing to do so. And you need to repeat this for every scope of code.

Consider the number of times you are using the same variable in a given block of code, and you realize that that number is close to 1 - if you are capsulating your code correctly. Even if it's 2, for the code insight you need to setup the comment and maintain it in every such block of code, for two usages of it. The time and effort invested might be better off used to simply lookup the method's declaration...

A feature I do like in visual C for example, is the ability to right click on a function, and choose "go to defenition of", BTW, but even in visual C that requires you to compile the code first, and that's a language where everything is declared beforehand anyway.

I think the best example of always-available code insight is visual basic. but you have to keep in mind that in visual basic the interpreter is constantly working, evaluating the code as you type it, and still you need to declare the types of your variables (eventough it's not really neccessary for the language - you can always resort to using variants. It's basicly there for code insight I think) - A course of action that might not be quite available for nusphere, with all the tweakability of PHP, even if using an external PHP executable. The user would need to make sure his php.exe and php.ini are correct, and even then you have the problem of editing an include file, conditions, and startup variables.

Still, it would contribute a whole lot to PHPEd if we did manage to define a way of doing this. That would really put the "I" in "IDE" here...
View user's profileFind all posts by Post-O-MaticSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8340
Reply with quote
PHPED v4 supports the following syntax for defining a variable or a property type:

PROPERTIES:
Code:
class Y {
   /**
   * @var SomeClassA it is an example1
   */
   public $anX;
   /**
   * @var SomeClassB it is an example2
   */
   public $anY;
}


ARGUMENTS:
Code:
/**
* example of basic @param usage
* @param SomeClassC $bax some comments may follow...
* @param SomeClassD $bay some other comments may follow...
*/
function function1($bax, $bay) {
}

// php5 way is supported too:
function function1(SomeClassC $bax, SomeClassD $bay) {
}


VARIABLE:
Code:
/**
* @var SomeClassE
*/
$a->
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 15 Aug 2003
Posts: 44
Reply with quote
So PHPEd uses PHPDoc's comments ?
View user's profileFind all posts by Post-O-MaticSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8340
Reply with quote
why not ? Smile
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 09 Dec 2003
Posts: 92
Reply with quote
Quote:
First off I don't think "extending" the language is a good idea if it's not done in coordination with other extensions, which might prove to be somewhat of a hassle for nusphere.


Quote:
Second, it also creates a bit of a hassle for the user himself. You need to remember to update your comment hints if you change you code, you need to declare these variables, eventough one of PHP's advantages is not needing to do so. And you need to repeat this for every scope of code.


Using phpdoc comment's solves the first issue in a clean manner. As to the second - consider it as an incentive for your developers Smile. Write phpdoc comments, keep them up-to-date, and you get the benefit of a better code completion Smile.

Unfortunately, there's no better way to do it, as PHP is weakly typed (OK, PHP5 introduces type hints).
View user's profileFind all posts by mpSend private message


Joined: 15 Aug 2003
Posts: 44
Reply with quote
ddmitrie wrote:
why not ? Smile
That's exactly what I mean by "done in coordination with other extensions".

That's very good, I wasn't aware of that. I was thinking of starting to use PHPDoc, so now it's obvious I will.
View user's profileFind all posts by Post-O-MaticSend private message
a comment after variable declaration specifiying the type
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic