We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    Quote from: sottwell at Jul 30, 2008, 06:06 AM

    I think the one thing that discouraged me the most was trying to pinpoint exactly where a certain variable got defined. I went through two or three classes, some that were extensions of others, and finally got bogged down in Smarty and gave it up. Once I can actually trace the process of how an end product actually gets produced I’ll be better able to cope with it. That’s the thing I like about Evolution, it’s very easy to trace processes and variables.

    This is a great point on the internal documentation. There’s nothing more helpful than a quick end-of-line comment when an alien variable first appears.

    $someVar = $mysteryVariable // $mysteryVariable defined in core/models/modx ....(full path here).

    It’s not only helpful for new users, it’s great when an original programmer goes back to work on the code a year or two from when it was written.
      Did I help you? Buy me a beer
      Get my Book: MODX:The Official Guide
      MODX info for everyone: http://bobsguides.com/modx.html
      My MODX Extras
      Bob's Guides is now hosted at A2 MODX Hosting
      • 22303 MODX Staff
      • 10,725 Posts
      Quote from: BobRay at Jul 30, 2008, 05:36 PM

      Quote from: sottwell at Jul 30, 2008, 06:06 AM

      I think the one thing that discouraged me the most was trying to pinpoint exactly where a certain variable got defined. I went through two or three classes, some that were extensions of others, and finally got bogged down in Smarty and gave it up. Once I can actually trace the process of how an end product actually gets produced I’ll be better able to cope with it. That’s the thing I like about Evolution, it’s very easy to trace processes and variables.

      This is a great point on the internal documentation. There’s nothing more helpful than a quick end-of-line comment when an alien variable first appears.

      $someVar = $mysteryVariable  // $mysteryVariable defined in core/models/modx ....(full path here).

      It’s not only helpful for new users, it’s great when an original programmer goes back to work on the code a year or two from when it was written.
      In what code are we talking about mystery variables being defined?  Can you give me an example?

      And am I the only one that uses my IDE’s global search function to see where some variable is defined or mentioned?  This what I typically do when trying to understand any code that is new to me. Of course, I also have the benefit of using an IDE that inspects/parses the code, including the class structures so I just right click on a function or variable, and get a list of potential matches for the source.  This is essential for OO programming IMHO, but the alternative is to learn the class hierarchy and memorize it, starting with the modX class, which extends (and thus inherits everything from) the xPDO class.  All of this is documented in the API documentation; you can even see the inherited methods and variables in each class, but I still would never attempt do any serious OO programming without a proper IDE to do it in.

      As for end-of-line comments: I personally just do not like inline comments in code at all, unless a piece of code is particularly terse or unclear for a reason that cannot be fixed by writing it more clearly.  I think it’s simply ugly and promotes code that is written poorly, but again, that’s just my perspective.  But even when a comment is appropriate, I would always put it on a separate line for clarity and ease of formatting.  I prefer all comments to remain in the PHPDoc sections.
        • 3749
        • 24,544 Posts
        Susan will have to speak to the mystery variable problem, I’m taking her word for it. wink I do have and editor with an excellent code explorer, although I always appreciate a coder saving me the time with a comment.

        You and I obviously have really different ideas about what constitutes "ugly" code. I can often figure out what code is doing by looking at the raw code, but not very easily when the code is calling member functions of objects it has instantiated that in turn call functions of objects *it* instantiates. Why not just tell me and save me the time. Even when the code is self-contained, why take the chance that I misinterpret what it’s doing or why? If I had a nickel for every time I’ve misinterpreted my *own* code when looking at it after a long delay, I could have retired long ago.

        Put the code in the documentation section at the top? Why make me bounce back and forth or open a separate window? I use end-of-line comments often because I can hit the end key and two slashes much faster than I can do anything else and the easier the job of commenting, the more comments there are. In my book, there’s no such thing as over-commented code. I’m sure you disagree. wink

        Here’s some code (a little of it is mine but mostly from others) that I find attractive and you probably consider ugly:

        /*
         Class for producing CAPTCHA-style images.
        
         This class generates an image with random or selected text
         to be used in form verification. It has visual
         elements design to confuse OCR software preventing
         the use of BOTS.
        
         Original Author: Huda M Elmatsani
         Modifications: Extensively modified by Bob Ray and many others
        
         Original date: 25/07/2004
        
         Copyright (c) 2004 Huda M Elmatsani All rights reserved.
         This program is free for any purpose use.
        
        
         USAGE
         create some image with noise texture, put in image directory,
         rename to noise_, see examples
         put some true type font into font directory,
         rename to font_, see exmplae
         you can search and put free font you like
                                                                  */
        class VeriWord {
        
        	/* path to font directory*/
        	var $dir_font 	= "fonts/";
        	/* path to background image directory*/
        	var $dir_noise 	= "noises/";
        	var $word 		= "";
        	var $im_width 	= 0;
        	var $im_height 	= 0;
        
        	function VeriWord($w=200, $h=80) {
        		
        		//$this->set_veriword();	// called directly by user
        		$this->im_width 		= $w;
        		$this->im_height 		= $h;
        	}
        
        /*	Set_veriword has three options. With no argument, it picks calls pick_word(),which
        	selects a random word and appends a random number to it. With the argument "MathString"
         */
        	function set_veriword($useWord="") {
        
        
        		/* create session variable for verification,
        		   you may change the session variable name */
        
        		   if ($useWord == "") { // no word sent, use random word
        		   		$this->word  = $this->pick_word();
        				$_SESSION['veriword'] = $this->word;
        
        		   } elseif ($useWord == "MathString") {  // use math string for veriword
        
        		   	require "mathstringclass.inc.php";
        		   	$ms = new MathString();
        		                $this->word = $ms->getDisplayString();
        		   	$_SESSION['veriword'] 	= $ms->getValue();
        
        		   } else {    // word sent as argument - use it.
        
        		   	$this->word = $useWord;
        		   	$_SESSION['veriword'] = $this->word;
        		   }
        
        	}
        
        	function output_image() {
        		/* output the image as jpeg */
        		$this->draw_image();
        		header("Content-type: image/jpeg");
        		imagejpeg($this->im);
        	}
        
        	function pick_word() {   // private - do not call directly. set_veriword() with no arg calls it automaticaly
        
        		// set default words
        		   $words="Ack,Arps,Alag,Atex,Bek,Bix,Chux,Caxt,Depp,Dex,Ext,Enya,Fet,Fets,Tek,Text,Gurk,Gex,Het,Heft,Inet,Ibex,Jax,Jerp,Jink,Lak,Lest,Liv,Mars,Mamp,Nex,Nelp,Paxt,Pex,Reks,Rix,Snix,Sept,Turp,Thix,Elps,Vix,Veks,Wect,Wex,Yap,Yef,Yeff,Zub,Zeks";
        
        
        		$arr_words = explode(",", $words);
        
        		/* pick one randomly for text verification */
        		$vWord = (string) $arr_words[array_rand($arr_words)];
        		$vNum =  (string) rand(10,999);
                                        while(strpos($vNum, "0")) {         // Change all zeros to threes
                                                  $vNum = str_replace("0", "3", $vNum);
                                        }
        
        
        		return $vWord.$vNum;
        	}
        
        	function draw_text() {
        
        		// dynamically load GD2 lib
        		if (!extension_loaded('gd')) {
        		       if (strtoupper(substr(PHP_OS, 0,3) == 'WIN')) {
        			@dl('php_gd2.dll');
        		       } else {
        			@dl('gd2.so');
        		       }
        		}
        
        		/* pick one font type randomly from font directory */
        		//$text_font 	= $this->dir_font."".rand(1,3).".ttf";
        		// added by Alex - read ttf dir
        		$dir = dir("./ttf");
        
        		$fontstmp = array();
        		while (false !== ($file = $dir->read())) {
        			if($file!="." && $file!=".." && file_exists('./ttf/'.$file) && !is_dir('./ttf/'.$file)) {
        				$fontstmp[] = './ttf/'.$file;
        			}
        		}
        		$dir->close();
        		$text_font = (string) $fontstmp[array_rand($fontstmp)];
        
        		/* angle for text inclination */
        		$text_angle = rand(-9,9);
        		/* initial text size */
        		$text_size	= 30;
        		/* calculate text width and height */
        		$box 		= imagettfbbox ( $text_size, $text_angle, $text_font, $this->word);
        		$text_width	= $box[2]-$box[0]; //text width
        		$text_height= $box[5]-$box[3]; //text height
        
        		/* adjust text size */
        		$text_size  = round((18 * $this->im_width)/$text_width);
        
        		/* recalculate text width and height */
        		$box 		= imagettfbbox ( $text_size, $text_angle, $text_font, $this->word);
        		$text_width	= $box[2]-$box[0]; //text width
        		$text_height= $box[5]-$box[3]; //text height
        
        		/* calculate center position of text */
        		$text_x     	= ($this->im_width - $text_width)/2;
        		$text_y 		= ($this->im_height - $text_height)/2;
        
        		/* create canvas for text drawing */
        		$im_text 		= imagecreate ($this->im_width, $this->im_height);
           		$bg_color 		= imagecolorallocate ($im_text, 255, 255, 255);
        
        		/* pick color for text */
        		$text_color 	= imagecolorallocate ($im_text, 0, 51, 153);
        
        		/* draw text into canvas */
        		imagettftext(            $im_text,
        				$text_size,
        				$text_angle,
        				$text_x,
        				$text_y,
        				$text_color,
        				$text_font,
        				$this->word);
        
        		/* remove background color */
        		imagecolortransparent($im_text, $bg_color);
        		return $im_text;
        		imagedestroy($im_text);
        	}
        
        
        	function draw_image() {
        
        		/* pick one background image randomly from image directory */
        		$img_file 	= $this->dir_noise."noise".rand(1,4).".jpg";
        
        		/* create "noise" background image from your image stock*/
        		$noise_img = @imagecreatefromjpeg ($img_file);
         		$noise_width = imagesx($noise_img);
        		$noise_height = imagesy($noise_img);
        
        		/* resize the background image to fit the size of image output */
        		$this->im = imagecreatetruecolor($this->im_width,$this->im_height);
        		imagecopyresampled ($this->im,
        				$noise_img,
        				0, 0, 0, 0,
        				$this->im_width,
        				$this->im_height,
        				$noise_width,
        				$noise_height);
        
        		/* put text image into background image */
        		imagecopymerge ( 	$this->im,
        				$this->draw_text(),
        				0, 0, 0, 0,
        				$this->im_width,
        				$this->im_height,
        				70 );
        
        		return $this->im;
        	}
        
        	function destroy_image() {
        
        		imagedestroy($this->im);
        
        	}
        
        }
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
          • 10487 MODX Staff
          • 1,535 Posts
          And am I the only one that uses my IDE’s global search function to see where some variable is defined or mentioned?
          No, not at all. I think that is needed with any kind of OO programming. Having a decent IDE that offers global search and some kind of code completion is a must. I cast my mind back to the two years .net development I did and I have to say that MS did a great job with Visual Studio ... Intellisense was a must.

          And, I think that’s important - in OO programming, things are naturally more abstracted. Having an IDE that works for you rather than having to trawl numerous class files is essential. Otherwise, like Jason says, look at the API documentation. I used a combination of both when first picking up what was then 0.9.7 - yeah, it took a few weeks to grasp all what was going on but I now know what does what and what comes from where.

          @BobRay: I don’t disagree with the occasional comment, especially where it distinguishes two or more, otherwise confusing, code blocks. But, using your example:
          $text_width	= $box[2]-$box[0]; //text width
          $text_height= $box[5]-$box[3]; //text height

          Are those comments really necessary? Don’t the variable names describe enough in that instance tongue
            Garry Nutting
            Senior Developer
            MODX, LLC

            Email: [email protected]
            Twitter: @garryn
            Web: modx.com
            • 3749
            • 24,544 Posts
            Quote from: garryn at Jul 30, 2008, 07:41 PM

            @BobRay: I don’t disagree with the occasional comment, especially where it distinguishes two or more, otherwise confusing, code blocks. But, using your example:
            $text_width	= $box[2]-$box[0]; //text width
            $text_height= $box[5]-$box[3]; //text height

            Are those comments really necessary? Don’t the variable names describe enough in that instance tongue

            I can’t argue that one. grin I didn’t put those there (and wouldn’t have).
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              This is great! And is exactly why I like to poke until something snaps, and a discussion like this gets started. I learn a lot, get a lot of good ideas, and it gets me thinking in the right paths to begin to understand, not necessarily what I’m trying to understand, but how to go about better understanding it. And for years I’ve been putting off going beyond a simple text editor with line numbers and syntax coloring, but now I understand that things have moved beyond that, and I need to take the time to find a good one and learn to use it properly.

                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 3749
                • 24,544 Posts
                Quote from: sottwell at Jul 30, 2008, 11:43 PM

                This is great! And is exactly why I like to poke until something snaps, and a discussion like this gets started. I learn a lot, get a lot of good ideas, and it gets me thinking in the right paths to begin to understand, not necessarily what I’m trying to understand, but how to go about better understanding it. And for years I’ve been putting off going beyond a simple text editor with line numbers and syntax coloring, but now I understand that things have moved beyond that, and I need to take the time to find a good one and learn to use it properly.

                A lot of people swear by PhpEclipse and I’m pretty sure that’s what Jason uses. Personally, I didn’t like the user interface and the fact that I had to install and update several different components.

                I love NuSphere’s PhpEd http://www.nusphere.com/. It has little flyout panels on the left and right for code exploration and db viewing and editing. It also has a greate built-in debugger, integrates well with TortoiseSVN, and is Smarty-aware. Sadly, I don’t think it’s available for the Mac. Too bad because it has all the old Wordstar commands built-in (even the Ctrl-Q, Ctrl-K bookmarks) which I suspect an old-schooler like you would appreciate. wink
                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  I’ve started with Eclipse a couple of times; I guess it’s about time to go at it again. I’m too cheap to pay what Zend wants for their IDE.
                    Studying MODX in the desert - http://sottwell.com
                    Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                    Join the Slack Community - http://modx.org
                    • 27708 MODX Staff
                    • 2,502 Posts
                    Susan, Aptana is built on Eclipse and seems more focused on php/ruby dev over a broad general application IDE like Eclipse. The problem with an IDE over an editor is the learning curve for using the App when already trying to learn something new can be annoying.

                    I’m not going to say another word on Revolution ’til I put the wheels down on it for a while.

                    Great, thread and even better that it is getting worked out in the team forum vs. open forum.

                    [MODERATOR: Please maybe move this to BlueSky]
                      Author of zero books. Formerly of many strange things. Pairs well with meats. Conversations are magical experiences. He's dangerous around code but a markup magician. Blog ✦ Twitter ✦ LinkedIn ✦ GitHub
                      • 22303 MODX Staff
                      • 10,725 Posts
                      I liked Aptana (for Eclipse, yes it comes as an Eclipse add-on since it is built on the Eclipse platform) at first; but started having lot’s of problems and found Spket much better for Javascript without crashing Eclipse so much... they may have improved it, but personally, I’ve been happy without Aptana.