Some thoughts on using chatGPT to write a program to determine which foods are fresh in Ontario

It is easy to find out which foods are fresh in Ontario. There are several guides, including this one from Foodland Ontario, that can help you with this. However, I wanted a particular guide that would list for me all the fresh foods for a given month only.  And since I couldn’t find a guide like that, I decide to write a python program to make such a guide.

In the past, to write a program like that, I would go through sample code I have, pull out bits of code that were good, and cobble together something from all these bits. Lately, though, I simply ask a service like ChatGPT or others to write the code for me. I find nowadays it’s just so much faster to go that route. Call me lazy. 🙂

Since I wanted this done quickly, I pointed chatGPT at the Foodland Ontario guide and asked it to do the following:

Write a python program that strips out the text on this page https://www.ontario.ca/foodland/page/availability-guide?gad_campaignid=22412095602
and leaves just the foods and the month they are grown on. Include all food that states that is Year Round.

Did ChatGPT do that? Yes, it did. Was the program any good? No, it was not! It somehow looked at that web page and decided the values were stored in a table, even though they were not. The web page is more complex than that and so the program was a pretty failure.

After many prompts, I gave up and took an alternative approach. For this new approach, I stripped out the data manually and created a simple CSV file. I then asked ChatGPT to write a program to process the CSV file. Since it is a simpler file, ChatGPT was able to produce a workable Python program that was able to process the CSV file and output the information I needed.

Perhaps a more skilled prompt engineer could have written a better prompt to process the code. I dunno. I am finding that LLMs — not just ChatGPT — are fine with writing some straightforward code based on non-complex inputs and outputs. They are not so fine once the inputs or outputs get complex. But that’s just my experience. YMMV.

I have also concluded that even warmer months like May in Ontario do not have much in the way of fresh food. No wonder there are so many food stories on asparagus and rhubarb! 🙂 You really need to hit June or later before you get into a cornucopia of fresh produce.

If you’d like to see the end result of my coding, go here to this repo: https://github.com/blm849/ontfoods

 

On futzing around with code

An example of a Prolog program

I was futzing around with code the other day. I wrote some html/css/javascript and then I wrote some unrelated prolog code. None of it had any value. The code didn’t solve some important problem. Some might consider it a waste of time.

But it wasn’t a waste. In both cases, I learned skills I didn’t have until I wrote the code. Those skills have value for the next time I do have to solve an important problem. Besides that, I enjoyed myself while coding. I was proud of myself for getting the code to work. That enjoyment and pride have value too.

Futzing around is a form of play, and any form of play is good for us as humans. Remember that the next time you consider taking on seemingly useless activities.

 

If you are using python packages like xmltodict or yaml, here is something to be aware of

If you are using python packages like xmltodict or yaml to write and read your own XML and yaml files, you probably don’t need to know this. But if you are reading someone else’s files, here is something to be aware of.

This week I had to process an XML files in python. No problem, I thought, I’ll use a python package like xmltodict to translate the XML into a dictionary variable. Then I could edit it and print out a new file with the changes. Sounds easy!

Well, first off, it wasn’t too easy: the nesting was horrendous. However, with some help from VS Code, I was able to power through and get the value I want.

Here’s where I got burned. I wanted to change the text in the XML file, so I had a statement like this to read it


mytext = python_dict["graphml"]["graph"]["node"][nodecount]["graph"]["node"][i]["data"]["y:ShapeNode"]["y:NodeLabel"]["#text"]

and then a simple statement like this to change it to lower text:


python_dict["graphml"]["graph"]["node"][nodecount]["graph"]["node"][i]["data"]["y:ShapeNode"]["y:NodeLabel"]["#text"] = mytext.lower()

Very basic.

Now this particular file is an XML file that has a graphml extension, which allows an editor like YED to read it. YED can read the original file, but it turns out xmltodict writes the file in such a way that the YED editor can no longer see the text. I don’t know why.

I spent hours working on it until I finally gave up. I wrote a much dumber program that read through the graphml file a line at a time and changed it the way I wanted to. No fancy packages involved. Dumb but it worked.

This is the second time this year a package has given me problems. In late January I wrote some code to parse yaml files for a client to extract information for them and to produce a report. Again, there is a package to do that: yaml. Which is….good…except when the yaml it is processing it is poorly written. Which this yaml was.

Again, I spent hours linting the yaml and in some cases having to forgo certain files because they were poorly constructed. What should have been easy — read the yaml file, transform it, write a new yaml file — was instead very difficult.

And that’s often the problem with yaml files and XML and JSON files: they are often handcrafted and inconsistent. They MAY be good enough for whatever tool is ingesting them, but not good enough for the packages you want to use to process them.

I think those packages are great if you are making the input files. But if you are processing someone elses, caveat emptor (caveat programmer?).

Advent of Code: a great way for coders to celebrate this season

You’ve likely heard of Advent, but have you heard of Advent of Code? Well let the maker of the site, Advent of Code 2023, explain what it is:

Hi! I’m Eric Wastl. I make Advent of Code. I hope you like it! I also made Vanilla JS, PHP Sadness, and lots of other things. You can find me on Twitter, Mastodon, and GitHub. Advent of Code is an Advent calendar of small programming puzzles for a variety of skill sets and skill levels that can be solved in any programming language you like. People use them as interview prep, company training, university coursework, practice problems, a speed contest, or to challenge each other. You don’t need a computer science background to participate – just a little programming knowledge and some problem solving skills will get you pretty far. Nor do you need a fancy computer; every problem has a solution that completes in at most 15 seconds on ten-year-old hardware.

It seems like just the thing for coders of all kinds, from amateurs to professional devs. Check it out. And if you want to get involved from day 1 in 2024, make a note on your calendar (assuming Eric still does it.)

Will there be Doom? (What I find interesting in hardware/software in tech Jul 2023)

While my last few posts on IT have been work related, most of these are on hardware and software and tend to be more hobby and fun related.

Hardware links:

Software links:

Hope something there was useful! As always, thanks for reading!

P.S. Before I forget… here’s a piece on how a hacker brought Doom to a payment terminal. Love it!

 

The history of people asking: is technology X going to replace programmers?

Recently Nature (of all publications) asked the clickbait-y question:
Are ChatGPT and AlphaCode going to replace programmers?  It then quickly states: “OpenAI and DeepMind systems can now produce meaningful lines of code, but software engineers shouldn’t switch careers quite yet.” Then why even ask the question? It goes on to say: Deepmind, a part of Google, “published its results in Science, showing that AlphaCode beat about half of humans at code competitions”.

Regardless of what you think about that article in Nature, here’s the thing to always keep in mind: technology X has been coming along to replace programmers forever.  We had machine code that was replaced with assembler language. We had Assembler language replaced with higher level languages like Fortran. We had a wealth of more sophisticated programming languages come on to the scene. In addition, programming tools like IDEs have come along to save the day and make programming easier for programmers. Yet we still have not lost the need for programmers to write programs.

Programming is still about taking what people want the computer to do and codifying it in a language that the computer understands. In other words: programming. As long as that code is required for computers to do what humans want, there will always be programmers.

Here’s another thing to consider: code is a more efficient way to communicate to a computer. I can write in English “count all the entries in this column from row 2 to 100 if the entry equals the word ‘arts'” or I can write in (Excel) code “=countif(A2:A100,”arts”)”. That efficiency will likely mean that coding will be around for quite some time yet. And people doing that coding will be programming, even if they don’t consider themselves programmers.

So no, Alphacode is not going to replace programmers and programming. It might replace some of the task of what some of them currently do. But programmers and programming will be around for some time to come.

(I like the image above because it captures how the software design and development process is a complex thing, and not just a matter of writing a bunch of code. A lot of thought goes into developing something like a smart phone application, and that thought results in code that results in a good app.)

What I find interesting in tech in general, Apr 2022


Well, I didn’t expect this week to be “what I find interesting in IT Week” , but here we are! I hope you have found it all useful. While the other posts were specific, these are of a general nature. From weird cool stuff to mainframes to iphones to architecture. Dig in!

IT Architecture: Here’s some tools you IT architects can use:

Cloud: some cloud related stuff:

Programming: here’s some things software and hardware folks might find interesting:

Finally: here’s some links that need to be seen without falling into a particular category:

Some good links on how to learn Python

A friend asked me for some help when it comes to learning Python. I put together this list for him, but it’s good for anyone wanting to learn the computer language.

  1. Why Learn Python
  2. Automate the boring stuff with python. A great book!
  3. Learn python in 24 hours. Another book. Also great.
  4. Learn python in 10 minutes
  5. Good doc on python
  6. Learn Python the hard way
  7. How to make a web app using Flask and Python
  8. How to build a twitter app in python
  9. Become a More Efficient Python Programmer

There are so many great resources on the Internet concerning Python. I could easily triple the size of this list. Start with these: you’ll find the rest soon enough.

(Image from Free Code Camp, which also has good links worth reviewing.)

What programming language should you learn? (2022 edition)

The best programming languages to learn in 2022, according to TechRepublic are these:

It’s interesting to see how things have changed. Back in 2015 when I wrote about this, Java was 1st and Python was in 4th. Javascript was 8th! I am not surprised by this.

Java and the C languages will always be good to know. But if you want to be marketable, learn some Python and Javascript.

Programming is on a spectrum, or how programming is like running

Programming is on a spectrum.  I have felt for some time. That said, I liked this article by Paul Ford, one of the best writers on IT that I know: ‘Real’ Programming Is an Elitist Myth | WIRED.  His and my thoughts overlap. First, yes you can do real programming/coding with simple tools. Anyone who writes their own HTML, Javascript, simple bash scripts or basic Python scripts is really programming. Heck, I argue that what people do in Microsoft Excel is a form of programming.

If you wanted to step up from small pieces of code, you could get a book like this and write all sorts of useful code. 

 

(That’s a great book, by the way.)

However there is a very wide spectrum for programming, and some people are very advanced in the form of programming they do. That should also be acknowledged. The work I do automating tasks by writing Python scripts is very different than the work done by people writing operating systems or other difficult tasks.

I like to think of it like running. If you run, you are a runner. End of story. If you work at running, you can enter a big race like the New York City Marathon and you will be with a range of runners from the very best in the world to people who will finish many hours later. The first and the last are all marathon runners, and the last are as real a runner as the first.

Same with programming. If you program, you are a programmer. You are as real a programmer as the person writing new code for the Linux operating system. Just like you can always get better as a runner, you can always get better as a programmer. It just depends on what you want to put into it and what you want to get out of it.

Developers and IT people: you need to have more than a good resume/CV

If you are a software developer or someone working in IT, you need to consider having more than a good resume or CV. You should consider having:

  1. an up to date profile in LinkedIn
  2. a professional web site (at least a one pager). It could be a blog, or an about.me page…something that provides information about yourself in a summary form.
  3. some repositories on github showing your work or an example of what you can do.

If you use github.io to host your professional web site, you get to cross off #2 and #3 with one effort.

I was reminded of this when I went to check out this page: DevProgress Tech Volunteer Questionnaire. You can see them asking for this information. It makes sense: if you are looking to hire a developer, it would be great to see not just what people are saying about them on LinkedIn, but what their code looks like too.

For some employees, putting code on github may not be an option. In that case focus on the first two and have a page somewhere on the web that discusses why you can’t host code there.

 

Why Python programs often have this: `if __name__ == “__main__”:`

If you were wondering why Python programs often have this: `if __name__ == “__main__”:` and then a call to a function, a good explanation is here.

In short, if your program is used as input to other programs, then you want to have that snippet of code in them. If your programs are standalone, you can get by without it.

What programming language should you learn? (2015 edition)

It depends on a number of factors, but if you want to decide solely on popularity, then you need to see this: The Most Popular Programming Languages of 2015 | ProgrammableWeb.

 

At the top you have some consistency, with Java at the top, and C, C++ and C# in the top five. Python, a language that I am becoming fond of and using to replace Perl, is up there at #4.

Following that are what you’d expect: PHP, Ruby, and Javascript, as well as some data oriented languages.

What is interesting, and not shown, are new and up and coming languages, such as Swift. I expect that to inch into the top 10 in the next few years.

If you want to focus on learning a programming language, and you have no other criteria, pick something from this list.

How to learn Python: fast, slow and somewhere in between

As one of my areas of skill development this year, I am teaching myself Python (the programming language). I had a number of different sites offering help with it, but I have found these three the most useful, so far. I have found each of them useful, but I have spent the most time on “medium”. If you are interested in learning Python, I recommend you check these out:

Fast: Tutorial – Learn Python in 10 minutes – Stavros’ Stuff. Great as a cheatsheet or a quick intro to Python or if you used to do work with Python but haven’t done it in awhile.

Medium:the Python Tutorial from python.org. If you know other programming languages, this is a good starting point.

Slow: Learn Python the Hard Way. Good if you don’t know much about programming and want to make Python the first language you know really well.

Are you trying to learn to code? Are you finding it difficult?

It’s likely not you. As this piece argues, Learnable Programming, there are limits to the approaches that online sites have which many can get by, but some cannot. If you are in the latter group, give this piece a read. Afterwards you might think: aha! That’s why I couldn’t get it!

With technology, if you don’t understand something, don’t assume the problem lies with you. It may, but most of the time, the problem lies with the technology.

A return to Twitter (not the service, but the community)

After the frustration with the Twitter service for changes like this, I thought I would give up Twitter. However, Twitter is the sum of a number of parts: there is the service that Twitter provides, from the backend servers to the APIs to the user interfaces and client software you use;  and then there are the people that contribute to Twitter. Among those contributors are people I really enjoy socializing with whom I cannot connect with any other way. To give up all of Twitter means tossing out the baby, the bathwater and even the tub itself. That’s dumb. (I do dumb things often, but typically correct most of them in time. :))

To get around that, I decided to use my limited software skills and the APIs that Twitter provides to write my own Twitter client, in a way. It is a hack, but it is a good hack (for me). I am able to control what I see this way. Not only do I not have promoted tweets, etc., in my feed, but I am able to get rid of things like RTs from everyone, rather than having to turn of RTs one at a time. I’m also able to save all the tweets in a spreadsheet or some other format, so I can look at them when I am less busy, or decide on other filters I want to apply, etc. Later on I can write more filters so if a trending topic gets to be too much, I can just delete it or save it to a different file for later.

Now my Twitter experience is gone from poor to great (for me).  I have thrown out the dirty bath water, but kept the tub and the baby. This makes more sense, obviously.

Last but not least, I appreciate all the people who expressed concern over my leaving Twitter. It was very kind of you, and why I want to stick around, if I can.