Verification vs Validation in practice

Published on: 01.03.2019

Verification is the process of checking that the software meets the specification.

It is doing what you wanted it to do.

An example could be that function need to add two numbers, then you verify (like write unit test) that it is correctly doing that.

Validation is the process of checking whether the specification captures the customer’s needs.

Using the example of the function need to add two numbers verification need to confirm that this function is really what user need, eg. maybe you need to multiply two numbers.

Practice vs theory

When I first head about validation I was able to understand it in theory, but in practice, I was thinking it is easy to know what you want why do you need to validate it.

Then I had personal experience of why and how validation is hard.

I build wrong software for myself and I had no one else to blame.

How I build wrong software for myself

My idea was to make software that will be run at 1 AM every day, will take all real-estate ads from https://www.njuskalo.hr/ for my town listed on a previous day, sort them by price for a square meter and send them to email.

Basically, I wanted all new ads per day to my email, sorted by price for a square (one day delay was fine for me).

Looks simple enough, what could go wrong?

After a few days and I had it running in production and it was working, verification was successful, I every day I got all ads from the previous day.

Why validation was wrong

After a week I found out that my software was useless.

What was the problem?

Rember that I wanted to get “I wanted all new ads per day to my email”, I wanted all “new ads per day”, but what I got was all updated and new ads per day.

Let me explain.

Every day I was getting around 200 ads per day and I noticed that a lot of them were the same ads, day after day.

What was happening is that a lot of people were just updating the same ad every day.

And they are doing this so that their ad is always on the first page, sometimes they even do it a few times per day (later I found out that a friend of a friend was contracted by one local real-estate agency to make software that will automatically update ads for them).

Altho my software was working correctly, only after I have made it I found out it is useless because of wrong assumptions.

My assumption was that every ad will be added only once, not that 60% of adds will be updated every week.

I have solved this problem by making version two that could know if an ad is new or updated and if updated what was updated.

Am I stupid

This experience was fascinating to me.

On this project, I was everything: user, project manager, architect, coder, quality assurance, investor, every hat was on my had and I manage to build the wrong thing.

It gave me a practical understanding of why it is common that the end user is not happy with the finaly product.

Even if everything is done correctly it is possible that the final product is not solving user original problem due to wrong initial assumptions.

How to improve validation

One approach is to make MVP, in this way you will spend fewer resources on version one.

If validation of MVP is correct, then add additional features, if not cancel it

Another approach is to get some domain knowledge ether internal or external.

I had built a few web-scrapers in the last few years and now know a few tricks about that domain, but I learned each on the hard way.

I also understood why some companies hire domain experts consultants (just be sure to have a good one).

Technology

For those interested in what tools did use to build my software here is the list: Scrapy, dataset, yagmail.

Raspberry Pi 2 B

Published on: 15.02.2019

After 3,5 years of owning and never using (let us talk about not being a finisher later) Raspberry Pi 2 B I finally decided to see for what it can be used in practice.

Yes, I know that now already Raspberry Pi 3 B+ exist and that it has better performance.

I did use the original Raspberry Pi in 2012 to make a simple version of Screenly, but that is a story for another time.

First, I went to the official webpage to see what is new and how to install operating systems (I will use abbreviations OS from here on).

There I have found out that the best way for beginners is to use NOOBS.

My experience with NOOBS is positive, there are few OS that can be installed with it.

Another software with similar capabilities is BerryBoot, it has some additional OS that NOOBS does not have, but also NOOBS have an OS that
BerryBoot, so best is to try both.

One tip, label of miniSD card must be called boot.

Just for information, all tests have been done on 22inch DELLmonitor.

Using Raspberry Pi 2 B as desktop PC

My test was basically how good youtube is working.

Surprisingly better than I expected, Raspberry Pi 2 B on Raspbian is able to play 360p videos with no problems, even 480p video worked, but the video had some lags but the audio was fine.

Form my opinion the biggest drawback for using any Raspberry as a desktop computer is lack of software (eg. no DropBox) because the software needs to be compiled for RISC processor.

Retropie

Retropie is OS for playing retro games.

NES and SNES games were fine, but N64 (N64 was my first 3D console, so there is an emotional connection) was not so good (GoldenEye on 10 FPS, not playable).

Raspberry Pi 3 is working better according to Reddit.

CCTV

Using motioneye as CCTV on Raspberry Pi 2 B is working better than expected.

You can add a local camera to motioneye or even remote IP camera.

Motion detection is supported with upload to FTP, DropBox, Google Drive, etc.

Just be aware that you can not expect the same quality as of specialized dedicated CCTV system, but it is perfect for a hobby project.

Public Facing Screens

You can use Raspberry Pi 2 B as a public facing screen, one useful OS for that purpose is Screenly.

It offered as a monthly subscription model, but if you use it just in a local network, it is free.

Tools and links

The tools:

balenaEtcher cross-platform tool to flash OS images to SD cards

SD Memory Card Formatter formats SD/SDHC/SDXC Cards

Links:

https://www.trustedreviews.com/reviews/raspberry-pi-3-performance-and-verdict-page-3

https://www.jeffgeerling.com/blog/2018/raspberry-pi-3-b-review-and-performance-comparison

FOSCAM FI8908W network IP camera

Published on: 01.02.2019

I bought this camera from Deal Extreme, almost a decade ago.

Anyway, if plan to use this camera first step is to upgrade to the newest firmware, on official website I found nothing, but they do have some software tools, luckily there are instructions on Deal Extreme Forums.

I did my firmware upgrade step by step, from a version on my camera to the next firmware version.

Maybe upgrade to last would firmware work also, but I did not want to take unnecessary risk and brick my device.

There is an upgrade for System firmware and Embedded Web UI first upgrade System firmware and then Embedded Web UI.

Also, there is similar model fi8918w, AFAIK last firmware version should not be upgraded to this model.

Be sure to understand procedure from Deal Extreme Forums before starting the firmware upgrade process.

My experience with a version with last firmware

The camera is giving 640×480 image, during the daylight it is acceptable, during the night you can see that somebody is there but not who, so it is not useful in a night mode.

Movement of a camera is possible, it is working fine but web UI for control is not working on IPad only regular PC browsers.

The device should offer an audio connection, but I have not used it

WiFi connection I have used, I just trust the cable more :-).

The camera also has an IO port for motion detection and trigger, but I have not used it.

There is also a possibility of motion detection, recording of video/pictures and sending to email and FTP upload.

I have not tested this feature because it is only working on Microsoft Internet Explorer so to use it you have to have one PC with it always running

Electricity consumption is about 3.5 till 4 watts/hour on 230 voltage.

I did notice that it need to be restarted once per week, otherwise, it will just get stuck.

Should you use this camera

It depends on what purpose you want to use it.

If you want to have a daylight live stream without recording and alarms and it is OK for you to restart it every week that it is fine.

Also one decade ago this was a great device for its price, today it is better to get a camera on Raspberry Ri with motionEye.

If you plan to use this camera with motionEye add it as Network Camera.

The most important lesson for new programmers

Published on: 15.01.2019

On my “Sending email from Python” blog post what was cross-published on Medium I got a comment asking how to send an email via outlook programmatically.

My first reaction what that this is some troll or bot.

So I did “Let me google that for you” answer and later got “Thank you” response.

That got me thinking, maybe he was not an internet troll, maybe he just does not know how to google.

It never crosses his mind that he can ask google for the answer.

Why I was thinking that somebody was trolling me

I am an experienced (15+ years) software developer, I am experienced because I know that when I do not know something first I google it, that I search on youtube and the last resort is to ask StackOverflow.

This is what professionals do, they do not ask questions on random blogs in hope that somebody will respond.

Learn how to google

For beginners learning to code, best what you can do for yourself (and other) is to learn to google what you do not know.

Today it is easier to learn coding than 20 years ago when I was starting.

At my time the only thing that you had was a book (if you were lucky).

Today there are much more opportunities to learn:

  • you have Youtube today what is the largest free video learning tool
  • google for asking
  • and StackOverflow communities where you can ask questions

Be aware that you should not ask a question specific to your particular coding problem, just bring it to a more abstract level.

Tips on googling

From my experience, it is important to know which keywords to google.

But if you do not know keywords you can always start with “how to …..”.

Any action is better than no action.

Most programmers are financial morons

Published on: 01.01.2019

Let me start with one true story from the year 2011.

At that time I was working as a software programmer (90% C++) in a team of 5 people.

One morning, a friend from team started showing cool new source code editor called Sublime Text.

He was very happy with it, he used it on the job, for his own pet projects, and for his freelancing side jobs for almost few months.

But for him Sublime Text had one drawback, he had to pay 100$ for it (at time of this writing Sublime Text license is 80$, but I think that at that time it was 100$, but I could be wrong).

At that time I know that my friend is a financial moron.

I tried to explain to him, using same logic like in this blog post, but he just could not get it, he only understood that he has to spend money.

Why most programmers are financial morons

Let say that he was only using Sublime Text every second day (altho, knowing him it was probably every day).

With every second day assumption that is 182 day per year.

He was happy with a new tool, it was better for him, so let us say that he got 10 extra minutes of work every day.

10 minutes times 182 days is 30 hours of work more per year.

To get a break even he would need to make 3,33$ per hour of work.

Even at that time, he was charging his freelance rate at 20$ per hour and he had around 5 hours of billable work hours per week.

He is a smart guy, but he was thinking that toll is expensive.

Economically speaking, he does not know how to do a cost-benefit analysis.

It is strange how logically intelligent programmers (believe me, you do have to be logically intelligent to write computer programs) never invest in tools that basically have ROI in days.

Conclusion

Do cost benefit analysis before saying that something is expensive or cheap.

Disclaimer:
I have no interest do you use or buy Sublime Text or not, I am just using it as an example.

Do not use Selenium for web scraping

Published on: 15.12.2018

Disclaimer:
This is primarily written from Python programming language ecosystem point of view.

I have noticed that Selenium has become quite popular for scraping data from web pages.

Yes, you can use Selenium for web scraping, but it is not a good idea.

Also personally, I think that articles that teach how to use Selenium for web scraping are giving a bad example of what tool to use for web scraping.

Why you should not use Selenium for web scraping

First,Selenium is not a web scraping tool.

It is “for automating web applications for testing purposes” and this statement is from the homepage of Selenium.

Second, in Python, there is a better tool Scrapy open-source web-crawling framework.

The intelligent reader will ask: “What is a benefit in using Scrapy over Python?

You get speed and a lot of speed (not Amphetamine :-)), speed in development and speed in web scraping time.

There are tips on how to make Selenium web scraping faster, and if you use Scrapy then you do not have those kinds of problems and you are faster.

Just because these articles exist is proof (at least for me) that people are using the wrong tool for the job, an example of “When your only tool is a hammer, everything looks like a nail“.

For what should you use Selenium

I personally only use Selenium for web page testing.

I would try to use it for automating web applications (if there are no other options), but I never had that use case so far.

Exception on when you can use Selenium

The only exception that I could see for using Selenium as web scraping tool is if a website that you are scraping is using JavaScript to get/display data that you need to scrape.

Scrapy does have the solution for JavaScript with Splash, but I have never used it, so far I always found some workaround.

What to use instead of Selenium for web scraping

As you can guess, my advice is to use Scrapy.

I choose Scrapy because I spend less time developing web scraping programs (web spiders) and execution time is fast.

I have found Scrapy to be faster in development time because of a Scrapy shell and cache.

In execution, it is fast because multiple requests can be done simultaneously, this means that data delivery will not be in the same order as requested, just that you are not confused when debugging.

What about Beautiful Soup + Requests

I have used this combination in the past before I decided to invest time in learning Scrapy.

Do not make the same mistake as I did, development time and execution time is much faster with Scrapy, than with any other tool that I have found so far.

Last words

This is not rant about using Selenium for web scraping, for not production system and learning/hobby it is fine.

I get it, Selenium is easy to start and you can see what is happing in real time on your screen, that is a huge benefit for people starting to do/learn web scraping and it is important to have this kind of early moral bosts when you are learning something new.

But I do think that all these article and tutorial using Selenium for web scraping should have a disclaimer not to use Selenium in real life (if you need to scrape 100K pages in a day, it is not possible to do it in single Selenium instance).

To start with Scrapy it is harder, you have to write XPath selectors and look at source code of HTML page to debug is not fun, but if you want to have fast web scraping that is the price.

Conclusion

After you learn Scrapy you will be faster than with Selenium (Selenium just have a lower-angle learning curve), I personally needed a few days to get the basics.

Introduction to Python packet Dataset

Published on: 01.12.2018

Python packet dataset describes itself as databases for lazy people and they are correct.

For saving data with dataset all you need is just a Python dictionary, the keys of the dictionary are columns in a table and that is all.

Dataset will automatically make all tables and columns necessary.

Internal data is stored in SQLite, PostgreSQL or MySQL database, my experience has only been with SQLite so far.

My experience

In one project I use it just for memory database, after scraping data from a website it is stored in-memory SQLite.

Then I can use standard dataset API to retrieve data with certain criteria and sort it, before emailing it.

On another project, I use it to store data in SQLite and later to retrieve it.

I must admit that for everything else than basic searching, filtering and sorting you have to write SQL queries.

One useful feature is upsert, upsert is a smart combination of insert and update.

If rows with matching keys exist they will be updated, otherwise a new row is inserted in the table.

There is also a feature to export data to CSV or JSON.

Conclusion

If you think that using DB on your next project is overkill, but you do need to filter, search or sort data, take a look at datase.

It is much better than to make custom solutions, I know because I did stored data in pickle format and wrote a custom function for filtering, sorting and retrieving data from pickle, before I learned about dataset.

The question of tradeoff in software, business, and life

Published on: 15.11.2018

In software development, it is common to have discussions about what technology is better or the best.

Those discussions look like a wise discussion for beginners, looking for a perfect solution, the holy grail.

But they are useless because there is no perfect solution, the much more important question to answer is what tradeoffs are you making and why?

Why tradeoffs are necessary?

In any system, if you want to increase one aspect of the system that has to come at the expense of some other aspect.

Let us take the car for example.

I am taking the car as an example because I suppose it is easy to understand.

If you want to make a car acceleration faster, you have to make it lighter and fuel consumption will go up.

So, to increase acceleration you have to decrease weight and fuel efficiency.

This is a simplified example, there are many imperfections, but I hope that reader can get the point.

Basically, you have to do tradeoff.

Back to the discussion on tradeoffs in software development

When you add business aspect into considerations, it is even more complicated.

Things that make sense from a technical standpoint, are a disaster for business and vice versa.

The hard thing about a tradeoff between business and technology is it is almost impossible to have one person who can understand just one side completely so what to say about both at the same time.

Today software systems are so complicated that it is common that there is no single person who understands everything.

That is why REST API is popular, but that is the discussion for another day.

Concrete software example

I have one personal program, that I use every day, it is responsible for saving me 1000$ on average per year, so I do have the real monetary use of it.

And SQLite DB is the main part of it, and I do not ever use indexes in it (no cost benefit from it).

I know that SQLite for my use case, from point of speed, is not the best option.

But I took SQLite because it was fast to start, backups are just copying one file and I am running SQL queries once per day while I am sleeping.

Currently, an average time for all SQL queries are around 30 seconds, and as DB file gets larger query time will also increase.

Even if it gets to 1 hour (what I am not expecting even in the next 100 years), that would be fine for my use cases.

My deployment platform is shared hosting with the flat monthly bill so increased CPU time is also not a problem from me, altho if I used platform with serverless billing per CPU time it could be.

Conclusion

Know what tradeoffs are you making and even more important is why.

Introducing PyAutoGUI

Published on: 01.11.2018

I found out about PyAutoGUI Python packet from Automate the Boring Stuff with Python book.

With PyAutoGUI you can automate GUI interaction on your computer.

PyAutoGUI is working on Windows, OSX and Linux, altho I have used it only on Windows.

Most GUI automation can be done just by automating mouse movements and keyboard input and PyAutoGUI supports it.

There are also functions for providing message boxes, saving the screenshot and finding an element from the image on the screen.

Personally, I have found PyAutoGUI useful, for automating some of my workflows.

To be honest, I use it for 45 minutes of work every month (I know this is not much), but I have found that if I manually have to do same interactions for 45 minutes it is really killing my soul, so I decide just to automate it.

If you want to automate web page interaction use Selenium, because with Selenium you can access elements on a web page independent of their position on the screen.

Because with PyAutoGUI you can just move the mouse to specific coordinates, that means if the resolution or layout of GUI has been changed, you need to update coordinates in your code.

Keep all coordinate in your code as constant in one place, so that you do not need to change them all over your code when change is needed.

This theoretically could be avoided if you use images as reference for finding elements on your GUI, but you will have the same problem if the appearance of the elements is changed, but then instead of changing coordinate in the code you have to change all reference images, what is more work.

My personal preference is to use hardcoded coordinated instead of images as the reference.

Using Selenium has also become popular for scraping pieces of information from web pages, but better is to use specialized framework for scraping like Scrapy, because of additional features like caching HTTP responses (quite a time saver in development).

The Clean Coder: A Code of Conduct for Professional Programmers, book review

beginning_serverless_computing-Book_Cover

Published on: 15.10.2018

Number of pages: 211
Written by: Robert C. Martin (Uncle Bob)
Publish by: Prentice Hall

Conclusion
Read this book if you plan to make money by writing code for others.

Review
This is an interesting book.

It is not a soft skill book, but it is also not a technical book, it is something in between.

The book has valuable advices on how to behave as a professional programmer.

The author is writing software professionally since 1970, so there are a lot of stories about how the software was made back then. I liked those stories a lot.

Chapters titles are: Professionalism, Saying No, Saying Yes, Coding, Test Driven Development, Practicing, Acceptance Testing, Testing Strategies, Time Management, Estimation, Pressure, Collaboration, Teams and Projects, Mentoring, Apprenticeship and Craftsmanship, Tooling.