Wednesday, January 31, 2024

Programming Paradigms

I thought I had a handle on the programming paradigms such as imperative programming, procedural programming, structured programming, object oriented programming, etc. I thought they were categories of coding style made possible with a language’s feature-set. For example, RPG 4 and Pascal allow for passing arguments to procedures while COBOL and RPG 3 do not. That difference made me think that RPG 3 and COBOL fall into the imperative programming paradigm and Pascal and RPG 4 are in the procedural programming paradigm. ChatGPT convinced me that I’m totally wrong. After a hundred ChatGPT queries, I know what ChatGPT thinks and I’m not happy with it.

ChatGPT tells me that procedural programming paradigm is totally encompassed by the imperative programming paradigm. I can see why this is true, because if/then/else falls into the imperative paradigm so every language that has if/then/else is imperative. However, having languages fall into a trail of paradigms where each newer paradigm can be a subset of its parent makes language categorization by paradigms rather useless.

ChatGPT’s answers led me back in time to the 1969 paper by Edsger Dijkstra, “GOTO Statement Considered Harmful” and to 1973’s "Global Variable Considered Harmful” by Wulf and Shaw. GOTO considered harmful appeared to me to have been the justification for the adoption of languages that have subroutines like COBOL and RPG 3. Global Variable considered Harmful appeared to me to have been the justification for the adoption of C and later, RPG 4, and languages which allow variables to be declared that are scoped only to methods. No, that would be too easy. There was further disappointment when ChatGPT identified a category error in my assumptions about programming paradigms, Structured Programming is not a paradigm. ChatGPT tells me that Structured Programming is a broader category. The first six words in the wikipedia article on structured programming are, "Structured programming is a programming paradigm” but, wikipedia doesn’t provide evidence and it hardly mentions structured programming in the article on programming paradigms.

The disappointment I found in programming paradigms is that the overlapping of paradigm definitions mean that COBOL and C are both classified as procedural and iterative. If a language with lexical scope and procedures that accept arguments falls into the same paradigm as a language that lacks those features then paradigms are useless, they are distinctions without differences.

Monday, June 20, 2022

JavaFX Book Review

Learn JavaFX 17 is a good book with good examples but JavaFX has some unique features that can be issues in your use the platform.

Note that JavaFX 17 requires purchase of a license. There is no free developer version of JavaFX 17. A free developer version of JavaFX 18 is available and that is what I am using and I have not found any code from the book that dows not work in JavaFX 18 but I have only run a few examples so far.

JavaFX 17 lacks free developer versions because the JavaFX project isn't run like a Free Open Source project. JavaFX is not like Apache open source. It is not like Google open source. It is not like Microsoft open source.

JavaFX was an Oracle project for many years and therefore, closely tied to use of the NetBeans IDE. This is no longer the case and the book Learn JavaFX 17 presents examples using the Eclipse IDE. I did try Netbeans on both Windows and Mac and the IDE failed to recognize the Java JDK and thus I could not compile or run programs. The best experience I got from an IDE was from the community edition of IntelliJ IDEA. On both Windows and Mac, I had an example JavaFX app within two minutes of installing the IDE.

Monday, January 3, 2022

Algorithmic Thinking Snowflake Problem

The challenge in this problem is to identify identical snowflakes even when the data about the snowflakes are stored in the same sequence but in a different orientation. In this problem, snowflakes have six arms of lengths varying from 1 to 6. The snowflakes are randomly generated so one snowflake may have arms represented by [1, 2, 3, 4, 5, 6] and an identical snowflake have arms of [3, 4, 5, 6, 1, 2]. These are a match. These snowflakes are identical but were generated with different orientations. A snowflake with arms of [2, 1, 3, 4, 5, 6] is not a match because its arms, even though of the same lengths, do not occur in a sequence that can be made to match the first two.

In the function makeSnowflakes() my solution generates 2000 snowflakes as the problem set. Then in searchArrayForMatches() and identifyIdentical() the program compares each arm of each snowflake to the arms of every other snowflake.

I wrote and tested this in Xcode, the Mac IDE.

Caveat: I've coded very little C and it probably shows.

Program Output

. . .
match 1749 1824 
3 2 6 5 5 3 
5 3 3 2 6 5
match 1759 1859 
3 3 6 6 5 1 
3 6 6 5 1 3
match 1776 1900 
4 4 5 2 4 5 
2 4 5 4 4 5
match 1860 1905 
6 5 2 3 4 6 
6 5 2 3 4 6
match 1915 1977 
3 1 1 1 5 4 
1 1 1 5 4 3
match 1998 1999 
1 6 3 2 6 1 
6 1 1 6 3 2
Number Matched 244
Program ended with exit code: 0

Friday, June 18, 2021

Creating and Populating a Database With Apache ANT

I recreated a very useful ANT script I originally created 15 or 16 years ago. The ANT script containing the database creation commands can be versioned making sharing, reuse and modification simple and easy.

Preliminary Setup

1.) install Apache ANT
   a.) download the zip file
   b.) open the zip and copy the contents to the clipboard
   c.) paste the content of the clipboard in a folder
   d.) create an ANT_HOME environment variable and give it the value of the path of the location of the ANT files
   e.) edit the PATH environment variable and add ANT_HOME to it
2.) download the H2 DBMS jar file and place it in the lib folder
3.) write the sql tasks in the ANT build.xml file.

Here is the build.xml file that contains the SQL commands that ANT will run:


C:\Users\javap\dev\src\java\h2Db>ant -v sqlcreate
Apache Ant(TM) version 1.10.10 compiled on April 12 2021
Trying the default build file: build.xml
Buildfile: C:\Users\javap\dev\src\java\h2Db\build.xml
Detected Java version: 11 in: C:\Program Files\Java\jdk-11.0.1
Detected OS: Windows 10
parsing buildfile C:\Users\javap\dev\src\java\h2Db\build.xml with URI = file:/C:/Users/javap/dev/src/java/h2Db/build.xml
Project base dir set to: C:\Users\javap\dev\src\java\h2Db
parsing buildfile jar:file:/C:/Users/javap/dev/bin/apache-ant/lib/ant.jar!/org/apache/tools/ant/antlib.xml with URI = 
jar:file:/C:/Users/javap/dev
/bin/apache-ant/lib/ant.jar!/org/apache/tools/ant/antlib.xml from a zip file
Build sequence for target(s) `sqlcreate' is [sqlcreate]
Complete build sequence is [sqlcreate, sqlpopulate, echo, sqlschema, sqldrop, sqlselect, ]

sqlcreate:
      [sql] connecting to jdbc:h2:~/h2db
      [sql] Loading org.h2.Driver using AntClassLoader with classpath C:\users\javap\dev\lib\h2-1.4.200.jar
      [sql] Executing commands
      [sql] SQL:  create table Project (ID INT AUTO_INCREMENT, name varchar(30))
      [sql] 0 rows affected
      [sql] 0 rows affected
      [sql] SQL:  create index Project_idx on Project (name)
      [sql] 0 rows affected
      [sql] 0 rows affected
      [sql] SQL:  create table Programmer (ID INT AUTO_INCREMENT, full_name varchar(100))
      [sql] 0 rows affected
      [sql] 0 rows affected
      [sql] SQL:  create index Programmer_idx on Programmer (full_name)
      [sql] 0 rows affected
      [sql] 0 rows affected
      [sql] SQL:  create table ProjectProgrammer (project_id INTEGER, programmer_id INTEGER)
      [sql] 0 rows affected
      [sql] 0 rows affected
      [sql] SQL:  create view ProjProg as select Project.name, Programmer.full_name from Programmer 
      join ProjectProgrammer on Programmer.id = ProjectProgrammer.programmer_id 
      join Project on ProjectProgrammer.project_id = Project.id
      [sql] 0 rows affected
      [sql] 0 rows affected
      [sql] Committing transaction
      [sql] 6 of 6 SQL statements executed successfully

BUILD SUCCESSFUL
Total time: 0 seconds

C:\Users\javap\dev\src\java\h2Db>ant -v sqlpopulate
Apache Ant(TM) version 1.10.10 compiled on April 12 2021
Trying the default build file: build.xml
Buildfile: C:\Users\javap\dev\src\java\h2Db\build.xml
Detected Java version: 11 in: C:\Program Files\Java\jdk-11.0.1
Detected OS: Windows 10
parsing buildfile C:\Users\javap\dev\src\java\h2Db\build.xml with URI = file:/C:/Users/javap/dev/src/java/h2Db/build.xml
Project base dir set to: C:\Users\javap\dev\src\java\h2Db
parsing buildfile jar:file:/C:/Users/javap/dev/bin/apache-ant/lib/ant.jar!/org/apache/tools/ant/antlib.xml with 
URI = jar:file:/C:/Users/javap/dev
/bin/apache-ant/lib/ant.jar!/org/apache/tools/ant/antlib.xml from a zip file
Build sequence for target(s) `sqlpopulate' is [sqlpopulate]
Complete build sequence is [sqlpopulate, sqlcreate, echo, sqlschema, sqldrop, sqlselect, ]

sqlpopulate:
      [sql] connecting to jdbc:h2:~/h2db
      [sql] Loading org.h2.Driver using AntClassLoader with classpath C:\users\javap\dev\lib\h2-1.4.200.jar
      [sql] Executing commands
      [sql] SQL:  insert into Programmer (full_name) values('Greg Helton')
      [sql] 1 rows affected
      [sql] 1 rows affected
      [sql] SQL:  insert into Programmer (full_name) values('Bill Gates')
      [sql] 1 rows affected
      [sql] 1 rows affected
      [sql] SQL:  insert into Programmer (full_name) values('Steve Jobs')
      [sql] 1 rows affected
      [sql] 1 rows affected
      [sql] SQL:  insert into Project (name) values('Workplace assignments')
      [sql] 1 rows affected
      [sql] 1 rows affected
      [sql] SQL:  insert into ProjectProgrammer values(1,1)
      [sql] 1 rows affected
      [sql] 1 rows affected
      [sql] SQL:  insert into ProjectProgrammer values(1,2)
      [sql] 1 rows affected
      [sql] 1 rows affected
      [sql] SQL:  insert into ProjectProgrammer values(1,3)
      [sql] 1 rows affected
      [sql] 1 rows affected
      [sql] Committing transaction
      [sql] 7 of 7 SQL statements executed successfully

BUILD SUCCESSFUL
Total time: 0 seconds

C:\Users\javap\dev\src\java\h2Db>ant -v sqlselect
Apache Ant(TM) version 1.10.10 compiled on April 12 2021
Trying the default build file: build.xml
Buildfile: C:\Users\javap\dev\src\java\h2Db\build.xml
Detected Java version: 11 in: C:\Program Files\Java\jdk-11.0.1
Detected OS: Windows 10
parsing buildfile C:\Users\javap\dev\src\java\h2Db\build.xml with URI = file:/C:/Users/javap/dev/src/java/h2Db/build.xml
Project base dir set to: C:\Users\javap\dev\src\java\h2Db
parsing buildfile jar:file:/C:/Users/javap/dev/bin/apache-ant/lib/ant.jar!/org/apache/tools/ant/antlib.xml with 
URI = jar:file:/C:/Users/javap/dev
/bin/apache-ant/lib/ant.jar!/org/apache/tools/ant/antlib.xml from a zip file
Build sequence for target(s) `sqlselect' is [sqlselect]
Complete build sequence is [sqlselect, sqlpopulate, sqlcreate, echo, sqlschema, sqldrop, ]

sqlselect:
      [sql] connecting to jdbc:h2:~/h2db
      [sql] Loading org.h2.Driver using AntClassLoader with classpath C:\users\javap\dev\lib\h2-1.4.200.jar
      [sql] Executing commands
      [sql] SQL:  select * from Project
      [sql] Processing new result set.
      [sql] ID,NAME
      [sql] 1,Workplace assignments
      [sql]
      [sql] 0 rows affected
      [sql] 0 rows affected
      [sql] SQL:   select * from Programmer
      [sql] Processing new result set.
      [sql] ID,FULL_NAME
      [sql] 1,Greg Helton
      [sql] 2,Bill Gates
      [sql] 3,Steve Jobs
      [sql]
      [sql] 0 rows affected
      [sql] 0 rows affected
      [sql] SQL:   select * from Programmer join ProjectProgrammer on Programmer.id = ProjectProgrammer.programmer_id 
      join Project on ProjectProgrammer.project_id = Project.id
      [sql] Processing new result set.
      [sql] ID,FULL_NAME,PROJECT_ID,PROGRAMMER_ID,ID,NAME
      [sql] 1,Greg Helton,1,1,1,Workplace assignments
      [sql] 2,Bill Gates,1,2,1,Workplace assignments
      [sql] 3,Steve Jobs,1,3,1,Workplace assignments
      [sql]
      [sql] 0 rows affected
      [sql] 0 rows affected
      [sql] SQL:   select * from ProjProg
      [sql] Processing new result set.
      [sql] NAME,FULL_NAME
      [sql] Workplace assignments,Greg Helton
      [sql] Workplace assignments,Bill Gates
      [sql] Workplace assignments,Steve Jobs
      [sql]
      [sql] 0 rows affected
      [sql] 0 rows affected
      [sql] Committing transaction
      [sql] 4 of 4 SQL statements executed successfully

BUILD SUCCESSFUL
Total time: 0 seconds

C:\Users\javap\dev\src\java\h2Db>

Wednesday, November 25, 2020

Is It Digits?

Does a String value consist only of digits?
if (mystr.chars().allMatch(Character::isDigit)) {
  System.out.println("all digits");
}

Tuesday, August 25, 2020

Iterative Test Driven Development circa 1968

A crisis in software engineering came about in the late 1960s from the marketing of a computer that was much cheaper to own and operate, the IBM 360 family of computers. Fred Brooks managed the development of OS/360 and Gene Amdahl was the architect. These computers allowed software to run on a range of computers which meant that the cost of development could be absorbed across many systems and many years. The software industry saw the opportunity to develop new systems but there was an insufficent number of experienced developers available to develop the software. Larger projects also required more intensive levels of management.

The 1968 NATO Software Engineering Conference was held three years after delivery of IBM's OS/360 that initiated recognition of a crisis in the realms of planning, scheduling and completing software. Brooks best illustrates the problem of scheduling by identifying "the mythical man-month" and illustrating it with a quote from another computer scientist: "while it takes one woman nine months to make one baby, nine women can't make a baby in one month".

At the 1968-69 NATO Software Engineering Conference an oddly familiar methodology was discussed:



SDLC and the waterfall methodolgy appear to be the worst possible way of addressing the the problem of scheduling a project and completing it successfully but, SDLC was adopted because it was the most easily communicated. The 'engineering' part of 'software engineering' became conflated with SDLC.

Friday, August 14, 2020

JUnit & DOS

When I tried coding this in VS Code, the plug-in did not recognize the system JDK so I reverted to DOS just because.