본문으로 건너뛰기
AI NEWS JOURNAL
Hacker News Show HNAI NEWS / JOURNAL

Show HN: A modern take on the Go language

Targets Go to use the toolchain and the package system you already know and love Comments URL: https://news.ycombinator.com/item?id=50595828 Points: 2 # Comments: 0

번역 서비스가 일시 중지되어 원문을 표시합니다.

A superset of Go with modern language features. Keep Go packages, generated Go code, and the familiar toolchain. Notice: GPP is an independent open source project and is not affiliated with or endorsed by Google or the Go project. GPP is a playful nod to Go++ echoing how C++ grew from C. GPP is distributed under the BSD 3-Clause License, the same license as Go. Bundled third-party components may have separate licenses; see their notices. What's implemented? GPP adds expressive language features while keeping Go packages, generated code, and the familiar build toolchain in reach. The guides below explain each feature with comparisons and examples. Language features Classes — Group fields and methods around an implicit this, with concise construction and generated Go structs. Static methods and factories — Put type-level operations on a class and provide named ways to construct values. Polymorphism — Use class values through compatible base types and interfaces, including when calling methods. Multiple inheritance — Compose behavior from multiple base classes, with qualified access when members conflict. Overloading — Reuse a function or method name for different arities and statically distinguishable argument types. Named arguments and defaults — Make call sites clearer and omit arguments that have a declared default. Anonymous structs — Pass composite values without declaring one-off structs for every function boundary. Enums — Define closed, named value sets with grouped declarations, validation, ordered values, and member metadata. Generic classes and functions — Reuse type-safe classes and functions across value types, with Go-compatible type constraints and explicit constructor type arguments. Lambdas and the prelude — Write concise functions and use familiar collection, string, and map helpers. Extension methods — Add compile-time methods to existing types, including several types in one extension block. String interpolation — Embed values in double-quoted strings, with formatting and String() support. Raw strings retain their literal Go behavior. Regular expressions — Compile and use regular expressions through concise prelude helpers. Safe access — Use ?. to access members of nullable class values without repeating explicit nil checks. Lazy error fallback — Use ?? to evaluate a fallback only when the value on its left is absent or erroneous. Exception handling — Keep Go-style error values while adding throw, try, typed catch, and finally syntax. Program exit hook — Register atExit work that runs during normal program shutdown. Annotations and introspection — Declare typed metadata, validate its targets, and inspect it at runtime. Application features and standard library Serialization — Generate JSON, YAML, and GOB conversion methods from class annotations and field metadata. HTTP servers and routes — Build servers with annotated routing, request binding, middleware, and lifecycle hooks. OpenAPI, Swagger, and OAuth — Generate API documentation and interactive Swagger UI, with OAuth/OIDC support. Typed SQL queries — Return scalars, anonymous or named structs, or models from full SQL statements. ORM models — Map annotated models to tables and use model-oriented queries and persistence hooks. Typed templates — Define HTML/XML templates as functions and render them with Go's html/template protections. External template reloads — Reload .gpp.tpl files during development without rebuilding the server. Embedded assets — Include files and directories in the program through source-level declarations. Cron scheduling — Schedule annotated functions or dynamic jobs with explicit start and stop controls. Experimental packages — Explore experimental packages, including the HTTP client and durable work queue. Suite-based tests — Organize tests into suites, methods, and annotations, then run them through gpp test. Go compatibility and tooling Go compatibility — Use ordinary Go imports and dotted GPP packages mapped to module paths; standalone programs can omit package main. Mixed Go and GPP builds — Call Go from GPP and GPP from Go while compiling both languages in one project. Project CLI — Initialize, build, run, test, format, and inspect GPP projects with the gpp command. Formatter — Format GPP syntax consistently and check formatting in CI. Source documentation — Read declarations and API documentation directly from GPP source. Language server — Get editor diagnostics, completion, navigation, semantic highlighting, and quick fixes. Visual Studio Code The GPP VS Code extension provides GPP syntax highlighting, snippets, formatting, and optional language-server support for diagnostics, completion, and navigation. The editor view below shows the Todo model in the full example. Install and build GPP requires Go 1.27 or newer. This enables generic methods declared directly on classes in generated projects, alongside generic free functions, static methods, and extension methods. Homebrew Install Homebrew if needed. Add the GPP tap:brew tap telgatech/gpp Install and verify GPP:brew install --HEAD telgatech/gpp/gpp gpp version Update to the latest commit on main:brew update brew upgrade --fetch-HEAD telgatech/gpp/gpp The formula currently tracks main, so --HEAD is required until a versioned release. Homebrew Core also has an unrelated formula named gpp; uninstall it first if present, since Homebrew cannot install both same-named formulae side by side. Go install For Go developers who already have Go 1.27 or newer and want to try GPP quickly: go install github.com/telgatech/gpp@main It provides one gpp executable with project commands: gpp init|compile|build|run|clean|fmt|fiximports|test|doc|env|doctor|version|lsp Create and run a starter project: gpp init hello cd hello gpp run gpp init creates a root go.mod and initializes a Git repository with an init commit when the target is not already inside a Git worktree. Dependency resolution happens when you build or run the project. The initial commit includes only the generated project files. Build a native executable. Intermediate Go source remains in the hidden compiler workspace rather than beside the GPP source: gpp build examples/hello.gpp -o ./hello Compiler warnings are hidden by default. Pass -warnings to show them: gpp build -warnings examples/hello.gpp gpp build reuses generated Go and the executable while its inputs remain unchanged. After a GPP source edit, the compiler reuses generated output for unaffected packages, and Go's build cache reuses unaffected Go packages. Native Go helper or embedded file changes are tracked as build inputs. gpp clean clears the generated workspace and its cache state. Use gpp doctor to check the Go toolchain and embedded standard library, and gpp clean to remove generated build artifacts. Format GPP source with the shared canonical formatter. It uses four-space indentation, preserves comments and opaque literal/template content, and supports CI-friendly check mode: gpp fmt examples/hello.gpp gpp fmt --check ./... gpp fmt --stdout examples/hello.gpp Use gpp fiximports to add missing imports, remove unused named imports, and resolve package-name clashes when a unique available package matches qualified names in GPP source. It prefers bundled GPP packages and uses std-prefixed aliases for colliding standard-library imports. It supports --check and --stdout modes. Pass -emit-go to gpp build when you want the generated Go workspace path reported for inspection. GPP tests use the bundled gpp/test suite library and ordinary Go test execution underneath: gpp test examples/testing.gpp gpp test --tag crud examples/testing.gpp gpp test --priority high examples/testing.gpp The compiler's CI also runs go test ./... and scripts/smoke-examples.sh. That smoke test creates a fresh project with gpp init, copies in the complete examples tree, then runs or builds every example (and executes the GPP testing example). Run it locally before submitting compiler changes: ./scripts/smoke-examples.sh Inspect GPP source-level documentation without exposing generated Go: gpp doc gpp/http.Server gpp doc string.TrimSpace gpp doc --json gpp/http.Server gpp doc --search template Start the editor language server over standard input/output: The server keeps open-document overlays in memory and provides diagnostics, completion, hover, navigation, references, rename, symbols, formatting, and signature help without running a Go backend build on every change. Use gpp lsp --log=/tmp/gpp-lsp.log when protocol-side diagnostics are needed; logs never go to stdout. Documentation site The technical documentation is built with VitePress. It includes a practical landing page, getting-started and language guides, compiler/tooling notes, and the specifications mirrored from spec/ at build time: npm install npm run docs:dev Build and preview the static site locally: npm run docs:build npm run docs:preview Pushes to main build and deploy the site through GitHub Pages using the workflow in .github/workflows/docs.yml. In the repository settings, set Pages → Build and deployment → Source to GitHub Actions once. Build and run For a complete project build, use the build subcommand. It clears stale generated source, runs go mod tidy to resolve imports, and runs go build: gpp build examples/hello.gpp Use run for the same generation and dependency setup followed by execution: gpp run examples/hello.gpp gpp run also accepts .go files and Go-only directories. Those files go through the GPP compiler before the generated Go is built and run: gpp run ./main.go -- program-argument gpp run ./cmd/server During gpp run, external .gpp.tpl sources are watched when used with gpp/http.Server; valid edits reload automatically and invalid edits leave the previous templates active. Production gpp build uses the compiled template sources without starting a watcher. Use a separate output directory when switching between standalone examples: gpp run -output /tmp/gpp-orm examples/orm.gpp Multiple GPP files can be passed to the same build. For example, the cross-package example is built and run as one generated project: gpp run \ examples/packages/people.gpp \ examples/packages/main.gpp GPP and Go can also live in the same build. The mixed-compilation examples demonstrate both directions: gpp run -output /tmp/gpp-go-from-gpp examples/mixed/go_from_gpp gpp run -output /tmp/gpp-go-imports-gpp examples/mixed/go_imports_gpp The first lets GPP call functions from native.go; the second lets ordinary Go import the generated generated/mixed package. The ORM example also resolves its SQLite dependency automatically: gpp run -output /tmp/gpp-orm examples/orm.gpp Build an executable at a chosen path with -o: gpp build -o ./hello examples/hello.gpp Generated Go is written to a stable, per-project workspace under the system cache. The CLI creates that workspace's go.mod with the default module path generated; choose another path with -module when local Go package imports need a real module path. Set GPP_CACHE to choose the cache root: GPP_CACHE=/var/cache/gpp gpp -module example.com/myapp examples/*.gpp Choose a different generated output directory with -output: gpp -output build/gpp examples/hello.gpp The standard GPP prelude is available automatically. Disable it for minimal or diagnostic builds with -no-prelude. The enum example demonstrates implicit and explicit values, grouped enum declarations, validated conversion, and metadata: gpp run examples/enums.gpp Expression-level error fallback is demonstrated by: gpp run examples/expr_catch.gpp Class introspection exposes generated name, fields, methods, annotations, owner, type, get, set, and addr metadata while preserving ordinary Go structs and stdlib interoperability. GPP is released under the BSD 3-Clause License. Copyright (c) 2026 Telga Technologies Pvt Ltd and GPP contributors. See LICENSE for details. When redistributing source code from this GPP compiler project, retain the copyright notice, all three license conditions, and the warranty disclaimer from LICENSE.

자료 출처

원문 읽기 ↗

관련 주제

← 전체 소식 이어 읽기