Skip to content

Commit

Permalink
fast first draft on the blog content
Browse files Browse the repository at this point in the history
  • Loading branch information
rcoreilly committed Jul 14, 2024
1 parent dc4ef97 commit b9a42ba
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 4 deletions.
142 changes: 141 additions & 1 deletion content/blog/-2024-07-17-initial-release.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,143 @@
# Initial release

Today
Today we are announcing the initial "beta" level release of the Cogent Core GUI framework. Core takes seriously the idea that you can "Code Once, Run Everywhere", and indeed you are reading this blog using a Core app running on the web, via wasm (web assembly). The same code can run on all major desktop and mobile platforms as well, and we include a `core` tool that manages all the details for running and building apps for each of these different platforms.

Cogent Core is written in Go (golang), and inherits much of its best features from this amazing language, and its associated tooling ecosystem. Go code is simple, easy to read and write, and emphasizes a _minimalist_ approach that eschews as much of the extra syntax and boilerplate stuff that clutters so many other languages.

Here's a simple "hello world" app in Core:

```Go
package main

import "cogentcore.org/core/core"

func main() {
b := core.NewBody("Hello")
core.NewButton(b).SetText("Hello, World!")
b.RunMainWindow()
}
```

See that `Hello World!` button up there? That is a "live" rendering of the code shown in the text editor box above. Go ahead, and change the message, and hit `Control+Enter` or just click off, and you'll see it update!

Cogent Core supports all the usual types of GUI Widgets, along with some fairly advanced elements not found in other frameworks. We encourage a trip to the main docs page, which provides interactive, editable examples of all major elements: https://www.cogentcore.org/core/ (yep, it is also a wasm Core executable).

Here's a small sample of some of the widgets, and a few things you can do with them:

```Go
core.NewButton(b).SetText("Hello, World!").SetIcon(icons.Send).OnClick(func(e events.Event) {
core.MessageSnackbar(b, "Message sent to world!")
})
core.NewText(b).SetText("Name:").SetTooltip("enter your name in next field")
core.NewTextField(b).SetPlaceholder("Jane Doe")
value := float32(0.5)
spin := core.Bind(&value, core.NewSpinner(b)) // todo: this crashes in full body import mode!
slide := core.NewSlider(b)
spin.OnChange(func (e events.Event) {
slide.SetValue(value)
slide.Update()
})

type language struct {
Name string
Rating int
}
sl := []language{{"Go", 10}, {"Python", 5}}
core.NewTable(b).SetSlice(&sl).OnChange(func(e events.Event) {
core.MessageSnackbar(b, fmt.Sprintf("Languages: %v", sl))
})
```

Again, you can modify any of the above code and immediately see the effects!

You can even make interactive plots of data:

```Go
type Data struct {
Time float32
Population float32
}
data := []Data{
{0, 500},
{1, 800},
{2, 1600},
{3, 1400},
}
dt := errors.Log1(table.NewSliceTable(data))
pe := plotcore.NewPlotEditor(b).SetTable(dt)
pe.Options.XAxisColumn = "Time"
pe.ColumnOptions("Population").On = true
```


## Key Features

* Vulkan for high performance 2D and 3D rendering

* Full-featured SVG for 2D rendering and icons

* Extensive standards-based styling properties enable everything to be customized, including powerful automatic layout system that solves all the hard problems for you. should be familiar to anyone coming from HTML / CSS world.

* Powerful HCT color space integrated throughout: allows instant light / dark and alternate colorscheme customization.

* Focus on efficient keyboard navigation and customizable mappings, with full support for emacs mode.

??

## Our Story

The open source world is full of half-baked abandonware, especially in the world of GUI frameworks. And writing any kind of significant application in a given GUI framework inevitably requires a lot of time and effort (even with something as easy-to-use as Cogent Core), so it is reasonable to be very cautious in investing in a given framework, lest this common fate befall it and take your project down with it.

Therefore, we think it is important to tell you a bit about where Cogent Core came from, and where we want it to go in the future, and why we are committed to supporting it and growing a full software ecosystem around it.

The initial version of this software was named "GoKi", and it was written in 2018 by Professor Randy O'Reilly to enable him to develop advanced neural network models of the brain using Go, instead of C++. He had grown increasingly frustrated with the long build times and tiresome boilerplate involved in coding in C++. Python is, by itself, too slow for the actual numerical simulation code, so it inevitably serves as a wrapper around the same dreaded C++, resulting in a complex and unpleasant combination of two languages. Go, by contrast, compiles nearly instantly, and runs nearly as fast as C++. The small difference in compute time (less than 5-10%) was more than made up for by the massive increase in coding efficiency and overall happiness from using Go.

Overall, GoKi provided a powerful 2D and 3D interface that enabled experts, as well as novice undergraduate students in various classes taught around the world, to better understand and develop new ideas about how the brain works. However, as a first effort in Go, GoKi retained too much of the C++ style, and many important lessons were learned in getting everything to work.

Meanwhile, Randy's son Kai was busy experimenting with lots of different frameworks and languages for various coding projects, and eventually came to the same conclusion, that Go is truly the best language around. After exploring the various existing GUI frameworks in Go, Kai came to the conclusion that a major overhaul of GoKi might end up producing a much better framework than any of the other options.

So the father and son team (more son than father, to be clear) spent the next year rewriting this codebase many times over, peeling away layers of complexity and finding the most robust and elegant solutions to the many problems such a framework must solve. The Principles section of the documentation captures some of our hard-won lessons learned, and we hope that the experience of using this framework demonstrates the resulting simplicity and power of the approach.

As a young and ambitious programmer, Kai has many plans for future apps to program in the Cogent Core framework, and Randy continues to develop his neural network models for research and teaching. Throughout the process, Randy has maintained what is now Cogent Code as his primary everyday editor, and the new versions of the neural network models are also well tested. Therefore, we are confident that the core of the framework is solid and ready to use at this point, even as we continue to build out more features and welcome suggestions and input from the broader community for how to make it even better.

We are excited to build toward a world-class GUI framework in our beloved Go language, and hope this excitement is sufficiently contagious to grow a vibrant community of users and developers. We think Go is such a special language that it deserves to be used for everything and anything, outside of its traditional role as a server-side and cli-based workhorse.

## Future directions

One important future direction, evident in the interactive editing ability shown above, is to use the Yaegi Go interpreter as a replacement for the traditional role that Python has played relative to backend languages such as C++, so that you can transparently have a dynamic, interpreted experience as well as the lightning-fast compilation of Go. We think this can provide an ideal combination of rapid prototyping and hot-reloading (as in the Flutter framework), within a strongly typed and robust language that scales to large-scale applications (unlike Python and Javascript).

Furthermore, we have written a shell language variant of Go, called `cosh` (Cogent Shell), which allows direct intermixing of shell-like execution of command-line tools, with standard Go control constructs, using the Yaegi interpreter. Everything can be transpiled into standard Go and built the usual way as a fully compiled executable as well. Next, we plan to extend this general approach to the numerical computing and data science domain, in the Cogent Numbers framework, to provide a viable competitor in this Python-dominated domain.

In addition, we will be completing the Cogent Canvas app, which provides Inkscape-like creation and editing of SVG-based vector graphics (and bitmaps embedded therein), and the Cogent Mail client. We also plan to make a video editing app, and even keep plugging away at a web browser!

## Comparisons with other Frameworks

In the remainder of this blog, we provide some commentary about how we think Cogent Core compares with various other widely-used GUI frameworks and languages. As you can tell if you've read this far, we think the Go language is the best, so if you strongly prefer another language, Cogent Core may not be for you. But if you've been slogging along in the Javascript + HTML + CSS world, or come from a Qt / C++ or Flutter background, you might find something to like here.

### Javascript + HTML + CSS Frameworks

Most of the world's GUI software is written in some version of this stack..

* basic widgets significantly lacking: takes huge amount of time and effort to code a basic slider or spinner. so much CSS garbage.. Kai, take it away here..

* send to link comparing tic-tac-toe implementations?

### Platform-specific frameworks

Most mobile apps are written using tools optimized for each of the two major mobile platforms (iOS and Android), requiring significant duplication of effort, and mastery of vastly different software ecosystems (Swift / objective C vs. Java). By contrast, Cogent Core allows you to truly write one app in one language, and have it work well on both platforms (Core = "code once, run everywhere!").


### Flutter

* lots of complex boilerplate, relatively obscure language (DART), apparently losing some support from Google.

* send to link comparing ours vs. theirs?

### Go GUIs: Fyne and Gio

* Fyne is "fine" but we found it lacking in a number of areas: styling, complex widgets, etc..

* Gio has a very powerful set of platform-specific backend code, but the low-level nature of the immediate-mode design makes it very difficult to develop complex, large-scale appliations.



4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/cogentcore/cogentcore.github.io

go 1.22

require cogentcore.org/core v0.2.3-0.20240714060244-28f26c05a1b3
require cogentcore.org/core v0.2.3-0.20240714075553-855d8e2c5aeb

require (
github.com/Bios-Marcel/wastebasket v0.0.4-0.20240213135800-f26f1ae0a7c4 // indirect
Expand All @@ -11,6 +11,7 @@ require (
github.com/anthonynsimon/bild v0.13.0 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/chewxy/math32 v1.10.1 // indirect
github.com/cogentcore/yaegi v0.0.0-20240714043945-dadb98936955 // indirect
github.com/dlclark/regexp2 v1.11.0 // indirect
github.com/ericchiang/css v1.3.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
Expand All @@ -35,4 +36,5 @@ require (
golang.org/x/sys v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/tools v0.22.0 // indirect
gonum.org/v1/gonum v0.15.0 // indirect
)
8 changes: 6 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cogentcore.org/core v0.2.3-0.20240714060244-28f26c05a1b3 h1:SMG2bCBlSfOpFKx8+Jz/9ToJFq1wWOevPsIBShHnbF8=
cogentcore.org/core v0.2.3-0.20240714060244-28f26c05a1b3/go.mod h1:d6mENgx02agXXdJ4eJRi8VWuT7wtAtEgqlPr8t+DNn0=
cogentcore.org/core v0.2.3-0.20240714075553-855d8e2c5aeb h1:uL/i4C8VmvV12q/xTuazs2ZFyWsSFASQc4QcCB0cDhA=
cogentcore.org/core v0.2.3-0.20240714075553-855d8e2c5aeb/go.mod h1:d6mENgx02agXXdJ4eJRi8VWuT7wtAtEgqlPr8t+DNn0=
github.com/Bios-Marcel/wastebasket v0.0.4-0.20240213135800-f26f1ae0a7c4 h1:6lx9xzJAhdjq0LvVfbITeC3IH9Fzvo1aBahyPu2FuG8=
github.com/Bios-Marcel/wastebasket v0.0.4-0.20240213135800-f26f1ae0a7c4/go.mod h1:FChzXi1izqzdPb6BiNZmcZLGyTYiT61iGx9Rxx9GNeI=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
Expand All @@ -18,6 +18,8 @@ github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuP
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
github.com/chewxy/math32 v1.10.1 h1:LFpeY0SLJXeaiej/eIp2L40VYfscTvKh/FSEZ68uMkU=
github.com/chewxy/math32 v1.10.1/go.mod h1:dOB2rcuFrCn6UHrze36WSLVPKtzPMRAQvBvUwkSsLqs=
github.com/cogentcore/yaegi v0.0.0-20240714043945-dadb98936955 h1:KYLrEXVCaBsw3msuox5E6r7QrYMyafu5zX3omRTSdBU=
github.com/cogentcore/yaegi v0.0.0-20240714043945-dadb98936955/go.mod h1:+MGpZ0srBmeJ7aaOLTdVss8WLolt0/y/plVHLpxgd3A=
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
Expand Down Expand Up @@ -119,6 +121,8 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm
golang.org/x/tools v0.22.0 h1:gqSGLZqv+AI9lIQzniJ0nZDRG5GBPsSi+DRNHWNz6yA=
golang.org/x/tools v0.22.0/go.mod h1:aCwcsjqvq7Yqt6TNyX7QMU2enbQ/Gt0bo6krSeEri+c=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gonum.org/v1/gonum v0.15.0 h1:2lYxjRbTYyxkJxlhC+LvJIx3SsANPdRybu1tGj9/OrQ=
gonum.org/v1/gonum v0.15.0/go.mod h1:xzZVBJBtS+Mz4q0Yl2LJTk+OxOg4jiXZ7qBoM0uISGo=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down

0 comments on commit b9a42ba

Please sign in to comment.