[uberconf 2023] go(lang) for java developers workshop

Speaker: Ken Sipe

For more, see the table of contents

@kensipe


General

  • Normally this is a workshop. Today’s session is abridged
  • Lots in lab that aren’t in the slides/presentation
  • Labs: https://github.com/kensipe/go-labs
  • Solutions: https://github.com/codementor/wman

Go

  • Go Lang only for search. Call it Go in talking
  • Google made Go in 2009 and started using in 2010
  • Killer app – advanced cloud/k8s
  • 1.0 released in 2012
  • Release every six months
  • Can run online – https://go.dev/tour/welcome/1
  • VSCode has good plugin. IntelliJ makes a Go IDE – GoLand. IntelliJ plugin for Go not same as GoLand

Value proposition

  • Ease to use – productivity
  • Efficient execution
  • Type safe
  • Latency free garbage collection
  • Fast compilation
  • Native binary, but run on multiple platforms

More about Go

  • Some inspiration from C but not derived from c family
  • Language simplicity – no inheritance/generics/assertions/method overload/classes
  • Implement interface
  • Inference assignment
  • Have structs, but not OO

Syntax

  • format is defined. {} must be positioned right. { must be on same line as predecessor
  • No semicolons

Differences from Java

  • No classes
  • Main doesn’t have ceremony – func main
  • In Java, the project contains the src tree. In Go, you clone the whole project into your src tree (GOPATH). In later versions of Go, can scatter if want.
  • Functions in files – less of a conventions
  • return used a lot more than in Java – want to fail fast/get out of method as quickly as possible
  • Naming controls behavior. name is private; Name is public

Go commands and files

  • go mod init – creates a go project in the current directory (assuming in GOPATH)
  • go mod init github.com/user/proj – creates a new go module
  • Creates go.mod file listing version number by default
  • go.mod lists required dependencies once add them
  • go.sum – checksum for dependencies
  • go doc – command line help. ex: go doc fmt or go doc.fmt.Println
  • many linters as options
  • go mod verify – checks checksums
  • go mod tidy – remove any unused dependencies

Hello World

package main

import "fmt"

func main() {
	fmt.Println("Hello World")
}

Packages

  • Can import one at a time or a list – like namespaces
  • Built in packages: https://pkg.go.dev/std
  • Reusable packages: http://awesome-go.com
  • Ken makes three sections; by likelihood of changing dependencies listed later and alphabetized by group. GoLand handles this ordering.
import "fmt"
import "net/http"

vs

import (
  "fmt"
  "net/http"
)

Types

  • bool
  • string
  • int, int8, int16, int32, int64
  • uint, unit8, uint16, uint32, uint64, uintptr
  • byte (alias for uint8)
  • rune (alias for int32)
  • float32, float64
  • complex64, complex128
  • Array
  • Slice – initially, think of as a way of getting to an array. Can pass part of an array via a slice. Window view onto array.
  • Struct – create own structure
  • Pointer
  • Function
  • Interface
  • Map
  • Channel – stream of things, can be bounded or unbounded, can add events to channel
  • if just use “int”, get default for your platform
  • defining size matters for certain apps

Variables

  • var name string
  • name = “value”
  • var a, b, c int
  • var name = “hello”
  • var a, b, c = 1, 2, 3
  • var a, b = 1, true – don’t mix types on one line
  • Common to have terse variable names when very small scope
  • Leave out time if can be inferred
  • message := “hello” – most common way for creating a variable, can shadow variable if exists in different scope
  • a, b, c := 1, 2, 3
  • x, y := FunctionReturningTwoThings()
  • Will not compile if define variable that is not used
  • _, y := FunctionReturningTwoThingsWhereDoNotCareAboutFirstOne()

Pass by reference

  • Pass by value by default. If want pass by reference, need to pass a pointer
  • foo(&a) – to pass pointer
  • fun foo(count *int) – takes pointer
  • *count – use thing pointer preferences (ex: int)
  • count – gives you actual pointer
  • Strongly typed – can’t pass nil if has a declared return type. Can if pointer

User Defined types

  • type MyType string – alias to an existing type. Can add functions to your type.
type MyType struct {
  name string
  value string
}

var mine = MyType { "n", "v" }
var longer = MyType { name: "n", value: "v" }
var evenLonger = MyType{}
eventLonger.name = "n"
fmt.Println(mine.name)
  • When use longer format to create, order doesn’t matter when passing in values and can leave some out.

Const

const (
 PI = 3.4
 other1 = iota
 other2 = iota
)

iota is successive integers where don’t care about the numbers

Map

myMap := map[string]int {
  "n": 4,
}

myMap["n"]

Last comma needed to compile. This avoids changing lines in version control that weren’t affected by the change.

Function

  • os.Args – to get args passed to main
  • fmt.Println(a, b, c)
  • fun Mine(type string) string – return one string
  • fun Mine(type string) (string, string) – return two strings
  • return “a”, “b” – return two things
  • fun Mine(name … string) – takes a slice of strings; can call like varargs in Java

Can use variables for return. If don’t set all return values, “return” will fail. (Ok to use nil)

func Mine() (x string, y string) {
  x = "x"
  y = "y"
  return

Methods

  • Function only accessible on a type
func (x MyType) MethodName() {
}
var m = MyType{}
m.MethodName()

Interfaces

  • uses duck typing – if method has signature of interface, it is that interface
  • interface{} – no functions so everything implements

My take

Good intro. I was puzzled at the beginning about scope. I thought it was a talk but he said workshop. Then the instructions about creating a key were there. Then it was a talk. Which is what I was expecting. It would have been clearer to not include “workshop” in the title slide to match both the abstract and session. Avoids that confusion. I do like the lab was available for “later”. The references to “we will cover that later” with 20 minutes left felt like false promises.

The actual material and flow was great. I learned a lot and the callouts for what is different in Java was helpful. The examples were good for learning. I’m happy with the session and glad I attended. I just wish it was designed to be a 90 minute presentation with “see here for full” rather than trying to shoehorn something clearly much longer into 90 minutes.

He went a little over. I stopped blogging at the official end time because the rest was flying through a lot of the remaining slides too fast to follow, let alone understand/type.

[uberconf 2023] making sense of other people’s code

Speaker: Scott Wierschem

@scott_wierschem

For more, see the table of contents


General

  • “I’m not a great programmer.. I’m a good programmer with great habits” – Kent Beck
  • 90% of time reading code (vs writing) – Robert C Martin from Clean Code
  • 58% time understanding code – IEEE
  • Content vs intent

Reading Prose vs Code

  • Prose is passive, remember general details, constant forward flow, relaxing and enjoyable
  • Code is active reading, understand everything in detail, loops/jumps/subroutines/async, exhausting hard word

Why code hard to read

  • Variable names
  • Long methods
  • Variable state
  • Complicated control flow
  • Long files
  • Someone else wrote it
  • I wrote it, bus must have been drunk
  • No docs or old/wrong docs
  • Not following code standards
  • Magic numbers
  • Reused variables (ex: second purpose in method)
  • Global variables/singletons
  • Bad naming
  • Magical annotations
  • Using new feature in language before understanding where fits

Why read code?

  • Learn how it works to enhance or fix
  • Learn how library/framework works
  • Learn different programming techniques – learn from other people
  • Code review – paid to read it

Learning

  • Book recommendation: The Programmer’s Brain
  • FIlter info and put in short term memory – 3-5 items; only lasts about 30 seconds
  • Associated info with something and then in long term memory
  • Load from short and long term memory into working memory
  • Working memory typically 2-4 items

Confusion when reading code

  • Lack of knowledge – ex: APL (a programming language) – Greek symbols
  • Lack of information – ex: not knowing what a lambda does
  • Lack of processing power – ex: too much complexity

Example

  • Flashed characters for a second or two.
  • Cyrlic. Remembered one character
  • Random letters. Remembered three characters. Characters in long term memory.
  • Three words. Remembered all three. Words in long term memory. Chunking – grouping together familiar patterns.

Iconic memory

  • Persistence of vision
  • Look at shape of code ex: of statement
  • Can see indents even in minimap where code is tiny (CodeGlance Pro plugin for IntelliJ; Eclipse/VS Code have setting)

Other guides/tools

  • Design patterns for chunking
  • Comments – new people rely on a lot more. Experienced people burned by docs and learn to remove.
  • Print code and write on it as external aid
  • Create dependency graph – print out/highlight or use a tool – https://annotate.codereading.club/
  • Use a state table – write down values of variables as go thru code/loops

Beacons

  • Simple Beacon – good variable name
  • Compound Beacon – combinations
  • Help future readers of code
  • Intentionally included to make easier to read/understand
  • Whitespaced for sections of code
  • Eye drawn automatically to bits of code

Remembering stuff

  • Faster to make associations when know more
  • Faster to learn
  • Break flow to google.
  • Takes average 15 minutes to get back to where you were
  • Remember through repetition; memory decays. The decay is slower over time. This is why spaced repetition works. ankiapp.com, cerego.com, quizlet.com)
  • Long term memory is good. Retrieval doesn’t always work. Practice helps. Try to guess before look it up.

Cognitive Load

  • Intrinsic – complexity of problem
  • Extraneous – outside distractions
  • Germane – storing thought in long term memory
  • Reduce load by refactoring – break it up, remove duplication, simplify, sometimes unroll function call, avoid unfamiliar language constructs (ex: ternary operator)
  • Can have IDE refactor for you without understanding first
  • Add confusing constructs to flash cards so can make association faster next time

Similarities

  • Write down what concept makes you think of; what is related
  • For each concept, think about why related. ex: syntax, context
  • What other ways can accomplish same goal? ex: other programming languages
  • Does it fit a paradigm, domain, library, framework, etc

Tools

  • IDE plugins – syntax coloring, indentation lines, plugins. Know your IDE; know the features
  • Paper and pen – colored pens/pencils, highlighters
  • Debugger – conditional breakpoints [these are great]
  • Profiler – call stacks
  • Log files

My take

I’m a morning person, so I wasn’t sure how live blogging at a talk at 8:30pm would go. It was right after dinner though so that helped me stay alert. It helped that he had a lot of interactivity. I still had trouble concentrating as much as I could earlier in the day though so I’m sure I retained less. Good thing I have this blog post. I will say brain being worn out was very reinforcing when finding code with higher cognitive load!

[uberconf 2023] Practical AI Tools for Java Developers

Speaker: Ken Kousen

@kenkousen

For more, see the table of contents


Prompt Engineering

  • Tools are improving fast, might not be needed as job
  • Suggest context (ex: “pretend you are”)
  • Give example of what you want

Chat GPT

  • Free version is GPT 3.5 Turbo (improved performance over original 3.5)
  • $20/month for GPT 4. Can make 25 requests in a three hour block.
  • Have not noticed quality control over plugins.
  • Plugins change rapidly.
  • Apologizes when you correct it.
  • Warning about pasting your company’s code in
  • Trained thru summer 2021
  • Can’t read files on local file system (Bard can). Can read link but doesn’t know it can
  • Often wrong if you ask it about whether can do something. Like talking to toddler; says want thinks want to know.
  • Temperature – tweaks creativity vs precision
  • REST API docs
  • REST API: cookbook has examples
  • Must give credit card to call REST APIs. Pennies are for 1000 tokens (about 750 words). Charged for both input and output words. Also limits on context (amount GPT remembers). Not expensive if don’t use it much. Ken’s bill has been pennies and too low to be sent a bill.
  • REST API JSON response says how many tokens used. Can also see graph when log into account
  • Had it make multiple choice questions on a topic

Chat GPT Code Interpreter

  • Code Interpreter beta feature.
  • Need to explicitly enable under settings.
  • From OpenAI, not third party
  • ex: can convert Groovy to Kotlin DSL for Gradle

DALL-E

  • First popular text to image generation tool
  • A generation behind text/GPT.
  • Stable Diffusion free, but behind on quality
  • Prefers MidJourney, more realistic

Whisper

  • Audio to text
  • Takes audio or video and writes transcription.
  • Free (unless use REST API)
  • Mac Whisper – $20 on time fee for larger models. Good for transcribing videos of talks. Slow first time. After that (including other videos, fast. [caching?]
  • Creates .srt file (Subtitles)

Claude.AI

  • Free beta
  • Only available in US and UK
  • Can hold 100K tokens. ex: can summarize a novel
  • Quality comparable to ChatGPT 3.5, but not as good as 4.0
  • Can upload many file types
  • Harder to get back to previous conversations than ChatGPT. Need to click on “A” icon on top to see them
  • Doesn’t do image

Bard

  • Can upload answers to Google docs on Ken’s personal account, but not business account
  • Used to be able to answer who Venkat is but can’t anymore.

Llama 2

  • Meta announced today
  • Pretrained language model
  • Free unless large company (aka: competitors)

Descript

  • Transcribes and edits video
  • Can give instructions – ex: shorten gaps in video, remove filler words
  • If don’t move around much, will make it look like you are looking at camera
  • Can give text and select a voice. With 30 minute sample, can train on your voice

Canva

  • Can describe presentation want and Canva makes a draft
  • Can choose theme from list of choices
  • Magic eraser – brush over part of image don’t want and replaces with background nearby
  • Beats Sync – line of slide transition to beats of music
  • Magic Write – like GPT 3.5
  • Magic Design – give own image and make presentation around that

GitHub Copilot

  • Virtual pair programmer
  • Plugins for VSCode and IntelliJ
  • If hesitate, suggests code
  • Can’t agree to part of suggestion. Need to accept it all or delete
  • Guesses right a lot because knows what have done before in a training class
  • Always looks plausible because trained on own code. Need to look carefully
  • Next generation is GitHub CopilotX. Only available via wait list. VS Code only at this point, can use for pull requests.
  • GitHub Next – tools in a variety of states – https://githubnext.com. “Visualizing a Codebase” runs as github action to see packages

IntelliJ AI Assistant

  • Not much documentation on how it works. Only one blog post
  • In Ultimate, not Community
  • In beta edition
  • Can highlight code and ask to explain it
  • If don’t like suggestion, can request it suggests something else and get more choices
  • Can write commit message for you
  • Find issues with code when know language well
  • Helps in language know less well because it knows the API/syntax
  • Good for nuisance tasks that would take a lot of time

YouTube Summary

  • Get summary or transcript of video
  • Free
  • Up to 20 minute video

My take

I was doing my interview with the Build Propulsion Lab so was a few minutes late. It was a full room so my seat was on the floor. Luckily, the room had a large aisle so I could sit near the front instead of in the very back! And the carpet was comfy.

As far as Ken’s actual talk, it was great. I liked the overview of a bunch of tools and seeing the REST APIs for calling OpenAI. Great breath of topics and fun examples! I learned a lot including some tools I hadn’t heard of. And some very cool functionality!