Code quality

Alexander Rozumiy, Innovecs

Code quality

Alexander Rozumii
github.com/brain-geek
@brain-geek

External quality

This is the quality of the product that is perceived by the users of the product. This includes the stability of the product, the ease of use of it, the interaction design and the way it conforms to the requirements

Internal quality

This is the quality of the source code, the quality of the architecture, the quality of the development process around the product, etc. Anything that is not perceivable by the users of the software.

    	bool IsBukva(char symbol) {
    	  switch(symbol) {
    	    case'a':return 1;break;
    	    case'b':return 1;break;
    	    case'c':return 1;break;
    	    case'd':return 1;break;
    	    case'e':return 1;break;
    	    case'f':return 1;break;
    

Or Regex.IsMatch(input, "[A-Za-z0-9]")

Not only code

      <table cellspacing="0" width=960 cellpadding="0" 
      border=0 align=center class=txt>
      <tr><td>
      <div style="position: relative; width: 960px; height: 190px; 
      top: 0px; z-index: 999;">
    

So, what should we do?

Know your tools

      void get_tomorrow_date( struct timeval *date )
      {
        sleep( 86400 ); // 60 * 60 * 24
        gettimeofday( date, 0 );
      }
    
      res = nil
      pics = self.pictures.not_price.all
      if pics && pics.any?
        res = pics.first
      end
    

Or res.last

      - (void) closeApp {
         int closer = 1 / 0;
      }
    
      $('div').each(function () {
        if ($(this).attr('id') == 'blok') {
          $(this).html('');
        }
      });
    

Or $('#blok').html('')

Think
Yes, THINK

        if self.from <= Date.today
          if self.to
            if self.to >= Date.today
              true
            else
              false
            end
          else
            true
          end
        else
          false
        end
    
      $week['monday'] = date("d.m.Y", $week_start);
      $week['tuesday'] = date("d.m.Y", $week_start + 1 * 86400);
      $week['wednesday'] = date("d.m.Y", $week_start + 2 * 86400);
      $week['thursday'] = date("d.m.Y", $week_start + 3 * 86400);
      $week['friday'] = date("d.m.Y", $week_start + 4 * 86400);
      $week['saturday'] = date("d.m.Y", $week_start + 5 * 86400);
      $week['sunday'] = date("d.m.Y", $week_start + 6 * 86400);
    
      if city.present?
        if city.city.present?
          city = city.city
        else
          city = "NIL"
        end
      else
        city = "NIL"
      end
    

Name your variables wisely

      int p,k,l,i,j,d,q,R,t,r;
      S6:    k+=d; if (k==l) goto S13; else x[k]=x[j];c[k]=c[j];
      S7:    j-=1; r-=1; if (r>0) goto S6; else goto S12;
      S8:    k+=d; x[k]=x[j]; c[k]=c[j];
      S9:    j-=1; r-=1; if (r>0) goto S3;
      S10:   k+=d; if (k==l) goto S13; else x[k]=x[i];c[k]=c[i];
      S11:   i+=1; q-=1; if (q>0) goto S10;
      S12:   q=p; r=p; d=-d; t=k; k=l; l=t; if (j-i<p) goto S10; else goto S3;
    

Full version

      void loop() {
        message(false);
        message(true);
        message(false);
        message(true);
        message(false);
        message(false);
      }
    

Comments and identation: you write code for people

      function newuser($username){
        return;
        /*
          ДВАДЦАТЬ СТРОК КОДА
        */
        //не пойму почему не работает:ФИО Программиста
      }
    
    # заменяем в разделитель на запятую в поле "Количество"
    $row[4] =~ s/\./,/;
    # лишние нули красим цветом фона
    $row[4] =~ s/,000/.000<\/font>/;
    
      def self.allow_some_behaviour?
        # better safe than sorry.
        bool = !false ? !false : !!false
        # type checking
        if bool
          # short circuit just in case
          return !true;
        elsif !bool
          return !false
        end
      end
    

Refactor your code. Copy'n'paste costs a lot

      switch ($data2["PHONE"][$i]["type"]) {
      case “Факс”:
      echo “<option selected>Факс”;
      echo “<option>Офисный телефон”;
      echo “<option>Колцентр”;
      echo “<option>Телефон”;
      break;
      case “Офисный телефон”:
      echo “<option>Факс”;
      echo “<option selected>Офисный телефон”;
      echo “<option>Колцентр”;
      echo “<option>Телефон”;
    

Full version

      If Day(Date) = 1 Then
          PreviousDay =  DateSerial(Year(Date), Month(Date), 1) - 1
          date_past_normalized = CStr(PreviousDay)
      else
          PreviousDay = DateSerial(Year(Date), Month(Date), Day(Date)) - 1
          date_past_normalized = CStr(PreviousDay)
      End If
    

TDD

What next?

  1. Delete your code, Aleksander Dabrowski

Anything else?

Code quality

Alexander Rozumiy, Innovecs

Presentation: brain-geek.github.com/quality-presentation