CUTCODEDOWN
Minimalist Semantic Markup

Welcome Guest
Please Login or Register

If you have registered but not recieved your activation e-mail in a reasonable amount of time, or have issues with using the registration form, please use our Contact Form for assistance. Include both your username and the e-mail you tried to register with.

Author Topic: Not only reviews of this new site but also contributions gladly accepted!  (Read 3408 times)

benanamen

  • Full Member
  • ***
  • Posts: 188
  • Karma: +18/-0
What I posted only replaces the first line in the file, not every instance of <?php in the files.
To save time, let's just assume I am never wrong.

John_Betong

  • Full Member
  • ***
  • Posts: 218
  • Karma: +24/-1
    • The Fastest Joke Site On The Web
What I posted only replaces the first line in the file, not every instance of <?php in the files.


Many thanks for the recursive script  unfortunately it failed because the PHP files do not follow the normal practise of having the first line starting as <?PHP. As an example:


Code: [Select]
An uncaught Exception was encountered

Type:           <?= get_class($exception), "\n"; ?>
Message:     <?= $message, "\n"; ?>
Filename:      <?= $exception->getFile(), "\n"; ?>
Line Number: <?= $exception->getLine(); ?>


<?php if (defined('SHOW_DEBUG_BACKTRACE') && SHOW_DEBUG_BACKTRACE === true): ?>
   Backtrace:
   <?php foreach ($exception->getTrace() as $error): ?>
      <?php if (isset($error['file'])): ?>
         <?= trim('-' . $error['line'] . ' - ' . $error['file'] . '::' . $error['function']) . "\n" ?>
      <?php endif ?>
   <?php endforeach ?>

<?php endif ?>


After considerable thought I realised that with PHP files having multiple PHP tags I could insert a first line with:
Code: [Select]
<?php declare(stict_types=1); ?>


The conversion script is now 100%.

Edited by ian: Removed stray size tag
« Last Edit: 28 Oct 2019, 03:36:20 pm by ian »
Retired in the City of Angels where the weather suits my clothes

Jason Knight

  • Administrator
  • Hero Member
  • *****
  • Posts: 1049
  • Karma: +188/-1
    • CutCodeDown -- Minimalist Semantic Markup
Many thanks for the recursive script  unfortunately it failed because the PHP files do not follow the normal practise of having the first line starting as <?PHP.
So fix the script so it's not going full Gungan opening and closing PHP willy-nilly all over the place.

Code: [Select]
<?php

echo 
'
An uncaught Exception was encountered

Type: '
get_class($exception), '
Message: '
$message'
Filename: '
$exception->getFile(), '
Line Number: '
,$exception->getLine();

if (
defined('SHOW_DEBUG_BACKTRACE') && SHOW_DEBUG_BACKTRACE === true) {
echo '
Backtrace:'
;
foreach ($exception->getTrace() as $error) {
if (isset($error['file'])) echo '
'
trim(
'-' $error['line'] .
' - ' $error['file'] .
'::' $error['function']
);
}
}
}

tosses around 20% of the code in the trash. There is little as painfully annoying and aggravating to make sense of as this habit people have of derping <?php ?> onto every blasted line. PARTICULARLY with things like "if" or "foreach". That entire "colon syntax" thing being one of the many derps on my short-list of things PHP needs to get rid of.

Alongside heredoc, nowdoc, etc.

But then I'm the nutter who thinks PHP shorrtags need to be removed from the language entirely.... or at least be invalid in includes. No more <?php <?= or ?>. Just assume the entire file is code, and if you want output, ECHO it like how nearly every other blasted programming language on the planet works.

Also not sure why you'd be manually forcing an extra newline without the matching carriage returns, especially when you already have at least one CRLF pairing just naturally from how the code is written. You want extras, hit the enter key one extra time instead of escaping JUST a newline 1990's Apple style.

-- edit -- oh and are you sure $error['function'] might have unwanted whitespace at the end of it? If so just trim that and not the whole thing since there's obviously NO whitespace at the beginning.

Code: [Select]
foreach ($exception->getTrace() as $error) {
if (isset($error['file'])) echo '
'-', $error['line'],
' - ', $error['file'],
'::', trim($error['function']);
}

Lets you switch to comma delimits, which is always a win over the epic /fail/ and memory wasting of string additions in an echo.

-- edit 2 -- oh, and if this is coming from user uploaded files, I'd htmlspecialchars $error['file']  since that's an easy spot to add a XSS exploit. JavaScript as a filename.
« Last Edit: 28 Oct 2019, 03:16:20 pm by Jason Knight »
We are all, we are all, we are all FRIENDS! For today we're all brothers, tonight we're all friends. Our moment of peace in a war that never ends.

John_Betong

  • Full Member
  • ***
  • Posts: 218
  • Karma: +24/-1
    • The Fastest Joke Site On The Web
Quote
So fix the script so it's not going full Gungan opening and closing PHP willy-nilly all over the place.

Many thanks for supplying the optimised script.

The script was an example taken from a revised PHP Framework which is soon to be released.

I agree about the optimisation apart from it is a Resource Candidate version.  I managed to solve the problem of adding declare(strict_types=1); to every PHP file. Most of the 320 files were easy to fix but about twenty were quite involved - one even having 69 PHP opening tags!!!

 [2]   => 69 ==> app/Views/errors/html/error_exception.php

The above example is about displaying errors, as long as it works it is not currently of prime importance...


...my philosophy learnt a long time ago from a knowledgeable programmer's signature was:

Get it all to work then make it better...

...which agrees with Donald Knuth's profound advice:

Quote
The real problem is that programmers have spent far too much time worrying about efficiency in the wrong places and at the wrong times; premature optimization is the root of all evil (or at least most of it) in programming.

https://stackify.com/premature-optimization-evil/



My biggest problem is trying to convince the framework authors to adopt the revised PHP validation which  I have found  fails fast and helps eliminate many problems. They all agree that they prefer being able to be pass different function variable types!!!

« Last Edit: 29 Oct 2019, 06:28:02 am by John_Betong »
Retired in the City of Angels where the weather suits my clothes

Jason Knight

  • Administrator
  • Hero Member
  • *****
  • Posts: 1049
  • Karma: +188/-1
    • CutCodeDown -- Minimalist Semantic Markup
The script was an example taken from a revised PHP Framework
Well there's your problem... Frameworks... bah. There's a reason the term has gained a negative connotation for many.

Most every time they reek of "for people who know nothing about the language, BY people who know nothing about the language." They most never result in quality, efficiency, or even ease of use.

The last part being why I don't understand how people are so enamored of them. It seems most if not all of them just make people work harder, not smarter.

Bootcrap, jQuery, react, vue, laravel, codeigniter, symphony... every time I deal with any of them I can't help but feel like I'm looking at... well... how Patton described fixed fortifications. Monuments to man's stupidity.

I don't mind libraries containing useful functions, but there's something about how frameworks basically try to change -- or flat out ignore -- how the underlying language is supposed to work that always makes everything a thousand times harder to do anything I want done, much less HOW I want it done.
« Last Edit: 29 Oct 2019, 08:27:29 am by Jason Knight »
We are all, we are all, we are all FRIENDS! For today we're all brothers, tonight we're all friends. Our moment of peace in a war that never ends.

John_Betong

  • Full Member
  • ***
  • Posts: 218
  • Karma: +24/-1
    • The Fastest Joke Site On The Web
Quote
Well there's your problem... Frameworks... bah. There's a reason the term has gained a negative connotation for many.
 
I find that some PHP Frameworks are quite good because:
  • a common structure is imposed that can be easily followed especially when debugging
  • no need to re-invent the wheel. far easier to utilise existing libraries
  • your own PHP script can be used or amendments made to existing libraries
  • usually good documentation
  • helpful support forums with in depth knowledge
  • numerous special libraries usually available
  • frequent security updates and can be updated in seconds

Yes I have written some small projects without using a framework. I found debugging very difficult because I could not remember my original thoughts on creating the project :(
« Last Edit: 29 Oct 2019, 11:22:34 am by John_Betong »
Retired in the City of Angels where the weather suits my clothes

benanamen

  • Full Member
  • ***
  • Posts: 188
  • Karma: +18/-0
Quote
I found debugging very difficult because I could not remember my original thoughts on creating the project

This smells of poor project planning and implementation. Before starting any project beyond something basic you need to write out an SRS (Software Requirements Specification). You cant build something if you don't know what your building and do the most basic of planning. It costs nothing but time.

If you wrote the code, debugging should not be difficult assuming an intermediate or better level of experience. Taking on someone else's code? Yeah, debugging can be troublesome no matter how much experience you have.
To save time, let's just assume I am never wrong.

Jason Knight

  • Administrator
  • Hero Member
  • *****
  • Posts: 1049
  • Karma: +188/-1
    • CutCodeDown -- Minimalist Semantic Markup
I find that some PHP Frameworks are quite good
Methinks we have a different definiton of "good", but some of your points do have merit. (which is more than I can say for most pro-framework arguments).

Better documentation than the language they are for is often fact, but In PHP's case I'm highly skeptical as php.net is one of the BEST language references I've ever come across. Things only seem to go pear shaped when people ignore it, or fail to keep up with the version changelogs.

I don't tend to find forums relating to frameworks useful, as more often than not they're echo chambers for the bad practices that resulted in a framework being built in the first place. When the concept of the framework itself came from an ignorance of the underlying language, the forums, "experts", advice, and "special libraries" are all doing nothing more than continuing that particular flavor of derp. When the foundation is cracked and insecure, rip it out instead of building something new on top of it.

When it comes to security updates, when everything ends up built upon dependency hell, where this library relies on this framework that was built with this tool with ZERO understanding of how any of it works, applying updates becomes a nightmare and a half. See the pinnacle of such stupidity and fragility: NPM.

Whilst the PHP ones aren't as bad as client side HTML/CSS/JS, or server side node.js, they still come into being either out of misplaced laziness stemming "wah wah, I dunz wunnu lurn", or an attempt to shoe-horn in programming models and structures that have ZERO business in PHP in the first place.

So many of those "common structures" are illogical, bad practice, or just plain ignorant of what PHP is and how it works. Take MVC. It's a GREAT programming model if I'm writing event driven low level code for motor control in C++ under QNX. It is an utter mismatch of task complexity when it comes to doing anything in PHP.

I appluad the idea of separation of concerns MVC brings to the table, but they do not even come close to lining up to the non-event driven input > process > output model that is the heart of how/when PHP is called. This is why every blasted MVC framework for PHP feels like stuffing a cows size 19 hoof into a ladies size 5. A ferrier is gonna look at you like you're out of your mind.

It's not a bad concept, it just draws the lines in the wrong places, and as such results in hard to follow, hard to maintain, bloated slow code. MVC in PHP is false simplicity in the form of task complexity mismatch.

... and it seems to go like that for every framework I've ever had to deal with. It's all bloated nonsense you have to learn on top of the underlying language, that results in more complex, more cryptic, and harder to maintain code. It sure as shine-ola doesn't make collaboration any easier.

Well, unless everyone working on a project has ZERO blasted business working on the project in the first place, and are just blindly plagiarizing others without the slightest understanding of how anything works.

As @Gary-SC described said folks on DigitalPoint, frauds. We have way too much "fake it until you make it" going on in this industry.
We are all, we are all, we are all FRIENDS! For today we're all brothers, tonight we're all friends. Our moment of peace in a war that never ends.

Jason Knight

  • Administrator
  • Hero Member
  • *****
  • Posts: 1049
  • Karma: +188/-1
    • CutCodeDown -- Minimalist Semantic Markup
You know, I asked in another thread for an example of what you think is good HTML 5, but this page of yours -- whilst "valid" in the eyes of the "validation service" -- is a perfect example of what I mean by gibberish semantics, failing to leverage selectors, and a general ignorance of what HTML tags are even for.

Mind you I'm not using "ignorant" as an insult here, it just means you don't know any better. We can fix this problem.

I mean, why do you have grammatical paragraphs that seem to be in flow as a section, marked up as SEPARATE definitions for the word "source"? Why are you wasting non-breaking spaces in empty definitions to do margin's job? What makes "Coding with Strict=1 <br> is like <br> driving with a seatbelt..." and an emoji the start of major new subsections of the page when they don't even have content to mark the start OF? What makes your menu a definition list? Why put a static image that's on every page of your site static in the markup instead of external where it can be cached? Why the bold tags thrown at things that aren't legal entities or other legitimate reasons for using said tag? Especially in cases where you seem to be "emphasizing" text such as the current menu item? (that's either EM or STRONG's job)... and again, just who exactly are you quoting with these blockquotes? As much as I dislike the tag, these almost seem more like a job for ASIDE

This is EXACTLY what I mean by people not learning what tags mean or why they exist because of an ALLEGED specification written for browser makers not the people using the language to make websites, horrible outdated guides, people refusing to abandon the worst of 1990's browser war methogologies, and all the other "I can haz teh intarwebs" so common to development today.

... and that's BEFORE we talk the painfully cryptic and meaningless to anyone other than you classes that are making you work harder, not smarter... or that stupid malfing "google tag manager" rubbish being loaded in the HEAD where it really doesn't belong.

It's how you've got 13.6k of markup and 3.4k of external CSS doing the job of 6k of HTML and 8 to 10k of external CSS.

... or do you have an actual HTML 5 page that might be a better example of why you think it's good, and not the worst of HTML 3.2 masquerading as 5?
We are all, we are all, we are all FRIENDS! For today we're all brothers, tonight we're all friends. Our moment of peace in a war that never ends.

 

SMF spam blocked by CleanTalk

Advertisement