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 7 years ago.
Improve this question
I have a computer science undergrad degree and during first year, during algorithm lessons, it is pushed into my head that i should not put return in any of condition branches; if, else.
The question and some answers support me. But there is a matter about my first PHP web site building experiment. PHP code samples on the Web tell that we 'must' use else die();.
I have prepared a Web site with 'my truth in my mind' without doing all the controls to handle all possible errors without any undesirable view on the pages of Web site. The database connection have exploded, thus some smart ***es tell me that i should use else die();.
Different coding styles have varying rules and there are many of them, so while that may violate a style that you've been taught, that doesn't mean it's a wrong thing to do.
Coding style recommendations are just that - recommendations; not a law. Their goal is to provide you with a set of rules that usually result in better-readable code. However, they are always influenced by somebody's own preferences and do not in any way mean that a piece of code is invalid.
Pick one and stick to it for your own benefit, but don't be surprised that other people have different coding styles.
Related
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 2 years ago.
Improve this question
Is it bad practice to make all of my web pages .PHP pages? My main reason for doing this would be to prevent myself from writing repeating code for things such as my nav bar and footer and having these in separate files so that I can 'include' them in a way similar to below.
<?php include('nav.php'); ?>
I was made aware that you can also use JavaScript to do this however my thoughts are that relying on JavaScript for something as crucial as a nav bar would be a bad idea.
This is more of an opinion question than anything. I would not consider this to be bad practice as long as the following conditions are met:
If someone browses to https://example.com/nav.php or any similar "include only" nothing bad can happen as a side-effect. By bad I mean that if the .php expects to be included from wider context and ends up wiping the database for example. Easy way to prevent this is to declare a constant in your main "page" files and check that in the includes.
You find this approach easy to manage. In a larger page you might end up with a lot of files that are included from different places and expect certain global variables to be present. In these cases structuring your directories correctly and documenting the code is essential.
Happy coding!
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 5 years ago.
Improve this question
Do WordPress Page Builders increase page load speed and as such, should these be avoided by those competent at hard coding?
Or is there something else that I am missing as the only real value, I can see with Page Builders, is that they help reduce time spent on coding.
Use code. Page builders add additional load time. Your site may also become less portable and maintainable because a bulk of the design for your site could be stored in the database. It really depends on the situation. I would assume code to be a little cleaner though.
Page builders add additional code which are mostly unnecessary so it means the page is heavier and therefore the speed is lower, i would recommend to always make the code by a coder, but if the page just have little content then probably a page builder cold come in handy
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
Is this a pitfall that some have encountered? I have only recently discovered the notion of defining a constant to use globally but find myself attempting to define away each and every repetitive block of code (no matter how long).
Can I get two major reasons when to avoid using constants and one supportive reason/example illustrating great use?
The reason not to use constants - Having global data is typically considered bad practice. Since PHP has the ability to be object oriented, most well written software takes advantage of it. Here is a pretty good explanation without getting too lengthy about encapsulation and abstraction.
The reasons I consider using them, typically for things that are reusable, that I would like to change all at once. an example i can think of is contact information. It's usually in the footer, sometimes the header and typically on a contact page. If I want to reuse a template I can just change the information in one spot and effectively update it on the entire site. Usually the database credentials live in the same file. I'm not saying this is the best practice, but it's convenient to only have to make changes to one file for global changes to a website.
That's just my 2 cents.
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 looked at languages such as PHP, Python, Ruby and Skala. However, I haven't found any language that meets the requirement below:
I'm looking for a language that is lax enough to quickly write a web application prototype with (without bothering with best practices), but is also sophisticated enough to support me when trying to "refactor to design patterns".
Is there a language/web framework specifically created for this purpose? An example would be PHP, optionally acting like Java if the developer requires it.
Refactoring bad code "to design patterns" has nothing to do with the language's sophistication.
You can really try any of the mentioned languages and see which one is the easiest for you to learn, you can't go wrong with any of them.
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 working on my first opensource project, and I found useful do do an html generator class, treating the html elements as php objects, but now I don't know if it really makes sense in the real world.
Have you ever needed an html generator class for you projects?
If your answer is yes, what would you find useful on it?
If someone wants to help in the project, you are welcome to the repository on github.Github repo
Thank you.
This approach, although liked by many at first sight, always fails a reality check.
Please learn about templates - the only way to go in dealing with HTML from PHP applications.
You need them only if you are some outsourced worker from India or China. Otherwise do not use them since you have potential to ruin your career and credibility.
Those tools are built for doing very dirty code without any future prospects.