Quantcast
Channel: Kingdom of Roi » Parkyeri

Code Smells

$
0
0

In recent days I have read an article about “Code Smells”. I was not aware of such a thing since then. I mean I was aware that people was writing bad code but I had not known there was a name for it. Anyway after reading the 3 part of the article at metapundit.net, I was really surprised to see people like me who actually think like me when writing code.

I know that development is about functionality, most often also about scalability and maintainability. Well most of the time you write a class constructor like:


public function Foo($a, $b, $c) {
$this->a = $a;
$this->b = $b;
$this->c = $c;
}

In most of the time you write down this kind of things. The part itself is repeating! Yuu just do the same thing, copy and paste. It’s perfectly understandable to do this. Because we are in the creation of it. How about something like this:


public function($a, $b, $c) {
$args = array("a", "b", "c");
foreach ($args as $arg)
$this->$arg = $$arg;
}

Is it cool? I know that it looks like lame. But isn’t the previous one looked lame too. I have not even reduced the lines of code. But think of adding another parameter to the function, then you have to copy paste another line doing the same thing but you just add another item in the array and lines are decreased. Instead of defining the arguments on the place where you define functions, you may use “func_get_args()” to get them and use the $args array to set them as you know which param is coming. Same thing can be done for most of the set and get functions


public function get($arg) {
return $this->$arg;
}
public function set($arg, $value) {
$this->$arg = $value;
}

Is it lame? Kind of, as you have lost lots of methods about getting and setting. I know that gets and sets are not used by this way. You may add some validations to it or some protections on it. Maybe you want to set to a new date and check if the day is 32 or not or if the month is 13 or something else. But that’s not the point. What I try to mean is, by this way you write less and create a more maintainable code I guess. It’s about functionality I suppose.

As metapundit mentioned, first thing we learn about programming is “loops”. The basic loops and, in most of the cases we pass down this first lesson and keep hard coding. How many of you created a form like:


<table>
<tr>
<td>Field 1</td>
<td><input type="text" name="field1"></td>
</tr>
<tr>
<td>Field 2</td>
<td><input type="text" name="field2"></td>
</tr>
<tr>
<td>Field 3</td>
<td><input type="text" name="field3"></td>
</tr>
</table>

Have you though of:


<table>
<?php
$fields = array("field1" => "Field 1", "field2" => "Field 2", "field3" => "Field 3");
foreach ($fields as $key => $val) {
echo '<tr><td><?=$val?></td><td><input type="text" name="<?=$key?>"></td></tr>';
}
?>
</table>

Isn’t this doing the same thing while giving you an understandable and maintainable code? I know that logic and design must be separated. So in this case our sample will change into something like:


<?php
$fields = array("field1" => "Field 1", "field2" => "Field 2", "field3" => "Field 3");
foreach ($fields as $key => $val) {
$template->setBlock("TEMPLATE1");
$template->setVariable(array("KEY"=>$key, "VAL" => $val));
$template->parseBlock();
}
?>
<table>
<!-- BEGIN TEMPLATE1 -->
<tr><td>{VAL}</td><td><input type="text" name="{KEY}"</td></tr>
<!-- END TEMPLATE1 -->
</table>

Syntax may change but the idea remains. You can also improve the way you define your form field elements in a way that template’s variable setting method accept it as it is.


<?php
$fields = array(array("key" => "field1", "val" => "Field 1"), array("key" => "field2", "val" => "Field 2"),array( "key" => "field3", "val" =>"Field 3");
for( $i = 0 ; $i < count($fields) ; $i++ ) {
$template->setBlock("TEMPLATE1");
$template->setVariable($fields[$i]);
$template->parseBlock();
}
?>
<table>
<!-- BEGIN TEMPLATE1 -->
<tr><td>{VAL}</td><td><input type="text" name="{KEY}"</td></tr>
<!-- END TEMPLATE1 -->
</table>

Remarked something? I repeat the way I define my variables. So:


<?php
$old_fields = array("field1" => "Field 1", "field2" => "Field 2", "field3" => "Field 3");
foreach ( $old_fields as $key => $val) {
$fields[] array("key" => $key, "val" => $val);
}
for( $i = 0 ; $i < count($fields) ; $i++ ) {
$template->setBlock("TEMPLATE1");
$template->setVariable($fields[$i]);
$template->parseBlock();
}
?>
<table>
<!-- BEGIN TEMPLATE1 -->
<tr><td>{VAL}</td><td><input type="text" name="{KEY}"</td></tr>
<!-- END TEMPLATE1 -->
</table>

You may not want to the last part, but I hope that I was able to explain what I meant.

Anyway I really try to write code like this. Whenever I copy paste a part of a code to somewhere else, I think of creating a function or a loop from it. But in most of the time as my time is limited, I note it down to do it in a later time which I don’t. Only in Boop I try to refactor the code I have written as I’m not pressed on releasing it in a mean time.

Anyway I have given some examples from metapundit and also created my owns too. I hope I was able to explain what I thought when I read about his article. I was really happy to find out someone who was thinking like me but still making that mistakes, just like me!


Parkyeri Planet

$
0
0

Someone, one of the interns, started a “Planet”, in the Company and that’s a post to try it out. Even I’m not a good blog writer, interns are started to change something just as the last year. I guess internship is a good thing for both the company and the company.

Development Diaries in Weburunu

$
0
0

Weburunu, also named as SanalDoku (meaning virtual texture/pattern in turkish) is a good framework for creating web sites and also a simple content management system.

It has its dead ends too of course. Even it’s a powerful tool, it’s not too easy to develop with it. You have to get some practice on it. While you practice writing code with it, you enjoy using it and fascinate with ideas in it, at least I had. Even it started to get a little older it’s still powerful and flexible.

During trainings about Weburunu I mentioned some things that can be added, since we need them but don’t have too much time to write their code or design them. These are some of my thoughts and they may take Weburunu one step ahead or it can be needles as there are some different projects going on.

Well in passing days I worked on the search part of WBU and added a template search in it. Now you are able to search in display templates and it will show you the results. It can be a useful tool or just nothing. Anyone who wants to try can try it from my home directory from any wbu website’s admin panel. Just search something and below the content results there will be template results.

One more thing that can be added is, the editing of these templates from the web browser. Without the need to open an html editor or emacs or vi, we should be able to edit these display types from admin panel. This will give us more freedom and perhaps more control over our product. Or it will just create a security hole.

Another thing is to add a form generator script to content types. Which will really take Weburunu one step ahead, and it will be really more user friendly and perhaps developer friendly. By this way we can really create content types that are different than others. How these values can be defined is a different discussion anyway, but if someone must intend to write them down, then we can discuss it anyway.

Not many people tries to change or improve the Weburunu’s core as many people try to use it as tools and not to get involved deep in it. But this will help you more to understand it and also will give more insight on how to write a framework :)

First Day in GUADEC

$
0
0

As some of you may know Gnome Users and Developers Congress (a.k.a. GUADEC) is taking place in Istanbul, Turkey at Bahcesehir University. And on it’s 4th day, it was my first day!

I had not have too much time to join discussions but, I’m sure I’m gonna attend tomorrow in the morning too. I had signed up over the internet and, GUADEC had some great stuff to give me as an attendee. A messenger back, a GUADEC 2008 t-shirt, a notepad (moleskin copy but red and written Google on it), a lots of commercial stuff about Turkey, Fedora 9 Live DVD, Ubuntu 8.04 CD and a 4G Mandriva bootable flash disk!

I had the chance to attend only two presentations, one was about Telepathy, a network framework that can be used to create multi user chat applications and other things. While at first I was intrested, the guy who was talking was not as good as a spokesman as a geek. I did not understand much of things he talked about but It was a good thing I guess.

The second one was about Moonlight, a Linux emulation of Silverlight. It was better than the previous one. The presentator was talking better but he had experienced some issues with his laptop. Anyway, It was intresting to see a Microsoft presentation in a Linux related congress. As Novell had some contracts with Microsoft, I guess this Silverlight emulation was about this as there is a group, full time worker in Novell who only does this job. I guess it’s also about that Adobe is not yet implemented Flash in Linux too. And this gap will be filled with Moonlight. It was funny to watch animations by the way. With it’s power to use C++ API and XAML markup language, it’s intresting. You have to use Mono for easily developing it. But any editors goes. But Mono is the easiest and most powerful I guess, at least that was what the man told.

It was great too see people in the conference room using their laptops during the presentation. You can argue that this is a disrespect to the man who is talking, but It was not the case in here. We are all geeks!! I really felt that I was not alone in the world and there is a lots of people around the globe that was like me!

While listening, some light bulbs had come on my mind that, joining these kind of congress open your way and mind up. When I had gone there, I was hoping there was somethings about Online Desktops but I had mistaken and I encountered something completely differently there and I entered to the discussion which I liked it’s name and it was enlightening and enjoying to do that.

Tomorrow I will go there just for that!

Using Custom PHP Codes on Magento

$
0
0

Magento is one of the newest and awarded ecommerce application right now. And I seem to have a project launched nowadays about it.

Above the ecommerce part like adding/modifying products, it also has a built-in CMS. It looks quite useful. Not very powerful though.  It just evaluates html code and not php. In most of the time this is prefered by the way. Because of security risks and things like that. But there are also cases which you want to do if you are importing something to magento or if you are just wanting to do in a quick and dirty way!

Well, the workarounds you find are not quite good. Simply they just take the CMS code, write it to a temporary file and include it, or writing a bit complicated parser inspired from joomla/mambo. Check out here for the details of the workaround. The tutorial I’m putting here is from there to, however I will also try to write solutions to problems that I have encountered (mostly because of magento versions).

This tutorial is working for magento version 1.1.8. You can download the latest version from here.

Now open up your favorite php/xml/html editor. While it will open up, also open your magento installation folder. Magento has a lots of folders for lots of things, which I do not know why. The code part is in app/ directory as you may guess. In the app folder you will find the etc/ where there are configurations for magento generally. Our PHP Code will be a module to the Magento, so we have to go modules directory and create a new xml file, named according to your module. The syntax is like: Parkyeri_customPHP. The first part till underscore means the name of the module, int this case Parkyeri. The second part indicates the component of the module. So you may have different components in one module, in this case customPHP, If we are talking about custom codded PHP pages, so in this module named Parkyeri, there can be different pages like: About, Contact, Jobs. And these are all different components, doing different things. If we were trying to create the About page then we had to use something like Parkyeri_About. You can add all of them in the same xml file.

Open up /app/etc/modules/ and create a file named Parkyeri.xml (the name of the module) and add these lines to file:




    
        true
        local
        
    

But what this means? You declare a new module named Parkyeri to the global site by naming the file Parkyeri.xml. Then you define in the module config file that, this module has a component named customPHP. You say that this component is active and the system can find it in the app/code/local directory by looking at the codepool

As you get it now we pass to the next stage. Now open up app/code/local/Parkyeri/customPHP/etc/ and create a file named config.xml (the default configuration file name for every module.) and add these lines in it.



    
        
            
                Parkyeri_customPHP_Block
           
       
    

What does it mean? This is more of a mapping file than a configuration file. What you are doing here is to map (you may also think bind) a class named Parkyeri_customPHP_Block to a block called parkyeri_customphp. So whenever a block of type parkyeri_customphp will be called, this block will look out for the class you defined in this configuration/mapping/binding file. But also you are defining the location of the component files that you want to call. In most of the cases, you want to call a component’s block from a module. So when calling you will say that I want a component named customPHP, and a block named test and this component is under the module Parkyeri. We move on…

Now the fun part, open up app/code/local/Parkyeri/customPHP/Block and create a file named Test.php and add these lines in it:


class Parkyeri_customPHP_Block_Test extends Mage_Core_Block_Abstract
{
    protected function _toHtml()
    {
        //put here your custom PHP code with output in $html;
        //use arguments like $this->getMyParam1() , $this->getAnotherParam()
        $html = "Hello" . $this->getWorld();
        return $html;
    }
}

So, we have finally reached the part which you are most comfortable, writing code! You will write down all the code you want to evaluate in this file. The _toHtml() method is called when you call it in the cms part. A magical function just like toString(). As you may remark the name of the class, is conventional according to the location of the class. That was how the previous configuration knew where to look when mapping.

And the final part is to embed it in the CMS, this is easy part. But the part where you get dissapointed most. Add this to page you want to show your custom php code:

{{block type="parkyeri_customphp/test" world="World"}}

So, it’s obvious isn’t it? In this code part, you say that, you want to put a block here. The type of this block is parkyeri_customphp/test. So actually you want a block named test under the customphp component which also a part of parkyeri module.  But you may be curious of the rest, on what I mean by saying, world. I’m sending a parameter to the class. Remember the code where there was $this->getWorld(). This world is that world!. So the code will print out “Hello World” (without an exclamation).
So this was it! Did it worked? No I didn’t did it? The real reason that it did not worked, is because, you did not refresh the caching system!! Yes, it’s that simple! It gave me a lots of headache though, hope it won’t to you. You can disable the caching from System -> Cache Management by the way.  Better then refreshing every time :)
If you are stuck on somewhere you should really check out magento forums. There are really helpful people out there from real developers, ceos and community experts.

Update: I have tested this code sample with 1.1.8 and all works fine.

How to Customize Magento Product Page

$
0
0

I’m back with another tutorial about Magento. I’m not the best man you can find about Magento. But I’m trying to learn something from forums. The best you learn something is when you can explain it to someone else. So this is for that!

As I had mentioned in my previous post Magento is an open source ecommerce application made with PHP and Zend Framework. Company behind it is very dedicated to this project and works a lot about it. But the missing part is the tutorials I guess. There isn’t enough entry in their wiki and if you want to learn something, you have find it out yourself. So let’s begin!

This tutorial will cover basics about how you can find your way in the magento code and get to the right place and how you can change a product’s page design by changing the place of the images from left to right.

I tried this on Magento version 1.1.3 and it worked. Check here for the latest version.

First of all we have to understand which part of the code does show the product’s detail page. You can guess of course. But don’t do it and open the Magento folder. Navigate to /app/code/core/Mage/. Then you will see.

No I mean it, really! Go and look on that folder! So your best bet will be the Catalog folder. So is mine. So I enter the folder and look for things which can suit me. Well As I’m a bit familiar with Magento and I know that they have mostly separated the logic and design. So there must be somewhere where this binding must have been done. So the people who has read the previous post and people who are familiar with Unix systems, they must have noticed the etc/. Yes this is the folder you are looking for. In it, there is the configuration file: config.xml. Not that hard to find I guess. Now the real problem is to find out, what is related with what?

config.xml is a huge file and if you don’t know what you are looking for you are in a bit of troube but don’t be afraid. Let’s cover the details a bit and make an understanding. In my previous post I had entered some information about modules’ configuration files. But it was a small file and let’s say I knew what I had to write. So let’s look under the hood. For people who does not want to see how the engine works, the file you are looking for is /app/design/frontend/default/default/layout/catalog.xml. (Maybe instead of looking to code I should have checked folders better :)

There is a version info, ok. There is an admin part, which does not mean a lot to you nor to me. Maybe it’s something fatal but it doesn’t mean a lot for us (Nothing more than a newbie I’m). So the next part I’m more comfortable, as I understand what it belongs to. Well first of all, we know that this part is global. It will be used for all the parts where this module is being used. And the next part is models. This is about database fields. You can see that, below the models, there is the definition of a resourceModel to a class. This means the class defined in this config, will use that resourceModel. But what is this model? Next part is this. You see that the name of the resourceModel (catalog_resource_eav_mysql4 for me) starts now and a lot things is defined. Classes (let’s say the database’s driver folder) and database tables related to this resourceModel are listed here. It basically says that, this attribute comes from this table. You can be shocked by the count but open your phpmyadmin and you will see that there are 192 tables in it. Ouch! The only important part is that (if you don’t want to change the core aspects of course), if you are stuck which table is what, you can always look to these configuration files and find out which table is related to which module. A bit confusing but better than nothing.

Forget about the database and let’s keep going on the config file. Passing to models we come to the resources part. I guess this is about what connections will be used for querying and other things. You see that in catalog_read, there is a connection value and this is core_read. You may guess that it defines which connection this database drivers will use, comes from here. You are right, probably. But I’m not sure, and it doesn’t look I need this part to change the place of the picture, so I move on.

And now comes the block part. This isn’t new and I’m happy to see something that I know from my previous experience. In CMS pages, this part of the configuration had helped me to get to the layout so this might be the part where the output is given. So I get to the /app/code/core/Mage/Catalog/Block/ there are some parts about products but this is the backend part as I see. There isn’t any meaningful htmls in files which are in that folder. So I had a hope that I had found it, but it seems that this is not the case yet. So I move on.

Now a part that I do not even have slightest idea comes and I pass. The next part is adminhtml. I mean HTML! This can be it! There are some definitions about some things but I do not get it. There is a folder /app/design/adminhtml/default/default/ in the file system. And these bindings refer to the template folder. I assume there are some language additions and some other tweaks about admin pages. But again, I’m not sure.

Finally I have reached the frontend part. I’m now sure that this is the part I’m looking, as there are language definitions, per_page_values and layout! There are some things which still I do not get what are they for, but I see the catalog.xml. And this my best bet! I open the file and I see: Default layout, loads most of the pages! Yes I found it!

Below that part, there are things which are not much useful to me, things like url rewrites and some more configuration values. You can alter the general layout of Magento by changing these options by the way (As this module is about catalogs, the general view of catalogs of course, not the payment part!).

catalog.xml is a file familiar to me. From my previous post I knew there was something about blocks defining somewhere and this is it! There are blocks here and I follow the comments and finds Product View.

<block type=”catalog/product_view” name=”product.info” template=”catalog/product/view.phtml”>

This was the part I was looking for all the time. You see the template part?. It refers to /app/design/frontend/default/default/template/catalog/product/view.phtml. So I go there open the file and yes htmls!!! product-img-box line is very meaningful what I’m looking for and it has a css class. I make a file search between files and I find /skin/frontend/default/default/css/boxes.css. The product-img-box is defined in it and I change the float:left; to float:right;.

I open my web browser, open a product page and see that images are at right and not at left. You may have been more lucky if you just looked with firebug and saw the css and changed to it. But you wouldn’t had gained the insight you would have gained with this.

I hope that this was helpful. I’m not an expert on Magento. This article on Magento wiki helped me to figure out something. My previous post’s references were also valid. Do not forget to keep watching Magento Wiki and Magento Forums for best resources about Magento.

Writing You Own PHPUnit Listener

$
0
0

Well, in the company, Parkyeri, we have restarted to a crusade to cover all the code lines we had by writing unit tests.

As a PHP Developer, I’m taking the part where I have to write PHPUnit, the xUnit family which is developed for the PHP language. I had used it in the first version for a while, but I had seen that it had reached to the 3rd version. As I’m someone who likes to use the latest things and demos, I tried the latest version and migrated all the first version unit tests to the latest version, which was surprisingly, very easy. You just have to change some class inheritance, delete some constructors, and you are nearly done.


The next part is to run the tests you have written, the best way, of course, is to use the CLI for PHPUnit. But as the Debian repositories does not include phpunit3, I can’t use CLI and I have to use something else.

So this is where we start to have trouble. I was thinking to show them on the browser but problems insisted. I will mention on them later. Let’s first create a testcase and then create a file to run my testcase. My testcase file is named ParkyeriTest.php:

require_once("PHPUnit/Framework/TestCase.php");

class ParkyeriTest extends PHPUnit_Framework_TestCase {

        function testMe() {
                $params = 1;
                $this->assertEquals(1, $params);
        }

        function testMeToo() {
                $params = 1;
                $this->assertEquals(2,$params);
        }
}

This will be our testcase. There is one test which fails and there is one which does not. The file will be called AllTests.php:

//Add the testcase you have created
require_once('ParkyeriTest.php');
//Don't miss to add TestSuite as we will instanciate it..
require_once('PHPUnit/Framework/TestSuite.php');
//And of course your own listener
require_once('myListener.php');
$suite = new PHPUnit_Framework_TestSuite(); //Create the instances
$mLis = new myListener();
$result = new PHPUnit_Framework_TestResult(); 
$suite->addTestSuite("ParkyeriTest"); //Add your test case to the test suite
$result->addListener($mLis); //Define your listener which the test result will use to give output
$suite->run($result); //And of course run this tests
//That's all buddies....

So you see that I have included my test case file and some PHPUnit files. I have created a TestSuite which will hold my TestCase and which will run it.

You see I have created a class named myListener. This class implements PHPUnit_Framework_TestListener and extends PHPUnit_Util_Printer. It implements TestListener because as a listener he has some jobs to do and this interface defines them, which are most basically things like addError(), addFailure() or startTest(). You will see them in the code block below. Let’s continue what we have done once we have instanciated our listener. We create another object PHPUnit_Framework_TestResult which holds the results of the test results. Also it allows you to listen the current process of the tests. I won’t mention the details of the TestResult, you can find them in PHPUnit Documentation.

And the rest is to add a listener to your results and then run the test suite. While the test suite ruins, you will se the output of your listener, as the execution progress. Now our listener’s file name is myListener.php:

require_once 'PHPUnit/Framework.php';
require_once 'PHPUnit/Util/Filter.php';
require_once 'PHPUnit/Util/Printer.php';
require_once 'PHPUnit/Util/Test.php';

//This part may confuse you. The only thing is, PHPUnit also contains a covered code part
//This line tells the PHPUnit to exclude it from code coverage things.
//At least that's what I understood :)
PHPUnit_Util_Filter::addFileToFilter(__FILE__, "PHPUNIT");

class myListener extends PHPUnit_Util_Printer implements PHPUnit_Framework_TestListener {
    protected $currentTestSuiteName = "";
    protected $currentTestName = "";
    protected $currentTestPass = TRUE;
    /**
     * Triggered when an error occurs on the test case
     */
    public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) {
        $this->writeCase(
          'error',
          $time,
          $e->getMessage()
        );

        $this->currentTestPass = FALSE;
    }
    /**
     * Triggered when one of the unit tests fails.
     */
    public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) {
        $this->writeCase(
          'fail',
          $time,
          $e->getMessage()
        );
        $this->currentTestPass = FALSE;
    }
    /**
     * Triggered when an incomplete test is encountered. 
     * You have to define the unit test as incomplete to trigger this.
     */
    public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) {
        $this->writeCase('error', $time, array(), 'Incomplete Test');
        $this->currentTestPass = FALSE;
    }
    /**
     * Triggered when an incomplete test is encountered. 
     * You have to define the unit test as to be skipped to trigger this.
     */
    public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) {
        $this->writeCase('error', $time, array(), 'Skipped Test');
        $this->currentTestPass = FALSE;
    }
    /**
     * Triggered when a testsuite is started
     */
    public function startTestSuite(PHPUnit_Framework_TestSuite $suite) {
        $this->currentTestSuiteName = $suite->getName();
        $this->currentTestName      = '';
        $this->write("Started Suite: " . $this->currentTestSuiteName . " (" . count($suite) . " tests)n");
    }
    /**
     * Triggered when a test suite ends.
     */
    public function endTestSuite(PHPUnit_Framework_TestSuite $suite) {
        $this->currentTestSuiteName = '';
        $this->currentTestName      = '';
    }
    /**
     * Triggered when a testcase starts
     */
    public function startTest(PHPUnit_Framework_Test $test) {
        $this->currentTestName = PHPUnit_Util_Test::describe($test);
        $this->currentTestPass = TRUE;
    }
    /**
     * Triggered when a testcase ends
     */
    public function endTest(PHPUnit_Framework_Test $test, $time) {
        if ($this->currentTestPass) {
            $this->writeCase('pass', $time);
        }
    }
    /**
     * I used this function to give output and not writing everything again and again.
     */
    protected function writeCase($status, $time, $message = '') { 
        $m = "Test: " . $this->currentTestName . " - Status: " . $status . " - Time: " . $time . ($message ? " - Message: " . $message: "") . "n";
        $this->write($m);
    }
}

I would have loved to add some PHPDoc, but I did not have much time.

What we have here is; we basically implement, I mean, create some functions that must be created in order to be used as a listener. Once you define this functions, you will decide what you will do with the current result. Basically, let’s take addFailure() as an example. This function is called whenever a test fails. Then you write what you want to do on that function and it’s done. You see that I have used another function writeCase(), which basically prints something on the screen by using, PHPUnit_Util_Printer‘s write() method. That’s why we have extended that class, because we had to give an output.

You may find additional listeners in the PHPUnit’s core of course. Something which will give you an xml output or a json output in root/PHPUnit/Util/Log folder.

Don’t forget to check out PHPUnit’s Manual and here for how to use PHPUnit_Util_Log_XML.

I have used PHPUnit_Util_Log_JSON as a base to my listener class by the way. You may want to check that one too. It had also implemented a complicated stack trace, but I didn’t need it a lot, as I show which test on which test suite I’m currently running and it’s not that hard to find the problem :)

PHP Debugging on PHP IDEs

$
0
0

As NetBeans has started to be a great IDE with powerful debugging features, like most people who are migrating to NetBeans, I would like to use it’s built-in debugger abilities. PHP debugging is not new. XDebug is quite around for some time but it always lacked the attention it has now. From now on PHP Developers are starting to use IDEs instead of colorful text editors. Because from now on, PHP started to be accepted as an Enterprise language. It’s pretty easy to code with PHP, it’s very simple but yet it can be a good base for complex applications. With the newest release of PHP 5, it also contains OOP features and with powerful frameworks built around (CakePHP, CodeIgniter, Symphony, Zend,…) some strict rules apply on designing your application for a cleaner, better code and yet you can still use the quick and dirty ways. :)

Now everybody is trying to debug their PHP scripts with IDEs (Zend Studio For Eclipse, PDT, NetBeans, KomodoIDE, PHPed, Aptana PHP, …) and IDEs try to create a great environment for developers. I really think there is huge IDE war out there, and all of the IDEs have powerful and different features. It’s really interesting to see one feature existing in one IDE, yet not in another. So the choice of the best IDE is not anymore a personal opinion but the one with most features or the best price/performance ratio.

As of now my favorite IDE is NetBeans 6.7 M2 and that’s for sure. I have so far tested Zend Studio For Eclipse, PDT, Aptana PHP, KomodoIDE and all of them has their own advantages. They all have the pros and cons and from time to time my favorite IDE changes with the new releases. I’m sure I may migrate from NetBeans to PDT when the new release comes (if it ever does:).

So long story short, let me come to the point. Every one (except Zend Studio which it has his own debugger but can still work with XDebug) is using XDebug for the debugger library of PHP and here is the problem with it: Two people cannot debug one server! In our company no one develops locally. We have our development servers maintained by system administrators. This prevents the developers from installing whatever they want on the server and having problems on what to install on the production server. So me and 4 or more of my colleagues are using only one development server and all of us wants to debug his own PHP scripts. The bottleneck? All of us have to enter the php.ini file to his own IP address and then restart the Apache! Problem: I don’t have sudo :)

Most of the IDEs I have tried so far, does not look to this problem. Especially NetBeans which thinks that development can only be done on a local machine and in order to edit a file you must create a NetBeans project! There are some ways to overcome this as I have mentioned in my previous post. Remote Development is better on Eclipse based IDEs. But the same file explorer problem applies to Komodo IDE. Why the hell should I need to create a project to just edit one file (I hope that this is my own inexperience with Komodo)!

But truth be told, even the debugging interface is bad on Komodo (even the generaly ui is bad:), debugging features is far more powerful than NetBeans and it solves the problem in our company too! The idea is to setup a proxy server to listen both the host and client debuggers via dbgp. From 3rd party tools you can setup such a proxy written in Python. But you can’t connect to this proxy with NetBeans as there is no such feature. NetBeans assumes that I’m listened by XDebug client, I’m the Host (King) after all. So if your audience cannot hear you, what if you are a King anyway :) You can setup Komodo to be used with such a Proxy and it works pretty well.

Yet everything comes with it’s own price. Komodo is not free (KomodoIDE is not but Komodo Edit is free yet it lacks the debugging features). I have opened an issue about this on NetBeans, I hope that it gets accepted (but nothing happened yet) and the reality about “PHP Developers usually develop on remote servers” gets noticed. I’m just looking for new things to use instead of Vi, the love of my life, the second best editor built for Developers on Linux :)


Looking for Web Developer Enthusiasts for Kartaca

$
0
0

It’s been almost a month since my last post and this time I’m back with a recruitment option to you! I will strict this post to Turkish, as opposed to my previous posts because we are mostly interested in developers who live in Turkey. If you are interested keep reading!

Uzun uzun yazıların hayranı değilim ve iş ilanı ararken bir sürü ıbıdık zıbıdık ütopik ilanlar okuduğunuzu biliyorum. Fantastik ‘title’lar ile gözünüzü boyamaya çalışan, aslında kötü bir şeyi size mükemmelmiş gibi satmaya çalışan bir İK uzmanı işe alım yazısı olmayacak bu. Tam olarak ne aradığımızı, adaydan neler beklediğimizi, size neler sunacağımızı, kim olduğumuzu anlatacağım. Hepsini de başlıklara böldüm, atlayarak ta okuyabilirsiniz. Şimdi gelelim detaylara:

Kimiz
Kartaca diye bir firmayız. Turkcell, Erdem Holding, Genpa, Demirdöküm gibi büyük ve köklü firmalar ile çalışıyoruz. Yabancıların dilinde bir software house yani yazılım eviyiz. Esas işimiz başka, yardımcı olması açısından yazılım yapan bir firma değiliz. Yazılım yapıp, bunu satıyoruz. Parkyeri çatısı altında kurulmuş başka bir şirketiz.

Neler sunuyoruz
Yıldız Teknik Üniversitesi Davutpaşa Kampüsü gibi, aslında dağ başı olan, yeşillikler içerisinde, bir duvarı boydan boya kütüphane olan bir ofisimiz var. Sizin için ne kadar önemli bilmiyorum ama, yüksek tavanlı ve ferah bir ofis, içerisinde ücretsiz faydalanabileceğiniz bir bisküvi ve gazoz dolabı var. Günümün önemli bir kısmını burada geçirdiğim için yukarıdaki kriterler benim için önemli, sizin için bilmem.

Çalışanlarımıza yukarıda anlattığım ortam ve maaş dışında, yemek kartı ve yol masrafı veriyoruz. Kütüphaneye yeni kitap alıp okuma ve her ay artan eğitim bütçeniz ise cabası. Uyumayı seven insanlarsanız benim gibi, sabah saat 10′a kadar işe başlama hakkınız var. Toplamda da günce 8 saat ofiste olacaksınız, öğlen aranız 10 dakika olmuş, 3 saat olmuş, size kalmış bir şey.

Ne Bekliyoruz
Sizden ne beklediğimize gelince, gayet dürüst olacağım. Sizi kahraman yapıcaz, inanılmaz mutlu olacağınız bir ortam sunacağız, önünüz çok parlak falan filan bunların hiç birine girmeyeceğim, benim işim değil. Takımlar halinde çalışan, dinamik ve iletişim içinde olan bir ekibimiz var. Senden beklentimiz bu dinamiğe dahil olman, zıpçıktılık yapman değil. Eğer bu dinamiği bozuyorsan, seninle çalışmak istemiyoruz, ne kadar iş çıkarıyor olduğun da bizi ilgilendirmiyor, çünkü ortada yarattığın dert, getirini karşılamıyor. Cümle de kurabilmen ve derdini, düşünceni karşındakine anlatabiliyor olman da bizim için çok önemli.

Bunun yanında iş çıkartmanı tabii ki bekliyoruz. Ama iş çıkarmak derken, ben evimden çalışır, işimi zamanında teslim ettiğim sürece bana kim karışır mantalitesiyle de uğraşmak istemiyoruz. Dediğim gibi, takım halinde çalışıyoruz, sen de ya bunun bir parçası olursan ya da bizimle olmazsın.

Ona söylenen her şeyi birebir yapacak, kafasını çalıştırmayacak, sadece ona verilen sorumluluğu yapıp, gerisine karışmayacak birini gene istemiyoruz. Firma içinde yeni çalışan adaylara söylediğimiz bir şey vardır. Kartacada (Parkyerinde) eğitim verilmez, alınır. Yani biri bana bu eğitimi verecek, falan yok. Sen peşinden koşacaksın, onu alacaksın. Şirket içinde alacağın bütün sorumluluklar da böyle olacak, kimse sana sorumluluk vermeyecek, sen isteyeceksin, sırtlanacaksın.

Çok lanet bir ortam olduğundan, böyle iş mi olur diye düşünenleriniz çıkabilir, böyle! İş yapmak, kendini geliştirmek, öğrenmek, öğretmek isteyen insanlar ile çalışmak istiyoruz, bunun için de ince eleyip sık dokuyoruz.

Bu kadar şey yazdım, hala teknik olarak ne bekliyor olduğumuzu yazmadım. Teknik yeterlilik kazanılan bir şey, ama insanların kişiliklerini o kadar kolay değiştiremiyoruz. Ha her ikisi de olursa ne ala.

Teknik mevzu ile ilgili dipnotumu da düştükten sonra ne bilirsen iyi olur:

  • PHP/Java/Perl
  • Object Oriented Programming
  • MySQL/PostgreSQL/Oracle
  • HTML/CSS
  • Javascript
  • Unit Testing
  • SVN/Git
  • Linux

Yukarıda sıralanmış her satırdaki maddeler için bilginiz olduğunu varsayıyoruz. Framework lere falan girmiyorum, onları ayrıca değerlendiririz. Ama en basiti bunlar. Hiç fikriniz yok ise fikrim yok diyebilirsiniz, öğretmeye açığız.

Teknik olmayan ama diğer beklentilerimize gelince:

  • Kafası Çalışan (Olabilecek en kaba tabir ile)
  • Cümle kurup, derdini anlatabilen
  • Öğrenmeye, öğretmeye, kendini geliştirmeye istekli
  • Ona söylenen şeyleri sorgulayan, beğenmediklerine sadace muhalefet yapmayan, kötü şeyleri düzeltmek için çözüm önerisinde bulunan
  • Sonuç odaklı ama yolda yürürken bacağını da sakatlamayacak
  • Şirket etkinliklerine katılıp, bizimle gülüp eğlenecek
  • Gerektiğinde, gece olduğunda bizimle beraber oturup kodunu yazacak

şeklinde sıralanabilir. Görüşmeye geldiğiniz zaman yukarıdaki şeylere göre değerlenedirileceksiniz ve gerçekten değerlendirileceksiniz. Her bir görüşme en az 1 saat sürüyor ve farklı aşamalardan geçiyor. Yani biraz hazırlıklı gelmeniz sizin için iyi olacaktır.

Ekstra
Çalıştığım yer ile ilgili kutsal bilgi kaynağına başvurunuz. Bir çoğu (özellikle görüşmeler ile ilgili söylenen şeyler Fibonacci hariç) doğru diyebiliriz.

Sonuç
Buraya kadar okudaysanız, zaten ilginizi çekmişimdir. Bize uygun olduğunuzu düşünüyorsanız, aşağıdaki soruya cevabınız ve CVniz ile birlikte insankaynaklari@kartaca.com adresine bir eposta gondermeniz yeterli. Bizim IK tayfası sizinle iletişime geçecektir.

Soruma gelecek olursak. Bana çok uzun olmayacak şekilde, Procedural Programmingin, Object Oriented Programmingden neden daha üstün (yanlış okumadınız) olduğunu anlatmalısınız.

Beklediğimden uzun oldu ama idare edersiniz artık.





Latest Images