Comments (5)
Every line in this project, as long as it is been written by me, are hand-tuned for aestheticness. Programming is a kind of art, not just tasks that someone forced you to finish.
Programs are indented to be read by human, not machine. Machines do NOT understand aestheticness, they can only do certain things pre-programmed by it's designer. It's also why there is very hard for computers to generate aesthetically pleasing arts.
If it's a trade-off, as long as they are functionally identical, I don't want to trade aestheticness for almost nothing.
IMO, go fmt
is just an excuse to the laziness of programming. NEVER write messy code and hope go fmt
magically fixes all the issues for you.
And also, go fmt
is A code-style, not THE code-style. If Go really wants to force everybody to write identically looking code, they should fuse it into the syntax.
We have the rights of choosing our own style of programming, as our ByteStyle
stats:
Champion Diversity and Inclusion
Take a look:
A hand-formatted program
func NameOf(id int) string {
switch (id) {
case APPLE : return "Apple"
case BANANA : return "Banana"
case ORANGE : return "Orange"
default : return "Unknown"
}
}
is considerably more readable and cleaner than the machine-generated counterpart:
func NameOf(id int) string {
switch id {
case APPLE:
return "Apple"
case BANANA:
return "Banana"
case ORANGE:
return "Orange"
default:
return "Unknown"
}
}
Also, the go fmt
has some wierd formatting rules that cannot be turned off:
if a < (x + y) * z << 5 {
// do something
}
will be formatted into
if a < (x+y)*z<<5 {
// do something
}
which is A LOT messier.
Consider editing CONTRIBUTING.md
.
from sonic.
Can you explain how a different code style might prevent others from participating in this project?
from sonic.
Can you explain how a different code style might prevent others from participating in this project?
check this: https://github.com/bytedance/sonic/blob/main/CONTRIBUTING.md#contribution-prerequisites, please.
You need fully checking with lint tools before submit your pull request. gofmt & golangci-lint
If you don't follow the contribution rules yourself, why should others follow?
and in google code review comments: https://github.com/golang/go/wiki/CodeReviewComments#gofmt:
Gofmt
Run gofmt on your code to automatically fix the majority of mechanical style issues. Almost all Go code in the wild uses gofmt. The rest of this document addresses non-mechanical style points.
An alternative is to use goimports, a superset of gofmt which additionally adds (and removes) import lines as necessary.
I think at least you guys represent bytedance, right? Isn't the company code specification mandatory to use gofmt
?
If we mr, it will be a disaster to see that all files are modified, because of our using of gofmt
from sonic.
hello @wymli , I've opened a pr for this #37 and find out that the code after format is less prettier than the code before format.
I learned that the code is formatted manually with great care by @chenzhuoyu to make it pretty, because there's a lot of assembly code in the go files, and assembly code format is not the same as the go code. Unfortunately, gofmt cannot handle this at the moment.
Here's some diffs, you may compare them and determine which looks better:
You may also take a look at the pr #37 .
Thanks for your suggestion anyway.
from sonic.
That's a trade-off, maybe just ignore these mannually fine-tuned *.go files or code snippets.
The tools can't fit all scenarios.
from sonic.
Related Issues (20)
- v1.10.0 中的 (ast.Node).UnsafeMap() 被注释了,为什么在同一个大版本内做不兼容升级? HOT 3
- mmap_unix.go missing BSD in Go build tag HOT 4
- When will golang 1.20 be supported? HOT 1
- go1.21.4 运行报警告 HOT 2
- How to make the unmarshaling process of json int array faster? HOT 1
- Execute file size is too big, can sonic be optimized when compile? HOT 9
- Add API documents to readme file
- Parse UTF8 characters failed HOT 1
- Any solution for parse sql.NullString field failed? HOT 2
- Panic: &rt.GoString{Ptr:(unsafe.Pointer)(0xc003f6d650), Len:100} has nil pointer while its length is not zero! HOT 1
- Is there a more elegant implementation of re-serialization after partial modification of the contents of ast.Node? HOT 9
- go1.22.0 build error
- WARNING: sonic only supports Go1.16~1.20 && CPU amd64, but your environment is not suitable HOT 2
- go 1.22.0 build error HOT 1
- Depress WARNING: sonic only supports Go1.16~1.22 && CPU amd64, but your environment is not suitable on Apple Chip Macs HOT 4
- bug: `unset()` misbehavior on v1.11.0-x
- can not compile at linux/amd64 and go 1.22 HOT 1
- [ast] invalid memory address or nil pointer dereference HOT 3
- Support golang v1.22 HOT 1
- 使用go的docker镜像编译时cgo报错 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sonic.