The online racing simulator
The Off Topic Programming Thread!
... Let the off topicness begin!

What is your most hated function call?

For me it's preg_match in the PHP Programing Langue, I just don't get it, however many times I read the manual.
Yeah, I have failed to get reg expressions full stop. I mean I know in principle what they do, but arggh that syntax does my head in.
Regular expressions are definately one of those things that drive me nuts, as well. Unfortunately I have to use a variety of editors, both personally and at work - all of which have radically different regex markup. For instance ^p in Ultra Edit for a newline, instead of \n.

If you start using something like gVim, or Scite with a decent RegExp search and replace, you do start learning it more. Often though, I have to resort to testing things on my regexp tool

Currently the functions doing my head-in, are in the APR-Util bucket and brigade module. It makes sense, until you want to run a transform on the whole set of data, instead of a chunk Although I love the new Apache HTTPD filter system, its rather different and confusing for a few days (since it relies on APR buckets and brigades).

Edit: if anyone knows the best way to do the above, please give me a shout
#4 - filur
Regular expressions are by far my favorite tool.

Very tricky to get used to, but once you're there pretty much any other string parsing thingie seems completely useless. The only problem is when expressions get very long.

@Dygear, sections on regular expressions in the PHP manual is basically for people who already know how to use them, it's more just a list of modifiers and basic syntax, google for some tutorials or buy a book instead, it'll be worth it.

Most hated function call? fork(), it doesn't work on Windows. (PHP)


<?php 
php
  $str 
stream_get_contents(fopen("http://liveforspeed.net","r"));
  echo 
preg_replace(array(
                      
"/\n/ms",
                      
"/<.[^>]*>/ms",
                      
"/.*April.[^W]*|(?=\!).*/ms",
                      
"/a(r)e/",
                      
"/th(?=[ai])/"
                      
),
                    array(
                      
" ",
                      
"",
                      
"",
                      
"\\1",
                      
"d"
                    
),
                    
$str) . "!!1! (rly?)\n";

?>

Quote from filur :Regular expressions are by far my favorite tool.

Same here. It's the reason i got into perl in first place. I admit that regex is a pain in almost every other language, but it just part of the landscape in perl.

Most of my programming now revolves around building object models, but when someone hands me a text file and needs the data to be converted into something else, or have something extracted from it, I always whip up a perl script to do the regex and write the data out in a format that's easier to parse for my other code.
Thanks filur . I'll look more into the function as well, see what it does ...
[edit] ... LOL The script tosses this out " We r pleased to announce dat there will be an important S2 update dis month!!1! (rly?) " ...
Parsing Packets With PHP
Parsing Packets With PHP (Cool Title Don't Ya Think - God I Need To Get A Life.)

Anyway, I have been playing around with the code that was posted on the fourms here not to long ago by our resident PHP InSim Guru filur. Anyway, in his exprament he simply took the first 3 charaters from the packet and added a little Keanu Reeves 'Whoa' to it then thow it out for us all to see. But it only had the packet identifier, it did not have information on what the packet really had in it.

So this it my (failed) attemp to read a LAP packet from the server using PHP.


<?php 
php

stream_set_blocking
$socketOut fsockopen"udp://127.0.0.1"65000 ), FALSE );
stream_set_blocking$socketIn stream_socket_server"udp://127.0.0.1:64999"$errno$errstrSTREAM_SERVER_BIND ), FALSE );
fwrite$socketOut"ISI\0" pack"Scc"649991+8+16+32) . str_pad"asdf"16"\0" ) );

$time microtimeTRUE );

while( 
microtimeTRUE ) - $time 30 )
{
    if( 
$packet fread$socketIn1024 ) )
    {
        
$time microtimeTRUE );
        switch( 
substr$packet0) )
        {
            case 
'LAP':
                
$LAP['LAP']    = substr$packet0);
                
$LAP['UName']    = substr$packet428);
                
$LAP['PName']    = substr$packet,2933);
                
$LAP['CName']    = substr$packet,3466);
                
$LAP['Time']    = substr$packet,6761);
                
$LAP['PlyNum']    = substr$packet,6263);
                
$LAP['UniqueId']= substr$packet,6465);
                
$LAP['VerifyId']= substr$packet,6668);
                break;
            default:
                echo 
"Packet " substr$packet0) . " Is Unhandled\n";
        }
    }
    
usleep(100 1000);
}

?>

#8 - filur
Quote from Dygear :So this it my (failed) attemp to read a LAP packet from the server using PHP

That's pretty similar to my thingie, tho mine isn't hardcoded like that.

Anyway, you're not using substr correctly, the parameters are string, start offset, length. You're thinking string, start offset, end offset, which isn't right.

<?php 
$LAP
['UName']    = substr$packet428);
?>

Will actually read 28 bytes from offset 4, not the range 4 - 28.
Ahh, that explains it, should of read the manule one more time . Thanks mate .

[edit]
:HUGE GRIN ON HIS FACE:


<?php 
$LAP
['LAP']     = substr$packet0);
$LAP['UName']   = substr$packet424);
$LAP['PName']   = substr$packet,2824);
$LAP['CName']   = substr$packet,5232);
$LAP['Time']    = substr$packet,844);
$LAP['PlyNum']  = substr$packet,881);
$LAP['UniqueId']= substr$packet,891);
$LAP['VerifyId']= substr$packet,901);
print_r$LAP );
?>

How would I go about reading the data tho? The unpack function is not very helpful, but once more, I must be using it wrong ...

Array
(
[LAP] => Array
(
[1] => L
)

[UName] => Array
(
[1] => D
)

[PName] => Array
(
[1] => ^
)

[CName] => Array
(
[1] => F
)

[Time] => Array
(
[III] => 1125888
)

[PlyNum] =>
[UniqueId] =>
[VerifyId] =>
)


<?php 
case 'LAP':
        
// Get Data
        
$LAP['LAP']     = substr$packet0);
        
$LAP['UName']   = substr$packet4,24 );
        
$LAP['PName']   = substr$packet,28,24 );
        
$LAP['CName']   = substr$packet,52,32 );
        
$LAP['Time']    = substr$packet,84);
        
$LAP['PlyNum']  = substr$packet,88);
        
$LAP['UniqueId']= substr$packet,89);
        
$LAP['VerifyId']= substr$packet,90);
        
// Make Readable
        
$LAP['LAP']     = unpack"a"$LAP['LAP'] );
        
$LAP['UName']   = unpack"a"$LAP['UName'] );
        
$LAP['PName']   = unpack"a"$LAP['PName'] );
        
$LAP['CName']   = unpack"a"$LAP['CName'] );
        
$LAP['Time']    = unpack"IIII"$LAP['Time'] );
        
$LAP['PlyNum']  = unpack"I"$LAP['PlyNum'] );
        
$LAP['UniqueId']= unpack"I"$LAP['UniqueId'] );
        
$LAP['VerifyId']= unpack"I"$LAP['VerifyId'] );
        
print_r$LAP );
?>

I figured out the unpack types by trial and error, what i use is:
  • char: just grab raw (plain substr).
  • byte: signed char "c".
  • word: unsigned short "S", note that input must be 2 bytes.
  • short: signed short "s".
  • int: signed integer "i".
  • MSHT: 3x signed char "c", skipping thousands since they're never present.
The other types listed in InSim.txt that i haven't included are AFAIK only present in packets not needed in server handling, float, for example, is only used to present replay speed and FOV.
Right, thanks mate .
Something I've always hated, but today more than usual; reading other people's code. Unless both myself and the other programmers / coders are in a "metal-sync", I just tend to think "wtf, I wouldnt do it like that" and not get past it. Either that or I need a few days to get into the api and mindset of the coders.
Quote from the_angry_angel :Something I've always hated, but today more than usual; reading other people's code. Unless both myself and the other programmers / coders are in a "metal-sync", I just tend to think "wtf, I wouldnt do it like that" and not get past it. Either that or I need a few days to get into the api and mindset of the coders.

know this problem, too but since working in a large software company, where you get some bugs assigned of which you didn't even knew the program itself you learn this very fast
I've just come across some legacy code from within our firm. Its driving me nuts, which has driven me to rant about it
installed eAccelerator on this forum server yesterday. I'm so happy about it I wanted to praise it
Quote from the_angry_angel :Something I've always hated, but today more than usual; reading other people's code. Unless both myself and the other programmers / coders are in a "metal-sync", I just tend to think "wtf, I wouldnt do it like that" and not get past it. Either that or I need a few days to get into the api and mindset of the coders.

Different indenting is enough to make me loathe a piece of code. :zombie:
Quote from filur :installed eAccelerator on this forum server yesterday. I'm so happy about it I wanted to praise it

Cool I'll be watching with baited breathe, to see how the forum survives this time

Edit: Now all you need to do is upgrade to apache 2.x and do some mod_mem_cache fu (if you can spare the memory that is)

Quote from filur :Different indenting is enough to make me loathe a piece of code.

Tell me about it. I usually end up re-indenting

On a different note, has anyone else tried php with ZTS enabled, stripped out any "unsafe" php modules, with the apache worker or event mpm's recently?
Well, I am glad this thread is getting use from other's then my self!

No rants today, happy to be using PHP makes life easyer. . <Said the noob programmer>
Okay, my turn for a rant, I've always, ALWAYS hated the "traidional" blocking.

if (Value){
FooBar();
}

May not seem like a big deal, but it's annoying when you're blocking huge nested statements..I think it just "looks" horrible.


switch (Irp->MajorFunction){

case IRP_MJ_DEVICE_CONTROL:
case IRP_MJ_INTERNAL_DEVICE_CONTROL:

switch (IrpStack->Parameters.DeviceIoControl.IoControlCode){

case IOCTL_SOME_DEVICE:

switch (Request->ReqeustNumber){

case REQUEST_ALLOCATE_ADDRESS_RANGE:
/*
Bunch of stuff goes here







*/



}
}
}

Just a nit pick...
if (Value){
FooBar();
}

No indent at all? I'd refuse to read it.

The worst kind of indent is ..


if (Value)
{
if (otherValue)
{
hello();
}
}

And my wonderful indent looks like ..

if (Value) {
hello();
}

.. that.
I much prefer

void Foo(
IN ULONG Param1,
OPTIONAL ULONG Param2)
{
if (SOME_VALUE == Param1)
{
Bar(Param1);
}
}

IMO, just makes it SO much easier to visualize the blocks that way.
Quote from filur :Different indenting is enough to make me loathe a piece of code. :zombie:

The indentation wars are the worst. When i'm using emacs, I can hit some keys and have the whole thing re-indented. But i have to refrain myself from the temptation, because it really messes with revision control, as it sees every line as changed which will come back to bite you when you try to dig for when a change entered the system.

In Visual Studio, our team has just agreed to all suffer to the MS auto-formatting. Sure it's not exactly the way any of us would do it, but at least its a consistent compromise. Although I still use 2 spaces for indent when everyone else uses 4
Quote from sdether :Although I still use 2 spaces for indent when everyone else uses 4

^ YEAH!!!!

*grumbles* Can't STAND the 4 space indenters...
Quote from der_jackal :^ YEAH!!!!

*grumbles* Can't STAND the 4 space indenters...

I use the stanard tab indent of 8 spaces (Runs)


<?php 
php
function foo_bar_tar_yar$some_random_var )
{
  if( 
$some_random_var == 'Your Mother' )
  {
    echo 
"No, your mother!\n";
  }
}
foo_bar_tar_yar'Your Mother' );
?>

For me, the function name is allways proceeded by the opening parenthesis then a space, and any variables I want to pass, if more then one, then the comma is proceeded by a space and the next variable name is incerted, and so on. The squiggly brace always goes on its own line. I also tab.

The Off Topic Programming Thread!
(309 posts, started )
FGED GREDG RDFGDR GSFDG