C-spirit reborn: why Go was bound to be created
-
Upload
artem-kovardin -
Category
Engineering
-
view
551 -
download
0
description
Transcript of C-spirit reborn: why Go was bound to be created
C-spirit reborn, or why Go was bound to be createdBOHDAN TROTSENKO
C, C++ CMyClass instance;
instance.DoSomething();
… void *p = get_memory_on_stack(sizeof(CMyClass));
try {
p.ctr();
p.DoSomething();
} catch (...)
{
p.~dstr();
}
Imperative Languages
C, C++
Go
Java, C#
Enterprise principle
The straight-forward way to do things is the right way to do things
func FillInp(path string, res chan string) {
var (
file *os.File
err error
)
defer close(res)
if file, err = os.Open(path); err != nil {
fmt.Println("Error opening file", err)
return
}
defer file.Close()
… some horrible code sem := make(chan bool, parallelism) // semaphore
for perm := 0; perm < parallelism; perm++ {
sem <- true // add initial values
}
for cs := 0; cs < len(cases); cs++ {
<-sem // read values
thiscase := cs
go func() {
Solve(&cases[thiscase])
sem <- true // permit others to continue
}()
}
protobuf message Test {
required string label = 1;
optional int32 type = 2 [default=77];
repeated int64 reps = 3;
optional group OptionalGroup = 4 {
required string RequiredField = 5;
}
}
usage of protobuf test := &example.Test {
Label: proto.String("hello"),
Type: proto.Int32(17),
Optionalgroup: &example.Test_OptionalGroup {
RequiredField: proto.String("good bye"),
},
}
data, err := proto.Marshal(test)
if err != nil {
log.Fatal("marshaling error: ", err)
}
A few gotchas… dbg_f("Awaiting writer...")
<-outWG
dbg_ln("done.")
////////////////
hostname := packet[start:end]
Bottom line Go is lightweight and powerfull
Collections and memory made right
Concurrency made right
Software architecture made wonderful
http://trotsenko.com.ua
@modosansreves