|
|
I'm addicted to .NET?
|
|
[Coding/Tech]
|
stevo
Veteran
Posts:
924( 7.21%) Threads: 229( 13.71%) Private Posts: 0
|
This user's posts are being ignored. Show Post?
|
Posted: 3/2/10 4:39:24pm
|
Edited: 3/2/10 6:49:28pm
|
|
and Visual Studio is my crack cocaine.
I've been working on a small car maintenance web app and building it in PHP using notepad++ for a text editor. I only work with Microsoft products at work, I'm basically in Visual Studio 2008 all day.
Now I realize there's a learning curve since I don't write much PHP at all, but I'm getting incredibly frustrated in PHP just building simple forms. I feel like PHP hasn't changed in 15 years, and ASP.NET and Visual Studio have really matured into a great development environment. Now I didn't like ASP.NET much when it first launched, and some of that might have been a little anti-MS bias, but it was buggy and VS was a glorified text editor. But with the 3.5 framework and VS2008, it just makes writing code a breeze. The intellisense is like reading my mind and basically eliminating syntax errors, and the .NET framework has every data structure, classes, and functions I'd ever need AND there's some consistency to the structure and naming of them.
As far as I know, no one here uses .NET at all, so maybe no one else has experienced the maturing of .NET that I have. Just wondering if anyone has an opinion on the future of PHP. Web development is changing and PHP isn't. I gotta run, but I've got more thoughts on this...
|
skeezer65134
Veteran
Posts:
2364( 18.45%) Threads: 150( 8.98%) Private Posts: 0
|
This user's posts are being ignored. Show Post?
|
Posted: 3/2/10 6:50:16pm
|
Edited: 3/2/10 6:55:41pm
|
|
Wait, you're comparing Visual Studio to Notepad++ and using that to judge specific languages?! I thought you were smarter than that! If you want all that hand-holding, why not try out a mature IDE. Eclipse, Zend Studio and Aptana all come to mind (probably because they all run on Eclipse or work as plugins). But, there's also Komodo (the free "Edit" and for-purchase "Studio"), PhpED and PHPEdit, and here's a nice comparison of IDEs for PHP. Don't want to pay or mess around with trials? Bluefish is OK, as is SciTE with the proper plugins. And you've already found Notepad++ which I believe has automatic PHP, HTML, CSS and perhaps even Javascript completion, although I could be wrong about that. Or, maybe you want to do more than just PHP. After all, .NET is something of an all-encompassing tech, isn't it? Like, just because I know ASP doesn't mean I'll be able to do much with ASP.NET as I understand it. So, one could argue that using a framework like CakePHP, CodeIgniter or Symfony would be more appropriate, all of which have some ability to generate HTML and Javascript from PHP directly which makes forms faster and easier to work with. There's even more obscure options like Prado which purports to absolve you from writing a lot or Javascript code. [Aside: I don't know Pardo's capabilities in that domain, but I do know that CakePHP has built-in Javascript generation as well] So, do you think the language is missing something or that your development routine is? ---- no fat chicks
|
Chops
Administrator
Posts:
2738( 21.37%) Threads: 326( 19.52%) Private Posts: 1
|
This user's posts are being ignored. Show Post?
I've heard that VS has always been a great development environment, and continues to improve. Intellisense is supposed to be pretty great.
But, I'm sure you know that Fleming and I code in Vim exclusively, which pretty much isn't an IDE at all. I'm kind of with Joe in that you can't judge the language by the IDE you're using.
But as far as PHP as a language goes, yes, it hasn't changed a ton, it's got too many inconsistencies (needle,haystack argument ordering), and it doesn't shelter the program from bugs. The argument goes both ways that PHP isn't a framework (like Rails or Django - or .NET if I correctly remember it being kind of framework-ish), and so it doesn't shelter the coder from bugs.
With PHP, in order to be effective, you kind of have to build your own framework: something to handle SQL calls, <select> generation, and handing input (extract() is dangerous).
Unfortunately, I don't know any .Net, so I can't really provide an actual comparison, but I do know Nitrogen with Erlang, and with that, I find myself preferring programming in Nitrogen to PHP, but raw PHP/HTML is more flexible.
PHP is great for 4 reasons:
1) Documentation is very good 2) Widely available install base 3) Easy to pick up 4) Extensive libraries and extensions
But, like any language, you'll have to do some work in it to really get the feel for it. Keep working on it, keep adding stuff, and after a while you'll find yourself looking up stuff less, which for me, was the slow part of PHP development.
If you could go into some more details, we can likely try to give some more detailed responses. Also, you're just getting started with the project you're on, and you're kinda getting started with the language, you could also look into something like Python, Ruby, or hell, a Lisp version (Clojure, CLisp).
The best way to learn a language is to build something useful in it.
---- Do it for the Lobster
|
skeezer65134
Veteran
Posts:
2364( 18.45%) Threads: 150( 8.98%) Private Posts: 0
|
This user's posts are being ignored. Show Post?
|
Posted: 3/3/10 8:39:13am
|
Edited: 3/3/10 8:49:27am
|
|
| But as far as PHP as a language goes, yes, it hasn't changed a ton |
I disagree... it's really a matter of how you use it. PHP4 to PHP5 was a pretty massive change if you were doing any OOP. Additionally, settings changed, some important functions were deprecated or had their return values changed and a handful of new functions were added to the mix. They also rolled JSON functionality into the core as an optional module, and I'm sure that wasn't the only addition. | it's got too many inconsistencies (needle,haystack argument ordering) |
I agree completely. I ALWAYS have to look that up, because it's different for many functions. Pretty annoying. That said, the documentation on php.net is pretty amazing and I have yet to find a language or framework that is so easy to get answers about. | and it doesn't shelter the program from bugs. |
Neither does C, Java, Erlang or any other *language* out there. Even you make the mistake of comparing Nitrogen (a framework) to PHP (a language). Apples to oranges my friend. If you want to do rapid PHP development, I suggest you use a framework. I've tried a bunch of them, and right now I'm pretty hooked on CakePHP. Even if you're just doing a simple site, it'll save you a TON of time. The way it handles Models (datasource access, such as a database, an XML file, a JSON file, text, etc.) and the Form helper (which generates form inputs based on the database and handle the output automatically) alone are worth the learning curve, and there's so much more to it once you start learning and using it. The one thing I don't like about Cake is the documentation; it's pretty terrible. Even the books written on it are pretty pathetic. For me, the most useful resource so far has been their IRC channel and a contact I made on Twitter, though I have figured out how to use the API now and I can usually find decent examples via Google now that I'm more comfortable with how things work in Cake. As an aside, I've also heard good things about the Zend Framework, but it always seemed like nothing more than a Pear wrapper. Even that would save some time though. And if you don't NEED a full framework, there's plenty of people who just do customized Wordpress installs. And if you need more than just a customized blog, Joomla has a decent community. And of course, we can't talk about content management without mentioning Drupal. There are a lot of options out there, you just need to read up and see which one(s) will work for you, then learn how to use them. I've always found the CMS route too restrictive, but others live exclusively from Wordpress or Drupal. I prefer to write my own code, but I like having libraries available to ease, reduce or remove the tedious parts of the code; for me, the tool that delivers the best is CakePHP. ---- no fat chicks
|
Chops
Administrator
Posts:
2738( 21.37%) Threads: 326( 19.52%) Private Posts: 1
|
This user's posts are being ignored. Show Post?
|
Posted: 3/3/10 9:53:25am
|
Edited: 3/3/10 10:31:59am
|
|
| PHP4 to PHP5 was a pretty massive change if you were doing any OOP. |
It is very incremental, and they're always adding new functionality. And yes, the OOP change from 4 to 5 was big if you do OOP. Namespaces coming and the completely removal of magic quotes in 6 will be pretty big (I'm embarrassed to say that my code for DKP and this site still rely on magic quotes - it's gonna be hard removing all that dependency, since it's like 200 php files). And the new integrated JSON stuff is coming in handy right now, as I'm working on the forum updates. Perhaps I was being a little hard on it. But I think if you compare ASP.net from 5 years ago with ASP.net now, the changes are almost certainly more significant than the changes for PHP in the past 5 years. But again, I get the impression that ASP.Net is more frameworky, whereas the whole PHP-Apache interface hasn't exactly changed. | and it doesn't shelter the program from bugs. |
Neither does C, Java, Erlang or any other *language* out there. Even you make the mistake of comparing Nitrogen (a framework) to PHP (a language). Apples to oranges my friend. |
Obviously no language completely eliminates bugs for the programmer, for sure. But, of those languages mentioned, they all protect the programmer in a certain way, eliminating (or syntactically discouraging) entire classes of bugs. Memory management is a class of bug that is much more common in C, for example. Immutable data and pure functions of Erlang remove a certain type of bug (that of "what is the state of my variables" bug). PHP does a good job of making everything flexible, but at the same time, it makes bad habits easy (which is why PHP gets a bad rap on "Hacker News" and whatnot). But yes, I did compare the Nitrogen to PHP. To be fair, PHP is kind of like a framework itself: built-in session management, "echo" prints directly to the page, superglobals ($_GET,$_POST,etc) being autopopulated. Those are all very frameworky. I'd say a three-way analogy would be like: Erlang:Ruby:PHP-CLI :: Nitrogen:Rails:PHP-Apache Overall, I think PHP is kind of a weird language. ---- Do it for the Lobster
|
skeezer65134
Veteran
Posts:
2364( 18.45%) Threads: 150( 8.98%) Private Posts: 0
|
This user's posts are being ignored. Show Post?
|
Posted: 3/3/10 2:03:57pm
|
Edited: 3/3/10 4:51:54pm
|
|
My point about the languages isn't that they are all unsafe and terrible, it's that at their core, they don't do much of anything to enforce your code. This is both good an bad. It keeps things flexible, but it also opens the door to horrendous code. | PHP does a good job of making everything flexible, but at the same time, it makes bad habits easy |
True. I've read, been told and found that it's one of the easiest languages to pick up; it's also one of the easiest languages to do wrong as a result. The biggest problem is that you don't really know you're doing it wrong until you learn more or someone exploits your code. Frameworks help, to some degree. | Overall, I think PHP is kind of a weird language. |
Yeah, I'll give you that. I think a lot of its rise to fame was pretty unfounded. Especially in the days of old when magic-quotes and globals were the norm. And it sat pretty idle for a long time between 4 and 5. | Erlang:Ruby:PHP-CLI :: Nitrogen:Rails:PHP-Apache |
That's an interesting way to think about it. I've never really thought of the CLI and Apache modules as being something different. The CLI is actually an extension of PHP though, isn't it? I mean, when you install PHP and Apache, you don't NEED the CLI component for it all to work. If you consider where PHP came from (someone looking to make their homepage dynamic), it's not surprising that, at the core, it's pretty sloppy. All the other languages were written with other goals in mind, usually to be their own language. I've never used Nitrogen or Rails, but I have, to an exceptionally small extent, used Django (python framework). If they are anything like Django is, I'd say comparing PHP to PHP+<framework> is more appropriate. Plus, aren't there more frameworks for Ruby than just Rails? And I assume the same is true of Erlang. PHP may lack a "de-facto" framework (although, I suspect either the Zend Framework or CakePHP has the largest install base), but isn't a framework in one language basically the same as a framework in another? Sure, they may all have different goals or functionality, but you're still trying to achieve the same thing; reducing time coding, preventing security problems, speeding up code and avoiding reinventing the wheel. Anyway, we could probably argue the merits of different languages and frameworks and IDEs and coding styles and anything else for quite some time. I'm still curious if we've covered any of stevo's original questions or concerns. To that extent, the future of PHP is probably not too different than it always has been. It will be easy to use, easy to install and easy for people to do wrong. PHP5 brought a lot of very nice OOP improvements, none of which you will ever appreciate if you don't use OOP. I don't know what PHP6 will be bringing as I haven't been keeping up at all, but if you're still not using objects and you ignore whatever changes PHP6 will bring, then in your world, PHP will continue to not change. I suspect that, much like the change to PHP5, the change to PHP6 will take a VERY long time since most people won't be willing to port their code forward. I have noticed that it seems like less and less people are learning PHP and instead are opting to learn PHP programs and frameworks (CakePHP, Zend Framework, Drupal, Joolma and Wordpress being the most talked about). You don't need to know much of the core language to use them (especially true for the CMS setups), and many people find that they can get things done much faster by skipping the core language. I don't know if that trend will continue, and if it does, what it will mean in the distant future. It's also possible that I'm only seeing a very small subset of developers and they all just happen to be making that switch, indicating there is no such trend overall... ---- no fat chicks
|
Chops
Administrator
Posts:
2738( 21.37%) Threads: 326( 19.52%) Private Posts: 1
|
This user's posts are being ignored. Show Post?
| \The CLI is actually an extension of PHP though, isn't it? I mean, when you install PHP and Apache, you don't NEED the CLI component for it all to work. |
Right, it's kind of backwards that way. I only meant to make the distinction that unlike other languages, PHP has the web interface built in, and that building a website in PHP-CLI is like building a website in non-Rails Ruby - hence the comparison between Rails and PHP+Apache. | but isn't a framework in one language basically the same as a framework in another? |
The goal is indeed to shorten the time, but frameworks for languages that can retain state information and running processes for each user can take on extremely interesting things, Arc and Nitrogen are examples (though Arc is a language, when you start Arc, you've started the Arc webserver - the webserver is part of the language). In the case of languages like Ruby and Python (neither of which I've used), the core language doesn't interface with a webserver without a bunch of coding, and by the time you're done coding a webserver interface, you've pretty much got yourself a homegrown framework. PHP as a language is (was) unique in that the language itself has the interface with the webserver built-in. You start PHP and Apache, and then you can just use $_SESSION, or use $_GET, and you're off. That's why I said that PHP+Apache is kind of like the a framework - the details of the web interface are abstracted away already for you, just like in a web framework in another language. The PHP frameworks are just further abstractions of PHP. I'm not sure the future of PHP. It can't exactly grow it's userbase much more - it's already the top web language, and it has certainly set the bar for "easy to get a webserver up and running", which should be the one of the goals of any web framework. ---- Do it for the Lobster
|
stevo
Veteran
Posts:
924( 7.21%) Threads: 229( 13.71%) Private Posts: 0
|
This user's posts are being ignored. Show Post?
I guess I should've separated my comments on ASP.NET from VS2008.
Though I think the #1 thing I like about the .NET VS combo is the structure of the .NET libraries is what makes the intellisense so great. How do you even do intellisense in PHP? None of the functions are in any hierarchy, and so like functions aren't grouped. Example off the top of my head, if I want to perform some common string function on a string object, in .NET I just put a . after the string variable and everything shows up in intellisense (Contains, Trim, PadLeft, ToUpper, etc) and everything has a consistent naming convention. Try to find all those functions in PHP, some are abbreviated (substr) some have underscores (str_pad). Some functions do the same thing as others. Some functions have such ridiculous names it's hard to take it seriously.
Also the syntax error and type error highlighting in VS is great.
Beyond that, I guess VS isn't much different from any other IDE. But the built-in intellisense is really the killer app for VS, and I just can't seem to live without it anymore.
As far as the language, you guys have more experience and knowledge with different languages than I do. So I'm not the most informed and I'm not a superstar developer. And I admit my career has basically stagnated for the last 5 years so I haven't been exposed to much outside the .NET world.
Classic ASP was like PHP. They were immature scripting languages for generating HTML. Obviously the way we use the web has change a lot from just generating basic HTML. ASP.NET is a huge change from ASP. PHP has had some improvements bolted on, but it's still PHP. Today we're building huge complicated applications on the web. Having to manage that through hundreds of includes in PHP is ridiculous. This kind of relates to that previous thing I posted about web development basically being hack on top of hack on top of hack, at least .NET makes me feel better about it, like there was some control of what's going on.
Chops is right about bad habits in PHP. I've tried looking for some best practices recommendations in PHP, and all you find is 5 different people saying 5 different things. There's no authority. .NET has great documentation, the online MSDN has *greatly* improved in the last 3-4 years, and now there's a lot more independent developers (and MS employees) out there who've posted in various forums and blogs. I have no trouble finding help for .NET questions.
OOP in PHP is a joke. No overloads. No private functions. I don't even want to get into dealing with PHP variable "types". What put me over the edge and prompted me to write this was trying to deal with some basic date/time math and formatting and read/write from the database. You can blame MySql for some of that too. But I know dates just work with MSSQL and .NET without dicking around writing string functions to parse the stupid thing out.
I realize there's a million frameworks for PHP that might address some of these problems. But then you have even a harder time finding documentation. I have never heard of CakePHP.
|
stevo
Veteran
Posts:
924( 7.21%) Threads: 229( 13.71%) Private Posts: 0
|
This user's posts are being ignored. Show Post?
This discussion is kinda all over the place now.
I guess it seems there are some frameworks for PHP that are promising, but I wonder if any of them will catch on and stick around.
I'll have to check out the Zend studio. I've used Eclipse before for Java, and I found it to be slow and awkward. Again, maybe just my brain just being used to VS. Thanks for the suggestions.
|
stevo
Veteran
Posts:
924( 7.21%) Threads: 229( 13.71%) Private Posts: 0
|
This user's posts are being ignored. Show Post?
BTW, I wasn't at work today, which is why I wasn't commenting back and forth with you guys. I was actually at home getting stuff done
|
Chops
Administrator
Posts:
2738( 21.37%) Threads: 326( 19.52%) Private Posts: 1
|
This user's posts are being ignored. Show Post?
|
Posted: 3/3/10 10:02:03pm
|
Edited: 3/3/10 10:06:15pm
|
|
| ...and everything has a consistent naming convention. Try to find all those functions in PHP, some are abbreviated (substr) some have underscores (str_pad). Some functions do the same thing as others. Some functions have such ridiculous names it's hard to take it seriously. |
This is a problem with PHP all over the place. You'll find functions don't have consistent argument order as well. In my case, I almost always use preg_match and preg_replace to do perl regular expression stuff. They're very flexible functions, and then require you to only remember those two. In any case, PHP has a lot of issues like that, and you'll have to get comfortable looking up functions in the documentation pretty frequently, at least until you start remembering certain functions without consulting the docs. | Classic ASP was like PHP. They were immature scripting languages for generating HTML. Obviously the way we use the web has change a lot from just generating basic HTML. ASP.NET is a huge change from ASP. PHP has had some improvements bolted on, but it's still PHP. |
PHP is much like Classic ASP. $_GET = request.querystring, $_POST = request.form (or whatever). ASP.Net is a reworked ASP with the .Net framework bolted on. ASP.Net is a different language than Classic ASP. PHP is still PHP, just as C is still C, but C# isn't C++ (C# is a new C, just as ASP.Net is a new ASP, imo) | OOP in PHP is a joke. No overloads. No private functions. I don't even want to get into dealing with PHP variable "types". |
Yeah, PHP doesn't support any kind of overloading, as far as I know (including function overloading). The closest you get to overloading is optional parameters. | to deal with some basic date/time math and formatting and read/write from the database. You can blame MySql for some of that too. But I know dates just work with MSSQL and .NET without dicking around writing string functions to parse the stupid thing out. |
My opinion: don't deal with the mysql date/time types. Use unix_timestamp() (which is just the date represented as an integer with the number of seconds since 1970) and use the php date() function for displaying. Otherwise parsing, redisplaying, reparsing and reformatting for mysql is a pain in the ass. With timestamps, you can deal in increments of seconds, which are very easy to understand. If you need to do more intense date comparisons, date_diff should work alright - though I don't think I've ever used it. Otherwise, the times can just be compared by hours or days or whatever. Aside from leap years and daylight saving, a day = 24*60*60. integer -> date string php date() date string -> integer php strtotime() For the whole IDE issue, I can't stand having to rely on an IDE to do coding. All I want and need is syntax highlighting, and that eliminates a lot of interface-shock when switching to another language/interface. My point is that ditching the IDE has been (I would say) liberating, even if it would be nice if my editor knew the argument order of substr (is it "needle,haystack" or is it "haystack,needle"), it takes two seconds to look up. If you lock yourself into an IDE, you become welded to that interface. ---- Do it for the Lobster
|
Chops
Administrator
Posts:
2738( 21.37%) Threads: 326( 19.52%) Private Posts: 1
|
This user's posts are being ignored. Show Post?
Apparently MS has some kind of intellisense thing for PHP http://msdn.microsoft.com/en-us/library/cc295492.aspx---- Do it for the Lobster
|
stevo
Veteran
Posts:
924( 7.21%) Threads: 229( 13.71%) Private Posts: 0
|
This user's posts are being ignored. Show Post?
| If you lock yourself into an IDE, you become welded to that interface. |
That's a good point. Though I also think its foolish to not use tools that make your work easier and faster. That's probably the root of my recent frustration. I only have limited time on nights and weekends to work on this stuff, and I just hate wasting the time looking up crap and dealing with the stupid nuances of PHP. In the end the language probably doesn't matter much, I should just use whatever is best for me to get stuff done, since you don't get anywhere until you actually make and finish something. I would love to be able to spend the time tinkering with new languages and these different Python and PHP frameworks, but I don't have the time now.
|
skeezer65134
Veteran
Posts:
2364( 18.45%) Threads: 150( 8.98%) Private Posts: 0
|
This user's posts are being ignored. Show Post?
| ...and everything has a consistent naming convention. Try to find all those functions in PHP, some are abbreviated (substr) some have underscores (str_pad). Some functions do the same thing as others. Some functions have such ridiculous names it's hard to take it seriously. |
Yeah, that's a pretty huge problem all of PHP. Underscore or no underscore, Order of parameters passed in, obscure function names, abbreviations, will it return the change or affect the variable by reference, etc. Luckily, looking things up on php.net is pretty simple and you can usually sort it out in short order... usually. Most/all of the IDEs offer some kind of code assistance, but you still need to know what you want to do to get a start on the right function. Variables aren't objects like it sounds they are in .NET (or javascript, for example); you don't manipulate the variable, you pass it. | OOP in PHP is a joke. No overloads. No private functions. I don't even want to get into dealing with PHP variable "types". | Yeah, PHP doesn't support any kind of overloading, as far as I know (including function overloading). The closest you get to overloading is optional parameters. |
I've honestly never heard of overriding before. Sounds interesting, but I can't think of any practical applications for it... care to share some? As for private functions, there sure are. That was one of the important changes is PHP5; private and protected methods and parameters. In PHP4, everything was public, which could cause a lot of problems, as you could imagine. I think it's inherently impossible to do overloading in PHP since it's a loose-typed language; that is, the variables really have no inherent "type", they are adjusted to meet the demand. That has its advantages and disadvantages. It's kind of nice for math stuff ($sum = 1 + '1'; //2), and you can test the variables in the function itself if you need to do other magic in there (is_array(), is_int(), is_float(), is_string(), etc). And, as you pointed out, you can use optional parameters. | What put me over the edge and prompted me to write this was trying to deal with some basic date/time math and formatting and read/write from the database. You can blame MySql for some of that too. But I know dates just work with MSSQL and .NET without dicking around writing string functions to parse the stupid thing out. |
What are you trying to do? And why are you parsing strings? Just toss the data into strtotime() and it'll parse it for you, returning a unix timestamp. Then you can use date() to convert to whatever format you want. Example; $date = date('Y-m-d h:i:s', strtotime('last week')). You can put almost anything in to strtotime and it'll magically figure out what you mean. Certain formatting results in different results though, but things like 2009-01-02, 12/1/10, tomorrow, last year, last week and so on all work as expected. | My opinion: don't deal with the mysql date/time types. Use unix_timestamp() (which is just the date represented as an integer with the number of seconds since 1970) and use the php date() function for displaying. [...] Aside from leap years and daylight saving, a day = 24*60*60. |
I've gone this route too. The only downside to that is you often find myself wanting to run custom queries filtering by date. If I'm running something like that in PHP, it's easy enough to make that give me the timestamp for comparison, but if I'm writing the query by hand to look something up quick, I need to mess around with the MySQL date and time functions which is always kind of a pain to look up. I find it's easier most of the time to just use date or datetime fields. And as you pointed out, thanks to daylight savings and whatever else, don't expect to simply add 86400 (24*60*60) seconds to a timestamp to add 24 hours. Some dates have 25 hours, others 23. It's bitten me in the ass several times. I've since learned to use mktime(), which is a little inconvenient (read, a lot more typing), but it's far more reliable. Example: $tomorrow = $timestamp + 86400; //don't do this $tomorrow = mktime(date('H',$timestamp), date('i',$timestamp), date('s',$timestamp),date('n',$timestamp),date('j',$timestamp)+1,date('Y',$timestamp)); //add one day in mktime, which will return the correct unix timestampPretty annoying. I guess it seems there are some frameworks for PHP that are promising, but I wonder if any of them will catch on and stick around.
I'll have to check out the Zend studio. I've used Eclipse before for Java, and I found it to be slow and awkward. Again, maybe just my brain just being used to VS. Thanks for the suggestions. |
I assume Zend Framework will be around for a while, since it's written by the folks known for their PHP skillz. CakePHP has a huge following as well, I wouldn't expect it to be supplanted easily or quickly. Some of the other ones are kind of up in the air, but each has its own niche. As for Zend Studio, it was OK when I used it. I can't stand IDEs though. Importing my site, navigating with the clunky sidebar menu to files, etc. The on-the-fly function assistance is nice, but not worth the price of admission. Give me some syntax highlighting and I'm good to go. I wish I could find something that could "predict" which function I want to use based on the files I'm including, and some claim to do that, but I've not yet bothered to figure out how to set it up. | For the whole IDE issue, I can't stand having to rely on an IDE to do coding. All I want and need is syntax highlighting, and that eliminates a lot of interface-shock when switching to another language/interface. My point is that ditching the IDE has been (I would say) liberating, even if it would be nice if my editor knew the argument order of substr (is it "needle,haystack" or is it "haystack,needle"), it takes two seconds to look up. If you lock yourself into an IDE, you become welded to that interface. |
Well put. I do with Vim could collapse functions so I didn't have to scroll around quite so much. I believe there's a plugin for it, but I've not seriously looked in to it. I've also become dependent on Vim's way of doing things via the keyboard. I can't stand the whole highlighting with the mouse step anymore. I've tried using text editors with syntax highlighting, and I always come back to Vim within a few hours. Plus, I love the terminal! So much easier to navigate around. Mixed with screen... delicious! ---- no fat chicks
|
stevo
Veteran
Posts:
924( 7.21%) Threads: 229( 13.71%) Private Posts: 0
|
This user's posts are being ignored. Show Post?
| I've honestly never heard of overriding before. Sounds interesting, but I can't think of any practical applications for it... care to share some? |
OverLOADing. (Overriding is actually a different thing, like you override a function from a class you're inheriting) Use overloading to simplify and reduce the number of functions you need. Say you have a function that searches for records. You could have: FindRecords(string name) return a list of matching records by name FindRecords(int id) find records by id So you still have two functions, but you don't have to name them FindRecordsByName and FindRecordsById. The signature (the number of type of parameters) of the function can't be the same otherwise the code doesn't know which one to call. Yeah I think you're right that you wouldn't be able to do overloading with PHP because its loosely typed. Which is another thing I find obnoxious. Well maybe you can do private functions. I was trying and I was getting errors, I don't know what I was doing wrong. | What are you trying to do? And why are you parsing strings? Just toss the data into strtotime() and it'll parse it for you, returning a unix timestamp. Then you can use date() to convert to whatever format you want. |
Yeah that looks like what I need. I didn't know about strtotime(). Call me a pussy, but I like having the a DateTime type that abstracts all the leap years and DST for me and not dealing with $tomorrow = mktime(date('H',$timestamp), date('i',$timestamp), date('s',$timestamp),date('n',$timestamp),date('j',$timestamp)+1,date('Y',$timestamp));
|
skeezer65134
Veteran
Posts:
2364( 18.45%) Threads: 150( 8.98%) Private Posts: 0
|
This user's posts are being ignored. Show Post?
|
Posted: 3/4/10 10:58:37am
|
|
|
Sorry, that was a mis-type. | So you still have two functions, but you don't have to name them FindRecordsByName and FindRecordsById. |
Pretty interesting. Why not just test the type that was passed in though? function findRecord($record){ if(is_int($record)) { //search by id } elseif(is_string($record)) { //search by name } else { //error, return false } }The idea is the same and it seems to me like it would be easier to read too. | Well maybe you can do private functions. I was trying and I was getting errors, I don't know what I was doing wrong. |
There's a different between protected (classes that extend can use the method, but you can't execute it directly on the object) and private (only that class can use the method). Maybe that was your problem? Call me a pussy, but I like having the a DateTime type that abstracts all the leap years and DST for me and not dealing with
$tomorrow = mktime(date('H',$timestamp), date('i',$timestamp), date('s',$timestamp),date('n',$timestamp),date('j',$timestamp)+1,date('Y',$timestamp)); |
Psh.... pussy. I kid, I kid. Yeah, dates in PHP are a pain compared to other languages I guess. There are some options (I could only find that one quickly though) for dealing with dates, but it isn't very fun, much like Javascript. I could also be wrong about how I add days, but that's the only *reliable* way I could think of to do it. Thankfully, the one application I've needed to do that in, I only needed the date, not the time, so I could pass 0 as the first 3 parameters. ---- no fat chicks
|
Chops
Administrator
Posts:
2738( 21.37%) Threads: 326( 19.52%) Private Posts: 1
|
This user's posts are being ignored. Show Post?
|
Posted: 3/4/10 5:54:45pm
|
Edited: 3/4/10 5:57:01pm
|
|
The tomorrow() function I'd use, probably slow, but unless it's running repeatedly and regularly (a couple thousand times a day is no big deal, a couple million times a day could be more of a problem), no reason to optimize:
// $days = 1 would be tomorrow // $days = 2 would be day after tomorrow // returns timestamp of X days from now // if $retain_time is true, return the new timestamp with the time as the same // should also work for negative days to get yesterday. function days_from_now($timestamp,$days,$retain_time=true) { // timestamp of the beginning of the day for the provided timestamp $beginning_of_timestamp = strtotime(date("n/j/Y",$timestamp));
// extract just the time (ie 6:30:15am) from the timestamp $time_str = date("h:i:sa",$timestamp);
// this time is guaranteed to be in the target day, though the time is not guaranteed // Notice that it increments the date by seconds in a day, then adds an additional 2 hours, just to be safe. // Since we always start a midnight, no we can be sure that 26 hours will be some time tomorrow. $target_guaranteed = $beginning_of_timestamp + 24*60*60*$days + 60*60*2;
// Just the date string of the $target_guaranteed $target_date_str = date("n/j/Y",$target_guaranteed);
// if retaining time, stick it together with the date, and return the timestamp, otherwise, just the timestamp return strtotime($target_date_str . ($retain_time ? " $time_str" : "")); }
// if timestamp is provided, do tomorrow relative to timestamp // otherwise, do timestamp of now function tomorrow($timestamp=0) { if($timestamp==0) $timestamp=time(); return days_from_now($timestamp,1); }
I need to get the improved syntax highlighter up in this bitch rather than this unintended crap.
---- Do it for the Lobster
|
skeezer65134
Veteran
Posts:
2364( 18.45%) Threads: 150( 8.98%) Private Posts: 0
|
This user's posts are being ignored. Show Post?
|
Posted: 3/4/10 11:48:32pm
|
Edited: 3/4/10 11:51:02pm
|
|
Why do you hate mktime so much? You could avoid all the date calls by using a delimiter and explode, like...
function days_from_now($timestamp, $days, $return_time=true) { if($return_time) { $times = explode('|', date('H|i|s|n|j|Y', $timestamp)); } else { $times = explode('|', date('0|0|0|n|j|Y', $timestamp)); }
$t = mktime( $times[0], $times[1], $times[2], $times[3], $times[4], $times[5] );
return $t; }
Wouldn't that be faster? 1 call to date(), 1 call to mktime() and 1 explode(). And this way you don't have to mess around with a 2 hour buffer "just in case". mktime() always returns the correct value, taking in to account leap years and daylight savings.
If explode is slower than date (and I don't know if it is or not, but I suspect date() is slower), you could skip the explode and just do a date() for each parm like I've done in a previous post.
EDIT: I wish your code tags didn't drop spaces. It would be easier to read, even without syntax highlighting.
---- no fat chicks
|
Chops
Administrator
Posts:
2738( 21.37%) Threads: 326( 19.52%) Private Posts: 1
|
This user's posts are being ignored. Show Post?
|
Posted: 3/5/10 12:27:08am
|
Edited: 3/5/10 12:27:26am
|
|
In your function, you don't have the $days parameter being used at all. It just returns the current time.
Or did you mean to do:
$t = mktime( $times[0], $times[1], $times[2], $times[3], $times[4] + $days, $times[5] );
?
In which case, that would be a better solution indeed, I didn't know mktime handled arithmetic. Again, another function I haven't used (since I don't really use date arithmetic all that often).
---- Do it for the Lobster
|
stevo
Veteran
Posts:
924( 7.21%) Threads: 229( 13.71%) Private Posts: 0
|
This user's posts are being ignored. Show Post?
|
Content of this site is © 2010 GummLANParty unless otherwise stated
Part of the SigmaSites Network.
© 2001-2010 Sigma Star Systems. All Rights Reserved.
|