CS245
Baby names in Go
In this assignment you will reproduce, the program you just wrote in Kotlin. But this time in Go. (See hw4 for a problem specification, if you need it.) Yes, this feels boring and repetitive. But given that you already understand the problem, getting started on the Go version should be much easier.
When you have finished your Go program write at least one page (and no more than 3) on the relative merits of your Kotlin and Go programs. Feel free to discuss almost anything. Some possible topics:
- Readability of the code
- Writability of the code
- Changability of the code
- Runtime complexity -- for the data given, this is a minor issue. Suppose you had the top 10,000,000 names for the past 100 years, worldwide.
- How much you hate VSC for developing in Java/Go/Kotlin (and why, be specific)
- How much you hate Kotlin/Go (and why ... be specific)
You should come up with at least one topic that is not included in the above list.
Reading CSV data from a URL in Go
To help you get started with the task here is a
complete Go program that reads CSV data and does a little bit with it. Feel free to use, or ignore, this program. The program is not commented intentionally; figure it out.
package main
import (
"encoding/csv"
"fmt"
"io"
"net/http"
"os"
"strconv"
"strings"
)
func readHurricane(url string, maxLines int) {
resp, err := http.Get(url)
if err != nil {
fmt.Println("Http problem", err)
return
}
body, err := io.ReadAll(resp.Body)
resp.Body.Close()
if err != nil {
fmt.Println("Http problem2", err)
return
}
str := string(body)
r := csv.NewReader(strings.NewReader(str))
r.FieldsPerRecord = -1
obsCount := -1
aCount := 0
for i := 0; i < maxLines || maxLines <= 0; i++ {
record, err := r.Read()
if err == io.EOF {
break
}
if err != nil {
fmt.Fprintf(os.Stderr, "%v\n", err)
break
}
if len(record) < 5 {
fmt.Printf("NAME: %v\n", record)
obsCount, err = strconv.Atoi(strings.TrimSpace(record[2]))
if err != nil {
fmt.Fprintf(os.Stdout, "CONV PROB [[%v]] %v\n", record[2], err)
}
aCount = 0
} else {
aCount++
fmt.Printf("OBSE %d %d: %v\n", obsCount, aCount, record)
}
}
return
}
func main() {
readHurricane("http://cs.brynmawr.edu/~gtowell/Data/hurdat2-1851-2019-052520.txt", 100)
}
In this code, please note the line strconv.Atoi(strings.TrimSpace(record[2])) Before converting from string to integer, be sure to strip off leading and trailing spaces. (This may not be important for the baby name data as I do not think it has many, if any, spaces.)
Grading
The Go program will be worth 75% of the credit for this assignment, the essay 25%.
What to hand in
- All Go code
- The usual README
- A script file swhoing the output of your go program on the following names: Aaron, Devon,marlen,syd
- Your opinion piece on the relative merits of Go and Kotlin. I would prefer this in .txt format (like the readme). I will also accept pdf. I may read other formats, but I will not be happy. Do not give me a link for a file stored elsewhere
Electronic Submissions
Your submission will be handed in using the submit script.
If you write your program on computers other than those in the lab, be aware that your program will be
graded based on how it runs on the
department’s Linux server, not how it runs on your computer. The most likely problem is not
submitting everything or hard coding file locations that are not correct on the Linux servers.
The submission should include the following items:
- README:
- This file should follow the format of this sample README
-
- Source files
- All of them (you might have only one)
- Data files used:
- Be sure to include any non-standard data files uses. You should not have any.
- Script file
- Include with your submission the output from your program on the following names: aa, Dev, sy, michelle
-
DO NOT INCLUDE:
- Data files that are read from the class site.
Again: Once you have everything you want to submit in the a5 directory within /home/YOU/cs245/
- Go to the directory /home/YOU/cs245
- Enter /home/gtowell/bin/submit -c 245 -p 5 -d a5
If this worked you will get a message with the word "success". If you cannot achieve success and the deadline is
approaching, send me email. We can set up a meeting to work out your problems. The email will establish that you
intended to submit. Once you send the email, do not change the files that you were trying to submit.