Getting ready for an alpha release: WeCSS/Wess improvements

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
When we unite against a common enemy that attacks our ethos, it nurtures group solidarity. Trolls are sensational, yes, but we keep everyone honest. | Game Memorial

Nao

  • Dadman with a boy
  • Posts: 16,082
Re: Getting ready for an alpha release: WeCSS/Wess improvements
« Reply #46, on December 19th, 2012, 12:02 AM »
Quite a bit = so you'd rather I put weUA::$browser['is_opera'] than weUA::is('opera'), even if I do a quick static cache?

Example:

function is($str)
{
  static $is_cache = array();
  if (isset($is_cache[$str]))
    return $is_cache[$str];
  return $is_cache[$str] = self::hasBrowser($str);
}

weUA bothers me a bit... Maybe weua or even 'weu' or weuse would be best... weUA::is() feels strange when typing it. It's a bit... alien.

Other than that, I've finished porting the functions to an object, converted Wess, it's all working I'd say. Some conversion functions in the CSS parser are going to be slower because of the weUA calls, but as they're cached...

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278
Re: Getting ready for an alpha release: WeCSS/Wess improvements
« Reply #47, on December 19th, 2012, 12:52 AM »
I didn't say that. Firstly, I seem to recall staticclass::$var as not being valid. You're accessing a property rather than a 'variable' per se, but static instances don't strictly have properties in that sense.

In terms of performance, accessing $context['var'] (assuming $context is already in scope) is faster than obj::function(), but the number of calls we're talking about in a typical page load is small enough that we can declutter $context with this.

Nao

  • Dadman with a boy
  • Posts: 16,082
Re: Getting ready for an alpha release: WeCSS/Wess improvements
« Reply #48, on December 19th, 2012, 08:10 AM »
And in loops, I'm trying to use the variable version anyway.

static::$var is definitely valid on my side... Works quite well.

Class name suggestions please... In all lowercase :)
weua, weu, weage, weuse, webro... (Challenge accepted!) (Oh that was a good episode yesterday....)

live627

  • Should five per cent appear too small / Be thankful I don't take it all / 'Cause I'm the taxman, yeah I'm the taxman
  • Posts: 1,670
A confident man keeps quiet.whereas a frightened man keeps talking, hiding his fear.

Nao

  • Dadman with a boy
  • Posts: 16,082
Re: Getting ready for an alpha release: WeCSS/Wess improvements
« Reply #50, on December 19th, 2012, 02:58 PM »
Starting to wonder if it wouldn't be, hmm, smart to have a generic 'we' (or 'you' :P) object where we'd store contextual information like browser data, RTL mode, $user_info -- we::$user['is_admin'] or we::im('admin'), maybe..?
Would save the need to globalize some stuff like $user_info obviously.

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278

Nao

  • Dadman with a boy
  • Posts: 16,082
Re: Getting ready for an alpha release: WeCSS/Wess improvements
« Reply #52, on December 19th, 2012, 07:10 PM »
Quote from Arantor on December 19th, 2012, 04:59 PM
I was thinking wesys might be better than 'we' for that, but I'm flexible.
wesys, hmm...? I don't know... I'm trying to keep things short because of the idea that we're going to be using that object a lot... ;)
Quote
I was sure static::$var didn't work, because I'm sure I'd tried it at some point.
If self::$var is allowed within the singleton, why wouldn't class::$var be allowed outside of it, as long as it's public...?

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278

Nao

  • Dadman with a boy
  • Posts: 16,082
Re: Getting ready for an alpha release: WeCSS/Wess improvements
« Reply #54, on December 20th, 2012, 05:56 PM »
Maybe it doesn't work in strict mode...? I dunno.

Anyway, I've started work on moving $user_info over to the we object.
Basically, use we::$user['is_admin'] or we::is('admin'), depending on your tastes. :)

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278

live627

  • Should five per cent appear too small / Be thankful I don't take it all / 'Cause I'm the taxman, yeah I'm the taxman
  • Posts: 1,670

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278

Nao

  • Dadman with a boy
  • Posts: 16,082
Re: Getting ready for an alpha release: WeCSS/Wess improvements
« Reply #58, on December 21st, 2012, 06:09 PM »
It's is('admin'), not is_admin(), but it's all right to add a helper function... ;)

BTW, I made a few performance tests... 100k calls for each.

(local) $browser['is_ie6'] => 0.02s
we::$browser['is_ie6'] => 0.036s
we::is('ie6') => 0.32s

Oops...
After some heavy micro-optimization on is(), I managed to get it down to 0.2s, it's still about 10 times slower than a local variable test, or 5 times slower than an object variable test, but we're talking about a function that will never, ever be called 100.000 times over the course of a page execution... Even calling it a thousand times will only add 2 milliseconds to the execution time.
Is that okay..?

Arantor

  • As powerful as possible, as complex as necessary.
  • Posts: 14,278