Categories
Technology

Pair Programming with ChatGPT

Pair programming is a software development technique in which two programmers work together at one workstation. One, the driver, writes code while the other, the observer or navigator, reviews each line of code as it is typed in. The two programmers switch roles frequently.

~ Wikipedia

Here’s a fun meme!

For a programmer, I think this makes sense. Generative AI has been evolving rapidly. It is only a matter of time (if we are not already there) to reach a point where it will be able to generate source code of adequate, or even high-quality. And this will force us (programmers) to re-invent our role in the industry.

In this post, I am sharing my first pair programming experience with ChatGPT, which helped me to quickly solve a problem (and make an open source repo out of it).

The problem

The other day, I needed to generate a set of QR codes. I am trying to have my first book published (more on that on another post), and we (my team and I) want to enhance the experience by adding QR references on strategic places inside the book. Our first thought was to go and create them manually, using one of the QR generator services available for free. And then, limitations and blockers started coming our way:

  1. Some services had trial / freemium plans that allowed for the QR code creation but, after the trial’s end, only a limited set of the generated QR codes would continue to be functional.
  2. The task was time-consuming. It was counterproductive to have someone do it by hand, multiple times for different services.
  3. The services we spotted didn’t offer bulk QR code generation, we had to create our QR codes, one by one.

Train of thought

At first, we started looking for alternative services online, preferably with bulk QR code generation. While searching, I started thinking that making my own bulk QR code generator shouldn’t be that difficult. I didn’t have previous experience with QR generation applications. However, I was sure that with a little research, I would find some open source libraries that could help me build something quickly.

With the first Google search, I found some great blog posts about generating QR codes. Nowadays, Python is my go-to programming language so, I intentionally looked for solutions in Python. I started reading the first post, and that was when it struck me; what if I asked ChatGPT to build the application for me?

Doing Agile with ChatGPT

OK, I had ChatGPT to work as my software engineer. That meant I had to play the role of the Product Owner and let it know what we were trying to build. I started by crafting the following requirements (in the form of a ChatGPT prompt).

Hello Miss Lemon*,

I want you to help me create a Python script with the following spec:

  • It will use the library Segno to create qr codes
  • It will take as input a .csv file that will contain the following columns:
    • url
    • icon
    • file name
  • For every row of the .csv file the script will do the following:
    • it will create a QR file in .png format with size 3000×3000 pixels.
    • The QR file will have as file name the “file name” of the respective .csv column.
    • The QR will lead to the url of the respective url column of the CSV.
    • In the center of the QR it will include an icon with the file path of the respective icon column of the csv file.
  • The png file will be saved in the parent folder inside a folder called qr_codes

* I am using a custom ChatGPT I have created, that I call Miss Lemon (inspired by the iconic character of Miss Lemon, the personal assistant of Hercule Poirot)

We wanted the result to look like this:

Proof of Concept

With the above prompt, ChatGPT created a proof of concept. In addition to the source code in Python, it also provided me with the following context:

This was very helpful as it highlighted which Python libraries I should have installed in order for the code to work and a sample of the input.csv file that was required for the bulk QR code generation.

The initial source code created by ChatGPT didn’t work 💩, due to the following error:

AttributeError: module 'PIL.Image' has no attribute 'ANTIALIAS'

But.. Stack Overflow quickly solved that, and I had my first QR code generated 🏆!

Iterations

Iteration #1: Functionality improvements

Now that I had a proof of concept, I wanted to make the “product” better. So I fed the result of the application back to ChatGPT and asked it to improve quality with the following prompt:

The new source code suggested by ChatGPT worked fine! Again, ChatGPT provided context on the enhancements:

Iteration #2: Source code documentation

Now that we had an application working properly, the next step was documenting our code. So, I requested ChatGPT to add proper docstrings and comments following Python’s best practices. Here’s the prompt and ChatGPT’s reply/reasoning:

I want you to document it following best practices on Python source code documentation. Also explain in the end why you documented it like that.

(Bonus) Basic Error Handling:

ChatGPT automatically implemented checks for missing files and invalid input data. For example, it added logic to verify the existence of icon files before attempting to overlay them on the QR codes. This ensured the script wouldn’t crash if something went wrong.

Iteration #3: README

With the script ready, I wanted to package the project in a way that would be easy for others to use. This meant adding a README.md file with clear instructions. I asked ChatGPT to draft the README, and it delivered a comprehensive document that included:

  • An overview of the project.
  • Installation instructions for dependencies.
  • Detailed usage steps with examples.
  • Guidance on customizing QR code resolution and icon size.
  • Error-handling tips for common issues.

You can find the README.md file, alongside the whole project, available in this Github repository.

Conclusions

In this post, we created a small-size (in terms of functionality) application. ChatGPT created the respective source code and, after “further discussion” via prompts, it improved the code base.

Notable highlights of the process were:

  • ChatGPT was able to infer some of the requirements (i.e. adding basic error handling in the code).
  • While the discussion was evolving, ChatGPT remembered and applied previous requests. For example, the request for a documented source code was done once, and it was automatically applied in every following iteration by ChatGPT.

I believe that Generative AI can help us craft high-quality source code by generating parts of it and iteratively improving them. For this process to be effective, we have to be able to converse with Generative AI models in a clear and structured way.

NOTE: As I continue to work on this project, I will probably either update this blog post or create follow-up posts, so stay tuned!

Categories
Guest Posts

Γιατί ανοικτό λογισμικό;

(δημοσιεύθηκε στο blog της Social Mind στις 20/10/2015)

Πριν λίγο καιρό είχαμε δει 5 λόγους για να δημιουργήσετε το εταιρικό σας website σε WordPress. Εκτός από ένα δωρεάν, εξαιρετικά ώριμο και πλούσιο σε λειτουργικότητα εργαλείο, το WordPress αποτελεί επίσης σύστημα Ελεύθερου Λογισμικού / Λογισμικού Ανοικτού Κώδικα (ΕΛ/ΛΑΚ), χαρακτηριστικό στο οποίο οφείλονται πολλά από τα πλεονεκτήματά του.

Για να μείνουμε στην ουσία, θα αποφύγουμε να εμπλακούμε στο διάλογο για το αν το Ελεύθερο Λογισμικό ή ο Ανοικτός Κώδικας είναι πιο δόκιμοι όροι και θα παρουσιάσουμε μια σειρά από πλεονεκτήματα που “θα απολαύσετε” εάν επιλέξετε να υλοποιήσετε τα digital assets σας κάνοντας χρήση ΕΛ/ΛΑΚ.

Πλήρης προσβασιμότητα

Σε συστήματα κλειστού λογισμικού, είναι στη διακριτική ευχέρεια των κατασκευαστών να σας αποκαλύψουν το κομμάτι των λειτουργιών του λογισμικού που εκείνοι επιθυμούν. Αυτό συμβαίνει γιατί πολύ απλά σαν χρήστες της εφαρμογής δεν έχετε πρόσβαση στον κώδικα (πως φτιάχθηκε δηλαδή το λογισμικό), αλλά μόνο στο τελικό εκτελέσιμο αρχείο.

Με το ΕΛ/ΛΑΚ, οι χρήστες έχουν πλήρη πρόσβαση στον κώδικα, το εκτελέσιμο αρχείο, την τεκμηρίωση και εν γένει σε οποιοδήποτε άλλο asset του λογισμικού. Έτσι υπάρχει διαφάνεια μεταξύ της ομάδας ανάπτυξης και του τελικού χρήστη, αφού ο τελευταίος μπορεί να πιστοποιήσει ότι το λογισμικό προσφέρει πραγματικά “ό,τι υπόσχεται”, είτε μόνος του (αν έχει τεχνικές γνώσεις), είτε χρησιμοποιώντας κάποιον εμπειρογνώμονα.

Η τεκμηρίωση υπάρχει (!) και είναι συνήθως υψηλής ποιότητας

Όταν δε χρειάζεται να μοιραστούμε τον πηγαίο κώδικα του λογισμικού μας με άλλους, συνήθως τεκμηριώνουμε πρόχειρα, ελάχιστα ή καθόλου. Αυτό συμβαίνει κατά κόρον στα λογισμικά κλειστού κώδικα αφού, επειδή ο κώδικας μοιράζετε μεταξύ των προγραμματιστών της εταιρίας, οποιαδήποτε απορία σχετικά με αυτόν μπορεί να λυθεί δια ζώσης.

Στο ΕΛ/ΛΑΚ τα πράγματα είναι διαφορετικά. Σχεδιάζουμε κώδικα ο οποίος θα χρησιμοποιηθεί, διορθωθεί και επεκταθεί, από προγραμματιστές που δεν γνωρίζουμε προσωπικά (και ενδέχεται να μη συναντήσουμε ποτέ στη ζωή μας. Προκειμένου λοιπόν το λογισμικό μας να είναι ελκυστικό προς όλους αυτούς τους εν δυνάμει συνεργάτες που θα τον επεκτείνουν pro bono, προσπαθούμε να γράφουμε όσο πιο αναλυτική και καλογραμμένη τεκμηρίωση γίνεται.

Ακόμη, όμως, και για projects ΕΛ/ΛΑΚ που η τεκμηρίωση είναι κακής ποιότητας ή ελλιπής υπάρχει περίπτωση κάποιος τρίτος να επέμβει και να τη διορθώσει.

Η λειτουργικότητα είναι ώριμη

Ένα πολύ συχνό φαινόμενο στα συστήματα λογισμικού είναι οι αστοχίες (bugs)… τα οποία για να διορθωθούν, πρέπει κανείς να τα βρει πρώτα. Πολλές εταιρίες λογισμικού σήμερα απασχολούν προσωπικό με την ιδιότητα του tester, δουλειά του οποίου είναι ο έλεγχος του λογισμικού για bugs.

Στο ΕΛ/ΛΑΚ επειδή το λογισμικό είναι συνεχώς ανοικτό και προσβάσιμο από όλους, οι τελικοί χρήστες το χρησιμοποιούν (και άρα το ελέγχουν), καταχωρούν τα bugs που βρίσκουν και πολλές φορές τα διορθώνουν κιόλας, αν έχουν τεχνική κατάρτιση.

Ας σκεφτούμε το εξής τώρα: Τι είναι πιθανότερο να είναι περισσότερο ελεγμένο; Ένα λογισμικό μιας εταιρίας που αναθέτει το testing σε μερικούς υπαλλήλους ή ένα λογισμικό που ελέγχεται καθημερινά από δεκάδες διαφορετικών χρηστών, ενώ χρησιμοποιούν το λογισμικό σαν τελικοί χρήστες;

Πληθώρα επεκτάσεων

Όταν φτιάχνουμε ένα σύστημα λογισμικού έχουμε στο νου μας μια σειρά πραγμάτων που θα θέλαμε να κάνει. Αυτό το λέμε version 1.0. Ας υποθέσουμε ότι το ίδιο λογισμικό θέλει να το χρησιμοποιήσει κάποιος άλλος χρήστης ή εταιρία. Οι ανάγκες του/της μπορεί να είναι διαφορετικές. Σε αυτήν την περίπτωση προχωράμε σε αυτό που ονομάζουμε επέκταση συστήματος, δημιουργούμε δηλαδή νέες λειτουργίες προσπαθώντας να καλύψουμε αυτές τις έξτρα ανάγκες.

Στο κλειστό λογισμικό επεκτάσεις γίνονται μετά από απαίτηση κάποιου πελάτη. Στο ΕΛ/ΛΑΚ, επειδή η πρόσβαση στον κώδικα είναι ελεύθερη, οι ενδιαφερόμενοι μπορούν να προχωρήσουν σε υλοποίηση των δικών τους επεκτάσεων ανά πάσα στιγμή. Οι άδειες ΕΛ/ΛΑΚ, ωστόσο, συνήθως επιβάλλουν αυτές οι νέες επεκτάσεις να “επιστραφούν” πίσω στην κοινότητα λογισμικού ώστε να χρησιμοποιηθούν και από άλλους. Έτσι, τα έργα ΕΛ/ΛΑΚ επεκτείνονται συνεχώς με νέες λειτουργικότητες που αποτελούν ανάγκες των τελικών χρηστών και το βασικότερο, οι επεκτάσεις αυτές είναι τις περισσότερες φορές δωρεάν για όλη την κοινότητα.

Μπορείτε να ζητήσετε support, αλλά δεν είστε υποχρεωμένοι

Δυο κόστη που είναι προαιρετικά στη χρήση ανοικτού λογισμικού είναι το κόστος άδειας (lisence fee) και το κόστος υποστήριξης (support). Επειδή το ΕΛ/ΛΑΚ είναι ελεύθερα διαθέσιμο προς όλους, οποιοσδήποτε επενδύσει χρόνο ώστε να το μελετήσει σε βάθος μπορεί να το κατανοήσει και να το υποστηρίξει. Αν δεν υπάρχει τέτοιο άτομο διαθέσιμο, η εταιρία μπορεί να αναζητήσει υποστήριξη από την κοινότητα του συγκεκριμένου έργου ΕΛ/ΛΑΚ επί πληρωμή.

Φορητότητα και αλλαγή τεχνικού team

Αν έχετε συνεργαστεί με εταιρίες ανάπτυξης ιστοσελίδων κλειστού κώδικα, μπορεί να έχετε συναντήσει τον όρο ότι αν επιλέξετε να αλλάξετε συνεργάτη, δεν μπορείτε να “πάρετε” την ιστοσελίδα σας μαζί. Η λογική πίσω από αυτό είναι ότι, αν πάρετε το site μαζί σας, παίρνεται και τον πηγαίο κώδικα, που είναι ιδιοκτησία της εταιρίας που το έφτιαξε.

Με τα συστήματα ΕΛ/ΛΑΚ αυτό δεν είναι πρόβλημα καθώς ο κώδικας βρίσκεται ήδη ελεύθερα εκεί έξω. Αυτό σημαίνει ότι ανά πάσα στιγμή επιλέξετε να αλλάξετε συνεργάτη, το website σας μπορεί να μετακινηθεί χωρίς πρόβλημα στο server του νέου συνεργάτη χωρίς να χρειάζεται να το φτιάξετε, και άρα να το πληρώσετε, από την αρχή!

Categories
Chest

Podcast που αξίζει να ακούσεις: Software Engineering Radio

Στην πρόταση αυτού του μήνα συναντάμε ένα podcast για την τεχνολογία λογισμικού. Πρόκειται για μια εκπομπή που στοχεύει στον επαγγελματία προγραμματιστή και έχει σαν στόχο να παρουσιάσει όλες τις νέες εξελίξεις στον χώρο της τεχνολογίας λογισμικού. Διάφορες θεματικές που έχουν φιλοξενηθεί κατά καιρούς αφορούν ανάπτυξη λογισμικού, testing, devops, hosting, scaling, κ.ο.κ. Η εκπομπή είναι μια παραγωγή του επιστημονικού περιοδικού IEEE Software.

Στο επεισόδιο που ακολουθεί ο István Lam εξηγεί σε πολύ απλή γλώσσα τι ακριβώς συνιστά ο όρος “Privacy by Design” όπως αναφέρεται στον κανονισμό περί προσωπικών δεδομένων στην Ευρωπαϊκή Ένωση, GDPR .

(Photo by Fancycrave on Unsplash)
Categories
Stories

Software metrics’ tools and where to find them

(last updated: February 4th, 2018)

There are several ways to analyze software. Depending on the scope we may be interested in the quality of the code, the documentation, the developer’s team and its activity and so forth. Here are some free software metric tools that can get you started with software analysis.

Tools for Static Program Analysis

Static program analysis refers to the analysis of the source code of a software rather than an analysis on an execution level.

  • PHPQA is a free, open source software project that supports a wide range of analyzers (e.g. phploc, pdeend, phpmetrics, etc.) for PHP. [demo]
  • Checkstyle, Findbugs and PMD  are free, open source software projects for Java, also available as plug-ins for the Eclipse and IntelliJIdea IDEs.

Didn’t find what you were looking for? You can try this exhaustive list of tools, grouped by programing language, maintained by Wikipedia.

Software Engineering Guidelines Compliance

  • Better Code Hub checks your code base for compliance against 10 software engineering guidelines – and gives you immediate feedback on where to focus for quality improvements. The tool can be used free for open source and non-commercial use.

Community Activity Analysis

Big software projects are usually built from several developers. Those teams or communities – for Open Source projects – are usually organized using a control versioning system (svn, git. etc.). Those control versioning systems are storing valuable data about the activity of those teams / communities the analysis of which can lead to very interesting findings.

  • GitsGtats – for projects using git-like environments (Github, Gitlab, etc.). [demo]
  • StatSVN – for projects using SVN. [demo]
  • Grimoire Lab – a very mature tool that can help with data gathering from several platforms (Github, Bugzilla, Slack channels, etc.), data analysis and visualization. [demo] NOTE: If you are interested in using Grimoire Lab for your own projects you can test the online service Cauldron.io (free for public projects on Github).