Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I am trying to implement and follow some coding standards in my PHP code.
I did read a few question already asked here but I think an attempt to centralise information might help others like me. I found a few resources (6 until now):
PSR: PHP Framework Interop Group
Wordpress PHP coding standards
framework.zend.com/manual/1.12/en/coding-standard.html (I am not
allowed to post more than 2 links yet)
pear.php.net/manual/en/standards.php
The latter has a tool to help comply with it, CodeSniffer, although you can configure it to check for any standards.
drupal.org/coding-standards
https://www.codeigniter.com/user_guide/general/styleguide.html
Although they do seem to set a common ground, they do show conflicting info, for instance, the first two links, Wordpress recommends to have a space after opening parenthesis and before closing one, while PHP-FIG recommends the opposite: if ( $a === 0 ) v if ($a === 0)
Codeigniter style guide basically contradicts everything in the Wordpress guide...
Are there any other resources that might have a higher authority on the matter?
What are others using, or does it even matter to follow a "standard" if it is contradicted by another?
Ultimately the way you format your code I think will come down to these questions...
Who looks at the code? Just you?
Stick with what you feel comfortable and feels more readable for you. There are very few projects where everyone actually adheres to the full coding standards.
Will anyone else in the future look at the code?
If so use the most common standard. You feel comfortable with.
Are you building/coding off an existing codebase?
Try to match their existing standards.
I am actually working off the 'ownCloud' core for my current projects. They have this huge guide of how to format their code. NOBODY who contributes follows it. So the code looks horrendous and is so inconsistent. Any portions of code I have to work with I always reformat to my taste since there is no standards police.
Actually this question is going to get closed because the answers will be opinion based and so is mine:
I would not go by Wordpress, the code of that project is... not good. WP is for sure not popular because of it's "superior" code and architecture. If you want a blog, take it, if you want good examples of development, architecture and best practice - stay far away from it.
PEAR is just outdated IMHO. And it is not just pear that has a code sniffer, phpcs is a generic tool:
https://github.com/squizlabs/PHP_CodeSniffer
Good projects come with a ruleset for their conventions. The sniffer itself comes bundled with a few rulesets like PEAR and I think PSR as well.
The PSR standard is a pretty good one to use except the never ending tab vs space discussion. I personally think spaces for indention over tabs is idiotic because that's exactly what tabs are thought for and virtually every editor can configure the displayed tab size to match X spaces.
So I would recommend the PSR standard.
But I use whatever standard the project I'm working on is using. If I work on CakePHP I use their coding standard, if I have to work on Wordpress (please no!), I'll use theirs. For my own projects I go for PSR.
I would recommend you to read this book in addition:
http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882
It's using Java for the examples but the language doesn't really matter here.
Whatever standard you use, I'm happy you think about writing clean code and that you want to make sure you have a standard! Many "developers" just don't care and write a huge mess.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am starting a new challenge. I am on my way to learn PHP since (I already have good knowledge in HTML CSS), i would like to have you advise in a good procedure of learning this.
To be specific my final goal is to be a very developer in PHP by the end of 2015 and able to work on project on my own and/or with team as freelancer.
I would like to hear from you guys a step by step learning programs which will conduct me to have confirmed knowledge in PHP OOP and Framework Symphony2. As i don't want to skip the stages i'd like your advise :
I have basic understanding of (loop, if/else, function).
I am looking some course (updated) and exercise to push up my level slowly but efficiency. A list of step would be a great start.
I'd suggest that you ensure that have a solid understanding of generic programming principles before you focus on a specific language. Knowing markup languages like HTML is relatively easy in comparison. When you get to programming, there's a lot more things to consider.
There's plenty of available free resources that should be able to help you.
http://www.tutorialspoint.com/computer_programming/
welcome to SO. There are lots of resources out there, some easier than others for a beginner. I would start on something like code academy and augment that with resources like php.net.
Then when youve covered those tutorials (I would do all the markup stuff like HTML as well) think of a personal project and build it. Its all very well reading manuals and doing tutorials, but you need a real live project to force you into finding solutions for real debugging issues. That cant really be taught.
Its worth noting that PHP isnt the only server side language out there, so keep an open mind and be ready to investigate other avenues as you find them.
Bear in mind to be able to hold your own in the industry is very different from being able to handle your personal projects ok. There are a lot more variables (no pun intended) in industry and the skillset you need to have is often wider.
Good luck with it.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I have been learning web design/development for a while. I have basic knowledge of CSS(3),HTML,PHP,MySql(i). I also started exploring Drupal.
Now, I tried to use DRUPAL but it's not perfect. (Memory Expensive/Less Freedom). I am also not expert enough to tear down everything from Drupal and use things.
I then started to notepad and tried to create with every single HTML tag. It's not as exciting when you are not perfect.
I could combine Dreamweaver GUI and my own coding or free codes from external sources. I do not have access to DREAMWEAVER which is a great tool.
I have seen Expression Web but did not have time to explore.
Given my middle level of knowledge, and constraints, which path is best for me? (Continue with notepad(or basic html editors)/Try Expression Web/try to be happy DRUPAL/other solutions).
I want to make it dynamic with features like user registration/search feature/APIs/. I will include a lot of external codes. (This was one of the places I had difficult implementing in DRUPAL).
With the kind of things you want to do, you really need to bear down and learn how to do it in a text editor. While you don't need a mastery of PHP/JS/CSS (because of libraries and things like that), there really is no substitute for simply knowing how the back end works, especially if you're looking to create unique and dynamic webpages.
There's a free tool I used to use a while back called Komodo. It had some intellisense features for PHP/HTML.
Stay away from WYSIWYG editors at this stage - like the JNatalzia said, you should know how the back end works. There's nothing worse than trying to work with a developer who doesn't know basic HTML syntax and can't make a change that the WYSIWYG editor doesn't support (and believe me, they ALL have things you can't do without getting your hands dirty in code).
If you want to be a proficient web developer or designer, don't use any wysiwyg editor for HTML and CSS.
My suggestion to you is to work on the languages themselves, without any plugin at all, and ensure that you understand and know the basics of each of them. Use a simple text editor (NotePad++) until you feel comfortable with them, then you should move to frameworks and other tools.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Compared to some languages, PHP's syntax is a little bit long (e.g. in java calling the method of an an object is done with a period ( . ) instead of phps (->) ).
I have always wanted to write my own language but I'm only a first year bachelors student and am in no way knowledgeable enough to write a parser that converts something to byte code for the Java VM or something.
So instead I'm thinking of writing a parser in PHP that converts my syntax into PHP code then runs that using regex and stuff.
Reasons for that being:
PHP is a stable language for web sites (my syntax will be suited towards web developers)
I already know PHP at a professional level (or at least I think I do)
I have already seen an implementation of something similar: http://tetraboy.com/lolcode/lol_core.phps
This converts LolCode into PHP. And I know its just a joke but still it has been done
So since I have proof that its possible.
My question is:
Could I actually make something that I could use for future projects? e.g. Can I get it to be as fast or almost as fast as PHP is?
I'm going to give it a try either way just for the purposes of learning a little bit more about PHP and how languages are put together, but I'm wondering if I could actually turn the end result into something worth a damn.
If anything, this is a very fun learning project.
There are others that had the same idea with other languages. For instance, take a look at CoffeeScript, which is basically the same idea but for Javascript.
You can make this work, but you'll have to take into consideration the conversion process. If you're looking for performance you do not want this to be done realtime on each request. Because adding layers of complexity will simply slow down your code. Even if it's just by the tiniest bit. To rememdy this CoffeeScript offers a command line 'compiler' for pre-compilation but also allows for a lazy loading situation - which works nicely for development purposes. Such a setup might work for you aswell.
You'll want to look at PHP_LexerGenerator and PHP_ParserGenerator for implementing your parser. Even if the latter is no longer maintained :)
Good luck! ;)
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I'm currently developing a web application using PHP, but I'm considering developing the web application using the lift framework instead, because twitter and foursquare have implemented it. I know a few benefits using lift/Scala but, could you guys mention some benefits compared to PHP?
Many thanks
Resmus Lerdorf, the inventor of PHP, once said with regards to foursqaure (build with scala/lift) that it's the first site for a long time that doesn't have a single security hole he could find.
If you're having trouble enumerating the reasons why you'd use scala/lift over PHP, you'll probably want to stick with PHP. PHP is a far more mature and supported platform - oodles of documentation, huge community, tons of tools and libraries.
Scala is a great language, but the primary reason it's being used by Twitter and Foursquare is it's ability to work with enormous sets of data on a horizontally scaled architecture. These are very specific problems for these companies, and Scala was chosen for this purpose very deliberately.
As someone who has recently begun learning Scala, the community and documentation is minute compared to PHP's. Especially where Lift is concerned. And things like IDE support is still in it's early stages.
There's really no way to compare the two technologies (very different approaches). If want to use Scala, use it, but you'll probably be investing more time and energy if you're not already proficient (also, some background in Java doesn't hurt). PHP is just PHP, it's so easy to just pick up and use.
If you ask such a question you'd better stay with PHP. Once your project becomes more and more complex and you are fed up with PHP limitations the question will disappear on its own.
But Lift does not have to be the framework of your choice.
You should consider anything except PHP a good language for web applications, but Scala is a pretty excellent one, although it will change the way you think about programming as a whole. Some people can't handle that, so be warned.
PHP advantages:
Is installed even on the cheapest "5ยข-a-month" webhoster.
PHP disadvantages:
The libraries are not stable and change every now and then, often without notice.
The whole language is buggy and generally doesn't work as a sane person would expect.
The documentation is unusable, sometimes wrong, sometimes only understandable with the user supplied usage examples (which are often wrong or not optimal, too).
No quick way to see the implementation of some language-supplied code.
The API is one big mess ... this shouldn't be called API, it should be called MCOBRIM: Messy Collection of Buggy, Random and Ill-named Methods.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
When you get a description of some project that should be made with Drupal, and requires some extra-functionality (beyond core and most popular modules), how do you decide how're going to do it?
Do you spend a day or two (or week?) searching for all possible modules, narrowing down the list?
What is the cricial point to start writing own module?
What is the cricial point to start altering some more or less suitable module?
To be more precise, lets imagine I am going to do a time Booking system in Drupal 5, but there are no modules that do exactly what I want.
What are the most important pros and cons when it comes to selecting the ground to build the Drupal project upon?
I will use a pre-built module only if:
it is for UI purposes. For example, an image gallery.
it is really, really well consolideted (like the views module for example, or imagecache), is specialized in one task and does it well, and if it serves my purpose whithout any modification (because it just fits, because I can adapt the requirements to make them fit, or because it offers extension points like an api or such)
what I need to achieve is peripheral to the system, and there exists a module which will do something similar, and it is easy to modify it and then maintain it
I will make my own if:
the functionality is "core" to my system and there is not a module which fits
the modules I found are new, not actively maintained, messy coded, etc...
In fact I usually prefer coding my own modules, which I have total control over, than adopt foreing ones, with the risk of having more troubles with them than advantages...
I'd say it really depends on what it is you want to do. If what you want to do is not to complicated, and you can't find a module for it. Chances are that even if you do find one or one that is close, that you end up spending more time searching that would have spent making your own. Where that line is, depends on how skilled you are and how intimate you are with Drupal. After doing lots of small custom modules you end up with a lot of snippets you can reuse making writing new modules quite fast.
Sometimes you can even take a module and make your own to modify it, to make the origin fit your needs. For me, I usually never spend more than a few houres trying to find a module. If I can't find it by then, it's usually
Not maintained and way old.
Still in development
Even if you can get a bit of a head start you might end up struggling in the end, with bad database designs and the like. But it's hard to say where the breaking point of using others halfway there code is. It depends on how hard or how much time YOU have to spend, to make it, vs the struggles you get using it.