SitePoint Sponsor |
|
User Tag List
Results 76 to 100 of 190
-
May 18, 2006, 15:29 #76
- Join Date
- Apr 2003
- Location
- London
- Posts
- 2,423
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
Hi...
I am also an ex-Hungarian user. A lot of the disadvantages have already been mentioned, but for me the extra clutter and endless, boring, dull, so terribly dull, typing just drove me away. Nothing is worth that much pain.
yours, MarcusMarcus Baker
Testing: SimpleTest, Cgreen, Fakemail
Other: Phemto dependency injector
Books: PHP in Action, 97 things
-
May 18, 2006, 15:55 #77
I too was a Hungarian user. Although I just forgot about typing the datatype. I just went along typing a name of the varibale that makes sense to me.
People in my company use them tho. But I believe they are switching to a better naming method.
-
May 18, 2006, 17:15 #78
- Join Date
- Jun 2004
- Location
- Copenhagen, Denmark
- Posts
- 6,157
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
oh ... welcome to hungarian anonymous ...
-
May 18, 2006, 17:57 #79
Originally Posted by kyberfabrikken
-
May 18, 2006, 17:59 #80
- Join Date
- Jun 2003
- Location
- Iowa, USA
- Posts
- 3,749
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
The first step towards a cure is admitting that you have a problem.
Jason Sweat ZCE - jsweat_php@yahoo.com
Book: PHP Patterns
Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
Detestable (adjective): software that isn't testable.
-
May 18, 2006, 18:15 #81
- Join Date
- Jan 2005
- Location
- Ireland
- Posts
- 349
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
The only place I can see hungarian being useful is when poorly named variables are employed and in spagetti code. That way you can't track down where the variables originate from (and hence how they are declared and initialised) and the name makes no sense. Well designed applications should make the application path (and it inputs) clear or atleast easy to find out.
-
May 18, 2006, 21:47 #82
- Join Date
- May 2003
- Location
- The Netherlands
- Posts
- 391
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I still use prefixes on ocassions, but I never use it to indicate the type, as PHP is loosely typed and, like Jason well said, it just does not make sense. I find useful though to indicate the scope of the variable:
PHP Code:// May there be any globals in the game
$gGlobalVar = 'I am evil';
// Arguments in functions/class methods
// I find useful to distinct an argument of a function variable
function ShowScope($aFirstArgument, $aSecondArgument){
$var_inside_function = 'My scope is only this function';
}
// And class variables
class MyScope{
private $mClassVariable;
}
There’s more than one way to skin a cat.
-
May 19, 2006, 03:01 #83
- Join Date
- May 2005
- Posts
- 255
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Using classes says absolutely nothing about the quality of any given piece of code. It just tells you that the developers like to use the OO paradigm. Drupal is an excellent piece of PHP code, and it's totally procedural. mysql++ (was) an OO oriented version of the excellent mysql client libraries (for C), and it was a festering pile of crap.
In many instances in PHP, making classes on something doesn't make sense. I personally keep every function I write inside a class (even if it's just a static function, because it lets me take advantage of __autoloading and using class_exists and the like). However, there's just as much code that belongs at the file scope level as belongs at the class level. Assuming you're using MVC (or some other 3 tiered approach), usually M = classes, V = template files, and c (little c...) = some combination thereof.
A lot of people on this site focus on writing apps that are intended to stand on their own (usually on some hosted service), so their perspectives are going to be different from someone who spends their time creating web applications where they have total control over the machine they're running.
Prefixing member variables is truly pointless because you always have to access member variables through $this->. They make sense in C++ or other languages where you don't have to explicitly access the this pointer, but they make no sense in PHP. There's absolutely no ambiguity here:
if($this->someVar)
doing:
if($this->mSomeVar)
doesn't tell you anything.
Globals should usually just be avoided, and it's much simpler to just access them as $GLOBALS['whatever'] anyway.
The only thing that needs to be well commented is the interface (e.g. function / class / file headers). The only other comments should appear in complex code that requires explanation. You don't need to tell me that you're iterating over something. I know what a for loop is. Write your comments for programmers, not for students. When you write comments, do it in such a way a to be easily picked up by doxygen / phpDoc and make everyone's lives easier.
Don't mix programming styles in user land code. Make your code predictable. If you use exception handling extensively, don't suddenly decide to have nested error checking in one place (unless you have a really good reason). Stick with the same casing / underscores (php forces you to use underscores, but I say it's ok to ignore php's convention here and stick with one that you prefer).
Do not use databases. . Well, I see, most of the developers, are to disagree. So let's periphrase it. Use databases, only for projects where data is very sensitive, changes fast, regularly, and is large. So what is large? It's a relative idea. One may say 12 MB, 700 MB or 4 GB. According to my experience 99% of all the projects don't need (MySQL,Acess - like)databases. "Please, excuse us but the MySQL server is not working a the moment", "The maximum connections exceed the limitations of the MySQL server", etc.
Code should be testable in the simplest way possible. I should be able to write a script that calls your classes / functions and have very simple conditions to test for. If I call $Template->render(), I should expect to see template output.
Lastly -- don't assume that what's good for the goose is good for the gander. PHP is NOT java, it's NOT C, it's NOT C++, it's NOT Ruby, Python, Perl, or any of these things.
What is good practice in PHP can be horrible practice elsewhere, and vice versa. If I had a dollar for every time I heard some first year graduate telling me some GoF brainwashed crap while failing to actually solve the original problem in a reasonable time frame, I'd have at least $20 so far this year.
-
May 19, 2006, 03:51 #84
- Join Date
- May 2003
- Location
- The Netherlands
- Posts
- 391
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by Etnu
Very good point! Thanks for pointing it out.
Never thought about it actually, how stupid that might sound. (I guess $this-> becomes invisible somehow ...). I'll be reconsidering ...There’s more than one way to skin a cat.
-
May 19, 2006, 07:10 #85
- Join Date
- Sep 2003
- Location
- Glasgow
- Posts
- 1,690
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by Etnu
OOP - particularly OOP combined with testing - is a much more powerful way to work. I can understand if it looks over-complicated or unecessary on first contact (I thought that when I was starting out) but statements such as above can be very misleading for people who are trying to learn. You don't have to, of course. Php is a bus you can hop on and off anywhere you like. But if you do want to learn to produce the best quality code you possibly can, OOP and testing is the way to go. We'd be selling people short to pretend that procedural is just as good or that it's all just a matter of personal preference.
-
May 19, 2006, 08:36 #86
- Join Date
- Apr 2004
- Location
- FL, USA
- Posts
- 87
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by McGruff
... people who are trying to learn.
Back on topic:
I've used App Hungarian Notation in PHP never thought I need a 12-step program though.Sys Hungarian Notation has never made much sense to me though maybe I've just not found a use for it.
Last edited by Buddha443556; May 19, 2006 at 09:09.
Simple fool to the 3rd include.
-
May 19, 2006, 11:02 #87
- Join Date
- Nov 2005
- Location
- The Netherlands
- Posts
- 205
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by Etnu
Taking over the web one pixel at a time.
Currently working @ CodeCreators
-
May 19, 2006, 12:40 #88
- Join Date
- Jan 2005
- Location
- Ireland
- Posts
- 349
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by McGruff
-
May 19, 2006, 12:52 #89
- Join Date
- Sep 2003
- Location
- Glasgow
- Posts
- 1,690
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I don't know anything about Java. What about php?
-
May 19, 2006, 13:08 #90
- Join Date
- Nov 2002
- Posts
- 841
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I was on a team where hungarian was the standard. I really loathed it. The focal point of my hate was a variable named cChar. Type based prefixes are the work of the devil. Scope based prefixes aren't too bad.
This is getting off topic, but I think that would be a nice language feature. $local, @member, @@global instead of $local, $this->member, $GLOBALS['global']. To bring it back on topic, I always use the $GLOBALS keyword when I use a global (less and less) rather than the global keyword. In my mind, globals should be combersome to use and to type and explicitly distinguished.
-
May 19, 2006, 13:57 #91
- Join Date
- May 2003
- Location
- London, On.
- Posts
- 1,127
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by McGruff
An example posted earlier in the thread that inspired this one demonstrates that very well.
PHP was developed as a scripting language. While the object-oriented capabilities are certainly a blessing to programmers of advanced or extensible systems, there are certainly instances where using them is definitely not desirable. Another example would be a script I've created to aid in the creation and deployment of new projects. It's interactive via the CLI, and perfectly suited to procedural code. Of course, such a project would be better handled by a shell script, but as a Windows user I find PHP more friendly than the alternatives.
-
May 19, 2006, 14:20 #92
- Join Date
- Sep 2003
- Location
- Glasgow
- Posts
- 1,690
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Sure: for something trivially simple there might not be any need for OOP. As soon as the number of lines of code gets into three figures or thereabouts I'd expect to start finding objects though.
-
May 19, 2006, 14:31 #93
i agree with your statements
-
May 19, 2006, 14:46 #94Off Topic:
Originally Posted by Ryan Wray
Sorry for the OT...
-
May 19, 2006, 15:53 #95
- Join Date
- Jan 2005
- Location
- Ireland
- Posts
- 349
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by McGruff
Now, is simple full of static methods. Of course, many probably would just classify this as procedual code wrapped in a class (an construct used in OOP). The class should be taken away. Just a bunch of procedual functions I think makes more sense, I can't think of a better OO way.Last edited by Ryan Wray; May 19, 2006 at 15:58. Reason: Blabbed on way too much, so I reduced the post :p
-
May 19, 2006, 16:07 #96
- Join Date
- Jun 2003
- Location
- Iowa, USA
- Posts
- 3,749
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by McGruff
Jason Sweat ZCE - jsweat_php@yahoo.com
Book: PHP Patterns
Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
Detestable (adjective): software that isn't testable.
-
May 19, 2006, 17:11 #97
Originally Posted by Ryan Wray
-
May 19, 2006, 17:24 #98
- Join Date
- Sep 2003
- Location
- Glasgow
- Posts
- 1,690
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by Ryan Wray
I do occasionally find some poor orphaned fns like that which end up in a class purely for somewhere to put them. I always have nagging feeling that they ought to have a proper home somewhere though. Should the math fns become part of a Calculator class?
-
May 19, 2006, 18:00 #99
- Join Date
- Sep 2003
- Location
- Glasgow
- Posts
- 1,690
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by sweatje
-
May 19, 2006, 18:58 #100
- Join Date
- Jan 2005
- Location
- Ireland
- Posts
- 349
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by 33degrees
Code:include Math sqrt(144)
Originally Posted by McGruff
When you say Calculator class, do you mean one that is to instanated in someway? I just can't envision a clean solution.
Bookmarks