- Web development stinks
- I don't want to program in 5 languages to serve a webpage
- I wrote the webgear package so I can just program in Go with Web Components
- This package powers Golang Basics
Hey, if you don't want to listen to my meandering (and I can meander with the best of them), just skip towards the bottom.
Does anyone like HTML for Apps?
Well, probably, but then they've probably never had the experience of using anything better. Or are masocists. Maybe both?
Many programmers today have grown up in the web era and people get used to whatever it is around you, no matter how bad it is.
HTML was great for what it was designed for: make research papers link to each other.
It's not so good at making Apps. The foundation is bad. Can you do it, sure...
Google/Microsoft/Facebook have spent billions making apps that are semi-functional. Semi-functional because they are never as good as desktop apps. Not in response time, amount of code, performance, memory consumption (have you seen how much RAM your browser uses!!!). But they run everywhere and are connected to the most powerful compute resources in the world. However, most web apps written by a dozen people could be beat in performance by a single developer on a Mac IIci from the 80s.
Instagram has thousands of employees to make an online version of a super simplistic desktop app somewhat equivalent to photoshop in 1990. Even they use native interfaces on platforms such as Android/IOS, it's so much easier and responsive (though maybe today they are all on React Native??).
We now have websites that build websites like squarespace/wix because its so hard to get right (and responsive). I've tried using these for my most simple sites and am always disappointed with the results in the long term. And they can only do this for the simplest of pages, not really worthy of the "web app" moniker.
So everyone tries to find some framework that gets in the way the least and has decent performance (React/Angular/...).
A couple of years ago I was creating a web site that delivers videos from Vimeo with notes on teaching Go Basics (plug: www.golangbasics.com).
I wrote that site in Go, cause you know.....
This required I write HTML. But you can't just write HTML, oh no......
Oh and I would like it to look decent, so now I've got to do CSS.
I think that means that I now need 5 languages to render a page.
Ok, done with that nonsense....
I decided for the future, I never wanted to do that again and this would be the first site I re-wrote.
I don't want to write in more than 1 language and that language I want to be Go. Go templates don't count as being part of Go for this conversation.
- Write in one language
- Have web components so that CSS stuff won't interfere with other code
- Reusable parts
- Avoid name collisions that components are prone to
- Can reproduce the site I've already written
I believe I have succeeded in everything but the one language, I'm still going to style with CSS.
The webgear package has several major parts:
- html/ Defines HTML doc, html elements and the dynamic element for generating HTML from Go.
- html/builder/ Defines a package for building HTML code more dynamically.
- components/ Defines encapsulated Web Components written in Go.
- handlers/ Defines simple wrappers around http.Server/Mux to serve your content.
- wasm/ Defines a Web Assembly package that is still experimental
What does this thing buy me
- Only use two languages: Go and CSS (maybe sprinkle some basic JS)
- Encapsulate each part of a page as a reusable component
- Launch the site quickly with the handlers package
- Have separate tests and a visual viewer test just for components, separate from the page
- Some static type checking, so you can only add form elements to forms
- Everything isn't stringly typed
- You can't accidentally misspell an attribute
- You can't forget closing tags
- Some more validation checks
- Getting the WASM code to higher quality
- Adding more tags, as I haven't added all tags or event types
Why are you letting CSS get away
When you change the html you have to reload your server. Now, that isn't too tedious if you are keeping your style away from your layout. So I consider that very low cost.
What isn't low cost is reloads while you are styling your CSS. You have to do that a lot. So by keeping the styles in external style sheets and providing a simple way to tell it to reload CSS when doing dev from external style sheets, you get a good mix.
HTML already has a dizzying amount of tags I have to recreate, not even looking at CSS and how I would deal with dynamic changes. I got a day job and carpal tunnel already.
Enough talk, show me the goods!
You can read all about Webgear with sample code here
You can view the Golang Basics site code here
You can checkout the future wasm package here