Micronations.net Forum Archive
September 07, 2010, 09:04 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Okay, here's the deal  (Read 221 times)
Ramu segirdair I
Guest
« on: February 22, 2005, 04:55 PM »

I really don't know whats going to happen. I recently talked to JoukerSendler again, but that was a week ago already... I don't know if we both have the time to work on this.



Also, there are some nasty bugs to be removed... and I'm thinking I might want to rewrite some of the code, mainly the error handling which is horribly inefficient. And PHPMX has proven that error handling should work properly. I also want to change the styles system... I'm affraid we'll end up with too much junk, the way it is now (everyone can create styles). And finally, something else that bothers me is that some actions cannot be guaranteed to be atomic (that is, they should either take place completely or not at all), which is a must for a system like this.



I just don't trust MX2 enough in this state, even with all the known bugs removed. It's too fragile. If we find the time to work on it again (and I really don't know when that will be, but trust me, I hope it's as soon as possible) I want to do more than just fix some bugs, because that isn't going to be enough.

Ramu ségirdair ranti of Lemuria



Also known as Sander Dieleman, Zayin I and Alfonso Rufio Castaneda

Logged
VA Foghorn
Guest
« Reply #1 on: February 23, 2005, 07:19 AM »

have you thought about making it open source? there are other PHP programmers out here, you know.

The Definitive Micronational Index

Logged
Ramu segirdair I
Guest
« Reply #2 on: February 24, 2005, 04:32 AM »

Open Source is a bad idea on this small scale. PHP programmers are scarce in this sector of micronationalism, and I reckon the percentage of those programmers that'd prefer to abuse errors rather than report and fix them, is a lot higher than in the "real world", so to speak. Besides, all PHP programmers were given a chance to enter the project when it started.

Ramu ségirdair ranti of Lemuria



Also known as Sander Dieleman, Zayin I and Alfonso Rufio Castaneda

Logged
Ramu segirdair I
Guest
« Reply #3 on: February 25, 2005, 05:15 AM »

Some detailed notes on how I want to change the error handling (errorhandling should be errorless, obviously...)



This is the CURRENT system:

 
$error=FALSE;

//do some stuff
if (!check) $error=10;
elseif (!check) $error=20;
else {
//do some more stuff

        if (!check) $error=17;
        elseif (!check) $error=18;
        elseif (!check) $error=33;
        elseif (!check) $error=12;
        else {
        //do more stuff

        }

}


//catching routine
if ($error) echo $errmsg[$error];


The problem with this is that, for each series of condition checks, the code to execute when they are all passed has to be nested. If there are 5 series of checks, that means 5 nested if-clauses. This is horrible to wade through when debugging.



The system I want would be something like this:

 
$error=FALSE;
//do some stuff

if (!check and !$error) $error=10;
if (!check and !$error) $error=20;

if (!$error) {
//do some more stuff
}

if (!check and !$error) $error=17;
if (!check and !$error) $error=18;
if (!check and !$error) $error=33;
if (!check and !$error) $error=12;

if (!$error) {
//do more stuff
}
else {
//reverse what was done before, if necessary!
}

//catching routine
if ($error) echo $errmsg[$error];


This offers a method of easily reversing what was already done, should an action have to be averted (which will make atomicity easier to be reached). And, no nested if-clauses: this system is entirely linear. It's gonna take some time to update all files to use this system though...

Ramu ségirdair ranti of Lemuria



Also known as Sander Dieleman, Zayin I and Alfonso Rufio Castaneda

Logged
VA Foghorn
Guest
« Reply #4 on: February 25, 2005, 02:18 PM »

yeah, the nested errors look like hell...

The Definitive Micronational Index

Logged
KingLockhart
Guest
« Reply #5 on: February 26, 2005, 07:44 PM »

Plus, unless something done in response to one condition being true is going to trigger the next condition..



it would look better and be more efficient as a case statement.

Logged
VA Foghorn
Guest
« Reply #6 on: February 27, 2005, 10:00 AM »

and for god's sake, DON'T MISS A SEMICOLON!

The Definitive Micronational Index

Logged
Trevon Andarosel
Guest
« Reply #7 on: February 27, 2005, 07:34 PM »

(nm, I was talking nonsense. There are better ways, though)



(Ok, let me try again)



I think you should make more use of functions. First, not only an $Errormsg, but an error handling function to which you pass the error id. This because I can imagine that you sometimes need to do more than only print an error message.



 

function error_handling($errorID)
{
   switch ($errorID)
   {
          case 10: //handle error # 10
                       break;
          case 20: //hanle error #20
                       break;
          default:
    }
    return;
}


(Please check the format of the switch/case loop. This is how it is done in C, not sure how it is written in PHP)



Then, you can make use of functions in the following way:



 
if (transaction_allowed(/* pass all necessary paramters */)
{
    // do transaction;
}

function transaction_allowed(/* all necessary paramters */)
{
   // do all checks here and return false if a check fails
   return true;
}




Trevon.







 

The storyteller of Ex, Umbagollah


Istvanistani Chaocrat





Ilotim parduvilin cerilis irauvisin irilis
Every end is a new beginning








Edited by: Trevon Andarosel  at: 28/2/05 11:59
Logged
Ari Rahikkala
Fan
*
Posts: 82


« Reply #8 on: March 16, 2005, 10:57 PM »

That's still wrong, you know. It might well work, true, but it's hard to read, hard to maintain, and encourages bugs. See, you're working with some sort of numeric error conditions that... well... they aren't really very meaningful. Are you supposed to have a table of "this error code means this thing" somewhere? What if you happen to typo an error ID now and audit the code three months later... every time you come across an unfamiliar error ID you'll have to check that table of yours to see what it actually means, so you'll be wasting valuable time and sanity in maintenance.



At the very least you should use symbolic constants instead of numbers for $error. If PHP offered something like enum you could get the nice benefits of static type checking, meaning that the interpreter could tell you if you missed a possible error value in the switch statement or used an undefined error value... and if it offered objects (as PHP 5 actually does), you could define an error handler class to inherit all of your specific error handlers from, which would also give the same benefit. It doesn't, though, so it might be beneficial to figure out if php.net/errorfunc could be helpful for you...









On Sander's bigger post: Starting to use guard clauses is a good thing. Seeing how good an idea it was almost made me miss this line, which made my stomach turn upside down:



Quote:
//reverse what was done before, if necessary!




You don't do this. You do not do this. OK? You'll be a good boy and use transactions. If rewriting half of the code is what it takes to get rid of the monstrosity of actually trying to ensure that you're reversing all of the changes that you actually did (which, of course, is not nearly always the same thing as what you tried to do - and in case of MySQL, not necessarily even what the server told you you did), well, I know you're a responsible developer and you'll do it. If you actually are already doing so but can't because you're using something like CREATE/DROP/ALTER TABLE, your design is broken anyway because you should have known you needed reliable transactions in the first place so you should have refrained from breaking them. If you haven't visited http://dev.mysql.com/doc/mysql/en/commit.html , damn well the code is flaky.


###############

+eMjrVZh@jRBcD#

#j#Yo*OlmzFduK####

#gGHw@sTif&ZYS+@

##################


-- Scared yet?

Edited by: Ari Rahikkala at: 17/3/05 18:18
Logged
Trevon Andarosel
Guest
« Reply #9 on: March 17, 2005, 12:49 AM »

Symbolic Errorcodes are better, I agree, but I don't think numeric codes are unmanageable. If necessary, you could add a comment after every errorcode call saying what error it is and why it is an error. The latter is recommended anyway. And then, usually you can easily derive from the conditions what kind of error is generated



Those guard clauses can be used well in combination with my idea of boolean check-functions ;)



About the SQL stuff, I'll leave that to the experts :) .



(I don't know much about programming theory, I just have done quite a bit of it and know how to keep my code understandable, or at least, when I bother to ;)  )



Trevon.

The storyteller of Ex, Umbagollah


Istvanistani Chaocrat





Ilotim parduvilin cerilis irauvisin irilis
Every end is a new beginning








Logged
extreme007
Fan
*
Posts: 2,387


« Reply #10 on: March 17, 2005, 03:39 AM »

enum still uses number system... only you can access them through constant words... a number list, like that done by Ramu is just as good... you only need to know what goes for what.. and that can be done simply by writing them out on top of file.. or wherever.. and since this code isn't open-sourced... there is no need to worry about other people not understanding it!





ok.. i tried to code something... but i am still left with nested if/else statements.....



a bit more info could have help.... like for example: i don't understand the 5 series of checks.. is that like going through that chunk of code 5 times? or you got 5 nested if/else statements? or 5 ice creams?

Discover, Invent, Theories, Experiment,



Advance Science,

Advance Extremism,

(in Karnali, Republic of)

Logged
Ari Rahikkala
Fan
*
Posts: 82


« Reply #11 on: March 17, 2005, 04:06 AM »



1 ,

2 .

3 Hi

4 I

5 You

6 a

7 already

8 am

9 and

10 anyway

11 are

12 between

13 but

14 decoded

15 easier

16 have

17 is

18 it

19 know

20 list

21 mappings

22 message

23 numbers

24 of

25 on

26 part

27 prove

28 since

29 symbols

30 than

31 that

32 the

33 there

34 this

35 to

36 top

37 understand

38 writing

39 you



3 2 4 8 34 22 35 27 31 29 11 15 35 37 30 23 2 5 7 19 18 1 28 39 16 7 14 6 26 24 34 1 13 10 33 17 6 20 24 21 12 29 9 23 25 32 36 24 34 22 2


###############

+eMjrVZh@jRBcD#

#j#Yo*OlmzFduK####

#gGHw@sTif&ZYS+@

##################


-- Scared yet?

Logged
extreme007
Fan
*
Posts: 2,387


« Reply #12 on: March 17, 2005, 06:31 AM »

There is one mistake... instead of 3 2 4 8 34 22 in the begining.. it should have been 3 2 4 8 38 34 22...

Discover, Invent, Theories, Experiment,



Advance Science,

Advance Extremism,

(in Karnali, Republic of)

Logged
Ari Rahikkala
Fan
*
Posts: 82


« Reply #13 on: March 17, 2005, 09:12 AM »

That's for the sake of illustration :)  


###############

+eMjrVZh@jRBcD#

#j#Yo*OlmzFduK####

#gGHw@sTif&ZYS+@

##################


-- Scared yet?

Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.7 | SMF © 2006-2008, Simple Machines LLC Valid XHTML 1.0! Valid CSS!