All Projects → gigantik → Gigsib

gigantik / Gigsib

📑Golang Is Good, Structure Is Bad

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Labels

Projects that are alternatives of or similar to Gigsib

VSCoding-Sequence
VSCode Extension for interactively visualising protein structure data in the editor
Stars: ✭ 41 (+127.78%)
Mutual labels:  structure
Typed Immutable
Immutable and structurally typed data
Stars: ✭ 263 (+1361.11%)
Mutual labels:  structure
Gofamily
🔥 大厂 BAT 面试高频知识点,后端技术体系。包含了 C GO Python, 网络,Redis ,MySQL ,消息队列 ,高并发,微服务,缓存,操作系统,算法,LeetCode 刷题等知识
Stars: ✭ 474 (+2533.33%)
Mutual labels:  structure
focus-single
Single repo demo project using GoFrame.
Stars: ✭ 26 (+44.44%)
Mutual labels:  structure
ts-json-validator
JSON Validator for TypeScript - Safer JSON.parse() validating by TypeScript types
Stars: ✭ 23 (+27.78%)
Mutual labels:  structure
Somepackage
Show how to structure a Python project.
Stars: ✭ 351 (+1850%)
Mutual labels:  structure
arch
🎉 a Tool to Manage & Automate your Node.js Server 🎉
Stars: ✭ 13 (-27.78%)
Mutual labels:  structure
Reclass.net
More than a ReClass port to the .NET platform.
Stars: ✭ 766 (+4155.56%)
Mutual labels:  structure
Construct
A PHP project/micro-package generator for PDS compliant projects or micro-packages.
Stars: ✭ 257 (+1327.78%)
Mutual labels:  structure
Struct2json
A fast convert library between the JSON and C structure. Implement structure serialization and deserialization for C. | C 结构体与 JSON 快速互转库,快速实现 C 结构体的序列化及反序列化
Stars: ✭ 424 (+2255.56%)
Mutual labels:  structure
directory-structure
📦 Print a directory tree structure in your Python code.
Stars: ✭ 40 (+122.22%)
Mutual labels:  structure
PlaneTR3D
[ICCV'21] PlaneTR: Structure-Guided Transformers for 3D Plane Recovery
Stars: ✭ 58 (+222.22%)
Mutual labels:  structure
Skema
🛰 Skema provides a handy & composable way to validate / transform / purify the input data.
Stars: ✭ 359 (+1894.44%)
Mutual labels:  structure
strcode
Structure your code better.
Stars: ✭ 42 (+133.33%)
Mutual labels:  structure
Java design patterns
Java 实现的面向对象设计模式示例, 创建者、抽象工厂、工厂方法、原型、单例、适配器、桥接、组合、装饰器、备忘录、观察者、状态、策略、模板方法、访问者
Stars: ✭ 547 (+2938.89%)
Mutual labels:  structure
algo-ds-101
Curated list of data structures and algorithms in 10+ programming languages.
Stars: ✭ 154 (+755.56%)
Mutual labels:  structure
Confita
Load configuration in cascade from multiple backends into a struct
Stars: ✭ 344 (+1811.11%)
Mutual labels:  structure
Abstractionlayers
Abstraction Layers
Stars: ✭ 16 (-11.11%)
Mutual labels:  structure
City Vein
Urban structure characterized by 🚌 public lines
Stars: ✭ 644 (+3477.78%)
Mutual labels:  structure
Objectmodel
Strong Dynamically Typed Object Modeling for JavaScript
Stars: ✭ 415 (+2205.56%)
Mutual labels:  structure

Golang Is Good, Structure Is Bad

I begin with imports. Nomarlly you just import a package and the last element of the package path would be the package you want to use.

import "foo/bar/baz"

Problem

So what if there's (probably is) type called Baz and you use it:

import "foo/bar/baz"

func main() {
        baz := baz.New()
}

wat.

You just shadowed the package name with calling a variable baz and you writing baz twice baz.Baz in linguistics terms which is not good (remember DRY!) and probably you'd write a factory function called NewBaz that's even worse.

package baz

type Baz struct{}

func NewBaz() {
        // do something
}

Solution

I found a solution or trick to naming things in decent way IMO. So you just name your package whatever you want and there must be only one exported type inside the package and you should call it Type and you must separate each type into different packages and you must name packages explicitly with in PascalCase.

import Baz "foo/bar/baz"

var baz Baz.Type{}

Why?

With that trick I can use packages as metaphor to classes and you can write:

package main

import Basket "gigsib/model/basket"
import BasketItem "gigsib/model/basket_item"

func main() {
        basket := Basket.New(nil)
        basket.AddItemBang(BasketItem.New("NikeLab ACG 07 KMTR", "1100"))
        basket.AddItemBang(BasketItem.New("Nike Kobe A.D. Triple Black", "750"))
        basket.TotalPrice()
}
    require "gigsib/model/basket"
    require "gigsib/model/basket_item"

    basket = Basket.new(nil)
    basket.add_item!(BasketItem.new("NikeLab ACG 07 KMTR", "1100"))
    basket.add_item!(BasketItem.new("Nike Kobe A.D. Triple Black", "750"))
    basket.total_price()

Do you see a big difference between ruby and golang? (expect ! and naming convention and entrypoint)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].