bcosca / fatfree

A powerful yet easy-to-use PHP micro-framework designed to help you build dynamic and robust Web applications - fast!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Source code is really hard to read and understand

winternet-studio opened this issue · comments

commented

The source code is terribly hard to read and understand! Why not write it so that other people can easily understand it and help contribute to the framework better?!

Just look at this example and try to follow what is going on...!

$prior=$this->hive['ERROR'];
$header=$this->status($code);
$req=$this->hive['VERB'].' '.$this->hive['PATH'];
if ($this->hive['QUERY'])
	$req.='?'.$this->hive['QUERY'];
if (!$text)
	$text='HTTP '.$code.' ('.$req.')';
$trace=$this->trace($trace);
$loggable=$this->hive['LOGGABLE'];
if (!is_array($loggable))
	$loggable=$this->split($loggable);
foreach ($loggable as $status)
	if ($status=='*' ||
		preg_match('/^'.preg_replace('/\D/','\d',$status).'$/',$code)) {
		error_log($text);
		foreach (explode("\n",$trace) as $nexus)
			if ($nexus)
				error_log($nexus);
		break;
	}
if ($highlight=!$this->hive['CLI'] && !$this->hive['AJAX'] &&
	$this->hive['HIGHLIGHT'] && is_file($css=__DIR__.'/'.self::CSS))
	$trace=$this->highlight($trace);
$this->hive['ERROR']=[
	'status'=>$header,
	'code'=>$code,
	'text'=>$text,
	'trace'=>$trace,
	'level'=>$level
];
$this->expire(-1);
$handler=$this->hive['ONERROR'];
$this->hive['ONERROR']=NULL;

Look, not to demean @bcosca 's work , but it's impossible not to be blunt when saying this:

I don't think the project is going to receive any further attention... there hasn't been any major updates for over 2 years and a lot has come to pass on the PHP realm since F3 was a first conceived (new features , PSRs, etc).

I'm not here to toot apocaliptic horns or anything , telling if a project is defunct is the owners own choice, but I feel it's only fair to give a head's up to people looking to use the framework:

In all honesty , I don't believe that F3 is a good fit for a modern PHP app and ,unless you have some very edge case or really want to adopt and mantaing the framework, you might want to consider some of the other microframeworks around (Slim and Lumen seem to be the popular choices)

@winternet-studio I don't think you are describing a bug.
I think you are missing an important point, F3 is made with PHP for PHP. It uses same object oriented paradigms and patterns but is not meant to be object oriented first.

True, it is less popular than the other micro-frameworks but it has an amazing performances in term of CPU and memory.

We are using it in commercial projects, some of them have high traffic. It took us some time to master it and understand it well. We figured out that we were doing things wrong by adding PHP packages to it and found that most of what we have been doing using tier packages was possible with only F3.

It is hard to follow the code and debug it, but if you are familiar with Regexes (I love hem) and know the PHP functions you will find that @bcosca is doing this from a perspective of a developer who really masters the web requirements.

The key to understand the code that have been shared above is to know the hive variables well.

To add to @GhaziTriki comment: F3 has been started in 2009 and hasn't changed that much in code-style terms. Back then it was meant to be the fastest and smallest PHP web framework out there. Back in the time, automatic tools for code minification weren't that popular like they're right now so F3 was built like that by hand.

If you prefer to work on a framework instead of working with a framework you either have to go the hard way to dig through F3's code base or you you switch over to something properly structured.

All in all, I don't see this as an actual "issue" because the outcome of this would be a major refactor of everything which would've happend in the past years already if there was time and need for that.

Going to close this issue. Feel free to keep the conversion open though.

Using with dependency injector F3 is awsome for routing and for views/templating while your code can remain SOLID, OO and clean.

Every bug and strange behavior got fixed in a few hours I came out with. I trust in F3 and in it's developers, it won't break anything.

commented

Look, not to demean @bcosca 's work , but it's impossible not to be blunt when saying this:

I don't think the project is going to receive any further attention... there hasn't been any major updates for over 2 years and a lot has come to pass on the PHP realm since F3 was a first conceived (new features , PSRs, etc).

I'm not here to toot apocaliptic horns or anything , telling if a project is defunct is the owners own choice, but I feel it's only fair to give a head's up to people looking to use the framework:

In all honesty , I don't believe that F3 is a good fit for a modern PHP app and ,unless you have some very edge case or really want to adopt and mantaing the framework, you might want to consider some of the other microframeworks around (Slim and Lumen seem to be the popular choices)

For me - in case of F3 - missing updates are more of a sign that the framework is mature enough to cope with most common problems.
But of course there are people that need updates of whatever every month and new mayor breaking releases every half year to feel there is a progress 🙄

commented

Well if the framework is not being developed further then of course the point is mute concerning this project - but then in general I just want to give a shoutout to all programmers - regardless of whehter you use object oriented paradigms and patterns or not - however you write your code PLEASE write code that is self-explainatory and that other people can understand! Especially if it will be open source.

Anyone have another suggestion for a small framework like this? I just want something that has ORM to easily work with databases AND which is very easy to install without any configuration and stuff. It's only for very small projects that are not going to expand to a big thing so it doesn't need all the bells and whistles of a normal framework. I thought F3 fit pretty good in that category! ... I might just go back to using my beloved Yii2 as a micro framework instead which I realize might be possible...

Well if the framework is not being developed further then of course the point is mute concerning this project - but then in general I just want to give a shoutout to all programmers - regardless of whehter you use object oriented paradigms and patterns or not - however you write your code PLEASE write code that is self-explainatory and that other people can understand! Especially if it will be open source.

It's not like F3 is dead. It just works the way it is and there's no reason to change that right now.

Anyone have another suggestion for a small framework like this? I just want something that has ORM to easily work with databases AND which is very easy to install without any configuration and stuff. It's only for very small projects that are not going to expand to a big thing so it doesn't need all the bells and whistles of a normal framework. I thought F3 fit pretty good in that category!

Why are you looking for alternatives? F3 is easy to install via composer and requires basically no configuration at all. F3 can be used for small and big projects and has ORM builtin. I still think that F3 does fit into your category just fine.

You can just switch to a more powerfull and modern ORM framework and still use F3 as a base.

commented

Just because the framework uses functions and techniques that that goes beyond comparisions and foreach for everything, it doesnt mean it's unreadable. Within the code it often uses results directly instead of creating temporary variables for all little steps. That saves memory but makes the code look very compact. For me it's more a sign of a very highly sophisticated peace of code and there are a lot of parts that have been developed with carefully planning and testing to achieve that kind of simplicity and flexibility. Of course there is always something to improve, but we are at a point where we only need to deal with edge cases, as the rest it battle tested and runs rock solid. Updates just for the sake of updating things, just lead to probably fat features or new bugs.
I have started to work on v4 last year again. It will tear things appart and break backward compatibility.. is that what you're waiting for? @winternet-studio

commented

@ikkez I respectfully disagree with pretty much all you are saying!

  • I believe code can be written so that it's both efficient and readable at the same time.
  • Just because code might be well tested and not need a lot of change at this point it hasn't always been like that. At a minimum it should have been readable until it got to this stage - but even so I believe code should be readable regardless! You understand what I'm saying? So that is a mute point.
  • I'm not saying you would have to rewrite everything - or even anything! Often just well-chosen variable names and a few simple well-placed comments explaining what the next few lines are doing in simple English can be very helpful. Even proper indentation and spacing can be helpful.
commented

and readable

I believe you're missing the points being made. Just because you can't read it, doesn't mean it's unreadable.

The code you posted in the original post being a case in point.

commented

No of course it will be readable to some - I would certainly hope so! It will of course eventually be a somewhat subjective opinion whether it's readable or not. I'm not a newbie programmer at all but I just in all humbleness think the code could have been written so it would be easier to understand - that's all. But if a few comments and a bit more descriptive variable names etc is so difficult for you guys to realize could maybe have been a nice idea - hey, what can I say...

I agree that there could be more comments in the code for expaining some parts. The rest is probably just a preferred code style of the author, and I'm fine with that so far... it's basically just 2 constraints: 80 chars line length (with very few exceptions) and tabs for indentation.
We'll keep an eye on proper naming and comments for further updates ;)

@winternet-studio just checkout git blame and see how old some of these lines are. Some of them are actually even older basically because of some refactoring years ago. The framework itself dates back to 2008/9.

We're aware of what you're saying but there's most certainly no refactoring just to make the code mor readable. It's something that is probably going to happen over time with new additions or fixes.

commented

We're aware of what you're saying but there's most certainly no refactoring just to make the code mor readable. It's something that is probably going to happen over time with new additions or fixes.

Of course - just something to think about as we keep programming :) Thanks for listening and discussing!