вторник, 11 августа 2015 г.

Instead of greetings…

Original in Russian: http://18delphi.blogspot.ru/2013/03/blog-post.html





I have been programming on Delphi for 18 years. Among other things, I know C, C++, Objective-C, asm PDP-11, asm-Intel86, FORTH and some "gibberish" languages. I want to share the TECHNICAL details of my work as a programmer and my thoughts about programming and architecture.


Apart from it, I am very interested in TDD and UML.


Here and there they say “who on earth need it?” in regard to TDD :-) I’ve almost got used to it.


As a matter of fact, GOOD programmers are the FIRST who need testing. Or, perhaps, BAD ones... Surely, not genios... who can not PREDICT their code’s behaviour when making the SLIGHTEST changes to it.


I’ll give an example. I have spent long and tiresome but interesting time on programming the Everest editor. A COMMERCIAL product was made on it.


So, one of the Everest’s features is printing and print preview. How we can debug it?


Suppose documents contain several thousands pages. Print? Several PACKS of paper?


Virtual printer is also useless.


I have been editing the code of the “print engine” for a VERY long time. And so I got trapped in the “programmer’s swing”: you edit here, it fails there, you edit there, it fails here… This is ENDLESS... My brain was so exhausted... It felt I could kill somebody... The functionality was not working...


Moreover, the Quality Group pointed at errors one after another… The Quality Group was my “Scourge of God”! They detected my errors FASTER than I could fix them...


Here and there appeared pages in the document that could not be printed or where the application simply failed....

That was the point I thought about TESTING... I was scared and terrified... I wanted to COVER all functionality with tests... I could not come up with the idea how to do it... Thoughts were tumbling in my brain.. I though about “how to find a SUPER-test to cover ALL AT ONCE"....


I felt like beating my head over the wall...

But I found a wise man...


Aleksandr Mozhaev... He said, “there exist DUnit, the Unit-tests for Delphi... you probably know... nothing extraordinary… but very useful..." I DID NOT KNOW...


I decided to try....


When I “looked into” DUnit, I was DISAPPOINTED... It was not only far from extraordinary - it was SIMPLE and “flat”...


"I can do this too"...


I asked Mozhaev, “so what?”...

He said, “try and you’ll like it"...

I shrugged my shoulders and decided to try...


By that moment, I had already written several frameworks... I actually thought that “I know how to teach programming to everybody" :-)


(sarcasm here)


I began to play with DUnit...


"Nothing extraordinary".. "Silver bullet here?"


I see published-methods that are “somehow” shown in “some” tree... So what?


However, I decided that if they advise it is worth trying...

I played further... I wrote MY FIRST TEST (not the very first in my life, but the FIRST for DUnit).. It printed the text... Or, rather did “print preview”, through the virtual canvas...


The test passed :-) I saw the “green light”.


Next, I worked on a “spherical cow in a vacuum”... I tried to launch this test automatically... I was DISPAPPOINTED AGAIN...


Thing is, I thought we could just launch exe-file and specify a run-time key for it: "come on, launch the test automatically"....

YOU WISH !!!


IT APPEARED there were not ANY key...


And so, I began to “grokk the source code" (as said my colleague).


After a thoughtful "grokking" I learned that, in order to execute tests automatically, we need to compile ANOTHER exe-file in consol mode (not the GUITestRunner but ConsoleTestRunner!).


"What the devil!", I said to myself, “these authors of DUnit must have me by the tale"....


They have ME, the man who managed “gibberish” language and Rational Rose (sarcasm again) by the tale?!!!


But then, I thought… and thought (and I liked it). I thought about, actually why I can not have the GUITestRunner and ConsoleTestRunner in ONE application. It turned out I CAN NOT. Though, it was just TECHNICAL complexity. I solved the issue.


I mate a hedgehog and a snake.. I mean I combined GUITestRunner and ConsoleTestRunner and refined them. The ConsoleTestRunner has got a child class KTestRunner. Back then I was already thinking about publishing the results of tests in our “knowledge base” and bug-tracker.


As a result, tests (ONE test) worked either both manually and automatically (if command-line option ItsLAW was set).


Next, I added automatic tests to automatic launch from Scheduler and I was HAPPY.


i was happy for I managed to make this staff work, not because I understood “why I need it".


Till the moment... Till the moment when the TEST FAILED!!! :-) That is how I UNDERSTOOD!! LITERALLY the light came on me!


I edited “a regular boring error from Quality Group", again about PRINTING...


I edited it THE DAY BEFORE, CLOSED the error and went home to SLEEP happy.


When I came in the morning, MY FIRST TEST FAILED!!!


I was kind of struck by the lightning!!! This is it!! Now I know WHY!!!


I decided to puzzle out ‘what is the matter and what I broke yesterday".


And so (bless my heart!!!) I made a WISEST thing... I WOULDN’T EDIT the code... I made a SECOND TEST... You’re right... It is VERY SIMPLE when you know... But I DID NOT KNOW then...


I made (I repeat) the SECOND TEST based on the error closed the previous day and checked and closed by the delighted Quality Group.


SURE, the SECOND TEST passed...


The FIRST TEST still failed as before...


I spent the whole next week trying to find out what I broke in the FIRST TEST (the Quolity Group did not find yet). It gave me no peace...

I launched the test manually and pushed different buttons... You see, I am a BAD programmer, I can not solve the task with my INTELLECT (I tried), I can only “push the buttons”....


At some point… at some point… at some point… I PUSHED THE RIGHT button… The FIRST TEST PASSED!!!


I launched it once and ONCE AGAIN - it PASSED...


(Let me note, I launched tests manually - not ALL at once but ONE test, the FIRST one).


I committed the code, wrote the error and closed it and WENT HOME happy....


When I came to work the next day I was once again DISAPPOINTED...


The SECOND TEST failed :-(


Again, I felt like beating my head over the wall...


But I collected myself a man (sarcasm again) :-) and ran the tests again and again...


The “number one” (peg-legged) passed, the “number two” (bare-feet) was resistant to pass...


My pride of “genios programmer” and Rational Rose handler was wounded by this ‘little bare-feet savage", so I decided to take it up seriously...


The WHOLE day I sought for the cause of failure and could not find it... At long last, by 12 AM I found it... It was a “little comma”... What a comma was it!!! Silver bullet pales in comparison with it. I found it, though.


And so, NUMBER TWO passed!!!


I was beyond happy.

I committed the code and wanted to go home… I left the room, closed the door… I went to the parking...

An EQUIPOSE OF DOUBT was in me... I knew I ‘did not do something”...


So I came back...


And I ran BOTH TESTS automatically...


NUMBER TWO worked, but NUMBER ONE failed :-(


My pride was wounded again..


I totally did not want to go home...


"The swing", came to my mind.


"These bloody programmer’s swing"...


So I stayed there....


The error revealed itself... I was “in stream” and I KNEW what I had edited in NUMBER ONE and in NUMBER TWO... So I analysed the changes...


I FIGURED it out!!!


I changed and ran NUMBER ONE - it PASSED...


Then I ran NUMBER TWO - it PASSED TOO...


I went HOME happily...


Now I KNEW WHAT TO DO and what for...


----------------------------

You’d ask if “regression tests” are the issue...
"Sure!!", I’d say...


But! A bad genius programmer and Rational Rose handler DID NOT know about it, although he read a “million of articles” in which “wise men” tried to explain it to him...


But not I KNOW PRECIESLY WHAT TO DO...


---------------------------


Now we’ve got about 2000 "regression" tests that run EVERY night... EVERY day on different machines... A handful of machines... We don’t KNOW WHAT TO DO... Most important is we can QUICKLY respond when being “in stream”... as long as the “yesterday’s” changes are live and familiar... More often, I can FIGURE it out...


----------------------------


We’ve got no more than 100 printing tests and we don’t need a SUPER test that “covers all”... So we sleep in peace :-)


------------------------------


P.S. Next time, if I don’t quiet down, I’ll tell you how I got familiar with VGScene (ака FireMonkey), how I cursed it, how slow I was to enter the “layer-cake” of styles... I’ll also tell about Anton (unknowingly) putting me in the understanding the genios architecture of this library...


P.P.S. I’d also like to tell how we located the applications for Delphi and our conclusions.


P.P.P.S. I’d like to tell how I made FORTH-machine for testing the application for DUnit on the knee, how Dima wrote binding and the results.


P.P.P.P.S. It would be interesting to tell about programming on UML vs. "prototyping on UML" and the metaphor of  "microchips items" vs. "logic compiling on triggers".


P.P.P.P.P.S. Sure, I’d like to tell about my lifetime project, Everest editor, its technical details and solutions born when I developed it.

Комментариев нет:

Отправить комментарий