[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Golang thread

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 65
Thread images: 3

File: images.duckduckgo.com.jpg (158KB, 1431x901px) Image search: [Google]
images.duckduckgo.com.jpg
158KB, 1431x901px
Golang thread
>>
File: 32.jpg (26KB, 390x310px) Image search: [Google]
32.jpg
26KB, 390x310px
>hello world binary is 3MB
>hello world
>3 FUCKING MB
>>
>not using C
#include <stdio.h>main(void){printf("Hello, World");}
>>
>>56178050
Still gets better performance than .net
>>
GOLANG

25 keywords:

break default func interface select
case defer go map struct
chan else goto package switch
const fallthrough if range type
continue for import return var

>>
C

33 keywords

auto
break
case
char
const
continue
default
do
double
else
enum
extern
float
for
goto
if
int
long
register
return
short
signed
sizeof
static
struct
switch
typedef
union
unsigned
void
volatile
while
>>
Java

50 Keywords

abstract continue for new switch
assert*** default goto* package synchronized
boolean do if private this
break double implements protected throw
byte else import public throws
case enum**** instanceof return transient
catch extends int short try
char final interface static void
class finally long strictfp** volatile
const* float native super while

>>
>golang
more like: badlang
>>
>>56178248
>hating on Go
>not even giving a reason
>>
.NET

hundreds of keywords

https://msdn.microsoft.com/en-us/library/ksh7h19t(v=vs.90).aspx
>>
>>56178284
>implement sorting
>have to implement len, swap and fucking less methods for trivial shit
>>
Rust

50 keywords

abstract alignof as become box
break const continue crate do
else enum extern false final
fn for if impl in
let loop macro match mod
move mut offsetof override priv
proc pub pure ref return
Self self sizeof static struct
super trait true type typeof
unsafe unsized use virtual where
while yield
>>
>>56178324
>he doesn't even know how to use the language
>>
>>56178340
52
>>
>>56178351
Tell me how to implement custom sorting on an array with strings without all the boilerplate.
>>
>>56178340
Many of them remnants from pre-1.0 days and are never used today, though.
>>
>>56178364
What boilerplate? What kind of sort? Strings are arrays so sorting is pretty trivial.
>>
Smallfuck: 5 operators
< > [] *
>>
>>56178426
i would kill myself
>>
>>56178387
More accurate list: https://github.com/rust-lang/rust/blob/master/src/libsyntax/parse/token.rs#L407
>>
>>56178127
>benchmarking hello world
ok
>>
>>56178408
Show me the code to sort an array of strings descending.
>>
if err != nil
>>
>garbage collection
into the garbage bin it goes
>>
>>56178159
>>56178214
>>56178231
>>56178316
>>56178340
>>> import keyword
>>> keywords = keyword.kwlist
>>> len(keywords)
33

Nice meme, keywords don't measure jack shit. Riddle me this anon: How many keywords does Lisp have?

I have nothing against Go. I think it has its place and is a legitimate language to learn and to develop in, but your line of argumentation is retarded.
>>
>>56178024
Why do you create a go/golang thread without sharing good tutorial, screencasts, books or packages? I am interested by the language but the fact there are absolutely no jobs for it wonders me a lot.
>>
>>56178645
There is more than one way to do that. This is one example, descending by length:


package main

import (
"fmt"
"sort"
)

func main() {
example := []string{"test007", "test0008", "test5", "test06"}
sort.Sort(sort.StringSlice(example))
fmt.Println(example)
}
>>
>>56178753
calm down bro
>>
>>56178779
This sorts ascending nigger.
>>
>>56178846
nope

but if you want to reverse order change line 10 to

sort.Sort(sort.Reverse(sort.StringSlice(example)))
>>
>>56178024
Where are the objects? It looks like bash!
>>
Are there any windows users using golang as daily language?
>>
>>56179038
It uses structs and interfaces

STRUCTS AND INTERFACES

STRUCTS
KEYWORDS:
type => introduces new type
struct => indicates struct type
-> A type that contains named fields
-> typically we use a pointer pointing to a struct
because instead of just returning something we
can modify the variable
-> type Circle struct {
x, y, r float64
}
c := Circle{x: 0, y: 0, r: 5}
or
c := Circle{0, 0, 5} //if we know the order
-> pointer: c := &Circle{0, 0, 5}

FIELDS:
-> can be accessed with dot notation
c.x, c.y, c.r, etc.....

METHODS
-> a function that extends a type
-> func (c *Circle) area() float64 {
return math.Pi * c.r*c.r
}
-> No pointers needed

EMBEDDED TYPES
-> a type embedded in a struct
type Android struct {
Person //some other struct
Model String
}
-> methods defined on Person can be called
directly from Android (Android.name())

INTERFACES
-> type Shape interface {
area() float64
}
-> instead of defining fields we define a method set
-> method set is a list of methods that a type must
have to implement the interface
-> Can assign methods to struct
-> When structs implement the same methods they
also implement the same interface
-> func totalArea(shapes ...Shape) float64 {
//stuff
}
// Can take any type/struct that implements
// shape interface
-> Can't access struct fields, only methods
-> Interface can be used as a field
type MultiShape struct {
shapes []Shape
}

multiShape := MultiShape{
shapes: []Shape{
Circle{0,0,5},
Rectangle{0,0,10,10}
}
}


>>
>>56179076
Don't use Windows. It's literally the worst OS.
>>
>no generics
literally into the trash it goes
>>
>>56179171
You don't need them. Honestly only bad coders use them.
>>
>>56178340
>Self
>self
What's the difference?
>>
What's Go's niche?
>>
>>56180209
networking/concurrency
>>
>>56178938
Kek, nice performance m8.
>>
>>56180832
>he didn't use a go routine
>>
i wish Limbo took off instead

seemed like better Java to me
>>
>>56178159

ERLANG 

27 Keywords:

after and andalso band
begin bnot bor bsl
bsr bxor case catch
cond div end fun
if let not of
or orelse receive rem
try when xor


And yet so much better when it comes to concurrency..
>>
Based fucking golang. We used it to hack up a baby version of paxos for class on distributed systems. Debugging concurrency has never been that easy.
>>
>>56183393

>Debugging concurrency has never been that easy.

This "go is so easy" meme..

First of all , concurrency in Golang is shit. One process dies, every process dies.

Also Go is NOT an concise langauge. For example, this is mergesort in Erlang:

-module(mergesort).
-export([mergesort/1]).

merge(A, []) -> A;
merge([], B) -> B;
merge([Ha|Ta], [Hb|Tb]) ->
if
Ha < Hb -> [Ha | merge(Ta, [Hb|Tb])];
true -> [Hb | merge([Ha|Ta], Tb)]
end.

mergesort([]) -> [];
mergesort([E]) -> [E];
mergesort(L) ->
{A, B} = lists:split(trunc(length(L)/2), L),
merge(mergesort(A), mergesort(B)).



And this is a "minimalistic" Golang mergesort:

package main

import (
"fmt"
"math/rand"
"time"
)

func main() {
slice := generateSlice(50)
fmt.Println("\n --- unsorted --- \n\n", slice)
fmt.Println("\n--- sorted ---\n\n", MergeSort(slice), "\n")
}

// Generates a slice of size, size filled with random numbers
func generateSlice(size int) []int {
slice := make([]int, size, size)
rand.Seed(time.Now().UnixNano())
for i := 0; i < size; i++ {
slice[i] = rand.Intn(99999) - rand.Intn(99999)
}
return slice
}

// Runs MergeSort algorithm on a slice single
func MergeSort(slice []int) []int {
if len(slice) < 2 {
return slice
}
mid := (len(slice)) / 2
return Merge(MergeSort(slice[:mid]), MergeSort(slice[mid:]))
}

// Merges left and right slice into newly created slice
func Merge(left, right []int) []int {
size, i, j := len(left)+len(right), 0, 0
slice := make([]int, size, size)

for k := 0; k < size; k++ {
if i > len(left)-1 && j <= len(right)-1 {
slice[k] = right[j]
j++
} else if j > len(right)-1 && i <= len(left)-1 {
slice[k] = left[i]
i++
} else if left[i] < right[j] {
slice[k] = left[i]
i++
} else {
slice[k] = right[j]
j++
}
}
return slice
}
>>
>>56183484

OK, maybe that is a bit unfair, since in the Go version we generated random numbers.

So let's look at concurrency:

This is an Erlang example where we generate a new process and send 100,000 messages to the process:

-module(counter).
-export([run/0, counter/1]).

run() ->
S = spawn(counter, counter, [0]),
send_msgs(S, 100000),
S.

counter(Sum) ->
receive
value -> io:fwrite("Value is ~w~n", [Sum]);
{inc, Amount} -> counter(Sum+Amount)
end.

send_msgs(_, 0) -> true;
send_msgs(S, Count) ->
S ! {inc, 1},
send_msgs(S, Count-1).


We need 3 simple parts here:
"spawn" cretes a new process
"!" sends a mesasge to the process
"recieve" is the block were we react to the message.


No in Go, you have:

Routines, Channels, Channel buffering, Stages, Pipelines, Fan-out, Fan-in..

How is this "simple"?
>>
>>56183298
Ada has 73. Does it win a prize
>>
>>56183810

More keywords = more stuff to learn.


The point is everybody praises Go for being so simplistic when actually even Node.js is better..

Instead of "Golang" they should have called it "Gohome" or "Memelang"..
>>
what about...Scala?
>>
>>56183298
Erlang is not better than go.
>>
>>56183665
Just because Erlang is a bloated piece of shit doesn't mean it's better.
>>
I will never understand why the Hype with Go considering we already have Java.
>>
>>56183920

Go is nice for a small API. It's even faster there. When you have a lot of computation and a small/mid-sized project, Go is the better choice.

But as soon as you have a lot of processes, or want higher avalibility and fautl tollerance, Erlang is the better choice.
>>
>>56183665
> Routines, Channels, Channel buffering, Stages, Pipelines, Fan-out, Fan-in..

That's a bit disingenuous. You just need channels and routines to do the same in Go.

The rest are what you'd consider design patterns or just examples of how you'd build on the simple channel/routine.
>>
>>56183948

Erlang is definately not bloated.

Enjoy your toy langauge with that retarded mammal while I change my code without restarting..

I don't even know how poeple can use a non-functional langauge with mutable values and that shared state clusterfuck in the current year.
>>
>>56184039

I admit that I'm not really an Go expert.

It's just that it's main seeling point is that it's incredibly simple to use. Nevertheless the concurrency doesn't really feel like concurrency to me, I can't help it.


OK, maybe I should take a few days and dig into Go again, the stuff I've seen so far wasn't very interesting to me. But then again it's unfair to judge without doing a real project in that language.
>>
>>56178159
>goto
hello fortran
>>
Serious question. Can you specify which cpu you want you task to run on in go?
>>
>>56178024
>>56178159
https://play.golang.org/p/sI0h9sUZw-
>>
>>56184539
yea
runtime.LockOSThread or something
>>
my website, made with Go in the backend, has been running with no problems for almost a year. (sadly, other than a ton of bots and the occasional attempt to hack it, almost no one uses it [unless I post links], but that's another topic)
Go is stable as a fucking rock and fast af.
>>
watch this:
https://youtu.be/KINIAgRpkDA
>>
What the fuck are all these "*" and "&" in this language?
Are they useful?
>>
The compiler is years behind clang and gcc.
>>
>>56179979
self refers to the instance of a type, Self is a type alias to the Implementor of a function. This is useful when defining traits for example:

trait Foo {
fn foo(self) -> Self;
}

impl Foo for u64 {
//Can also write fn foo(&self) -> Self
fn foo(self) -> u64 {
self + 1
}
}

fn main() {
let x = 1u64.foo();
println!("{}", x) // 2
}
Thread posts: 65
Thread images: 3


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.