I've read so many tweets on the X platform that web servers built on Bun are faster that Rust and Go. How true is that, they have their Benchmarks to support their claims and I just find it absurd because because the way I think Node/Bun works is that your Javascript are transpiled to C++/Zig in every execution, a thing I believe would give Rust or Go the edge because these languages are directly compiled etc.
im a web dev with 5-years-ish of experience, i do familiar with js, php and python
i came accross this masterpiece: stash (web based app for organizing porn)
and it makes me wanted to learn golang and contribute to it (because i actually use it)
the question is:
-
how hard and different is golang from js/php/python?
-
is there any book/course recommendation for webdev that wanted to learn golang?
Videos
Hey guys, Will you consider developing a backend in javascript instead of golang even when there is no time constraints and cost constraints Are there usecases when javascript is better than golang when developing backends if we take the project completion time and complexity out of equation
Just want to know the community opinion: from what I see the key benefit of using node.js for back-end is the same language as front-end part. If I would like to work on back-end side only, would it better to switch to golang, let’s say, to do back-end only things, and don’t care about any front-end related stuff. Have node.js developers already considered as the real “back-end” guys? Or just an JavaScript front-end switchers 😀
Which is a better starter to learn web dev? I have tried a bit of all three.. and I can't help but think golang felt easier when it comes to setting up server and connecting to Db and stuff.
Been a long time since I did any code. Just a noob who tried some things. Now I don't even remember the syntax of any of these.
Now trying to go with python since there are more tutorials and it feels simple even though what it does underneath is masking complexities underneath a layer of abstraction.
What are your thoughts?
-
What do you think of when you say "web dev"? Provide a literal one-page static HTML page, nicely styled via CSS? A single page application, lots of JavaScript running in the browser (only, no backend)? "Frontend Development" vs "Backend Development" vs "Fullstack" (awful terms).
-
Are you simply interested in that type of things or do you need to get a job fast at a certain geographic location (even a badly paid one)?
-
What type of things do you want to do? Are you interested only in building stuff? Or operating them too? You alone? A team? How long do you want to keep your things up and running? At wich exposure?
-
When asking this on a Go sub you will get biased answers.
IMHO stay away from anything JavaScript-ish as this is layer, tooling, layering, tools, layer, tools, transpilers, layers, more layers, more tooling, more transpilers, more translation steps, some more layers all the way down. Each layer, tool "fixing" (read "hiding") some fundamental problem of the lower layer. Python is stronger in other areas than "web development".
JavaScript is probably the most useful (because front-end too) but the ecosystem is an absolute shitshow.
Python is more general-purpose but it can be very complex. There are a bazillion tutorials partly because there's a need for them.
Go is designed to be simple, it's easy to learn, powerful, but designed for one job; writing servers. If you want to do other stuff with it there's very little tooling or support. E.g UI/apps, ML,
Hi! I'm new to Golang and I'm trying it out.
I implemented the Kosaraju's algorithm in both Golang and node.js and measured the execution time. To my surprise, the Golang version is ~34% slower. I expected Go to be much faster than node.js.
I did my best to use the same logic and data structures for both languages to make sure I'm comparing apples to apples. I know that the algorithm itself can be improved, but I'm not looking for an algorithmic improvement, I just want to find out why Go is so much slower than node.js when both are executing the same thing.
I'll paste both scripts below. Each of them is a single file that you can run in the terminal. They'll execute the algorithm 6 times, then print the average time of the 6 executions. They expect a payload.json file in the same folder from which they'll load an adjacency matrix. I can't share my payload.json because it's too large (11 mb), but it's just a 2d matrix of random integers with 3000 rows and 3000 columns. Let me know if you need help generating it.
Can someone explain why is Go so slower than node?
graph.js
const fs = require('fs')
const { performance } = require('perf_hooks')
class Graph {
constructor() {
this._edges = new Map()
this._inNeighbors = new Map()
}
connect(vertexFrom, vertexTo, weight) {
if (!this._edges.has(vertexFrom)) {
this._edges.set(vertexFrom, new Map())
this._inNeighbors.set(vertexFrom, new Set())
}
if (!this._edges.has(vertexTo)) {
this._edges.set(vertexTo, new Map())
this._inNeighbors.set(vertexTo, new Set())
}
this._edges.get(vertexFrom).set(vertexTo, weight)
this._inNeighbors.get(vertexTo).add(vertexFrom)
}
findOutNeighbors(vertex) {
return new Set(this._edges.get(vertex).keys())
}
findInNeighbors(vertex) {
return new Set(this._inNeighbors.get(vertex))
}
findVertices() {
return new Set(this._edges.keys())
}
findConnectedComponents() {
const unvisited = this.findVertices()
const L = []
for (const vertex of this.findVertices()) {
this.visit(vertex, unvisited, L)
}
const components = new Map()
for (let i = L.length - 1; i >= 0; i -= 1) {
this.assign(L[i], L[i], components)
}
return components
}
visit(vertex, unvisited, L) {
if (unvisited.has(vertex)) {
unvisited.delete(vertex)
for (const neighbor of this.findOutNeighbors(vertex)) {
this.visit(neighbor, unvisited, L)
}
L.push(vertex)
}
}
assign(vertex, root, components) {
let hasBeenAssigned = false
for (const component of components.values()) {
if (component.has(vertex)) {
hasBeenAssigned = true
break
}
}
if (!hasBeenAssigned) {
if (!components.has(root)) {
components.set(root, new Set())
}
components.get(root).add(vertex)
for (const neighbor of this.findInNeighbors(vertex)) {
this.assign(neighbor, root, components)
}
}
}
}
function measureExecutionTime(f) {
const start = performance.now()
f()
return (performance.now() - start) / 1000
}
function buildGraphAndFindComponents(data) {
const graph = new Graph()
for (let i = 0; i < data.length; i += 1) {
for (let j = 0; j < data.length; j += 1) {
graph.connect(i, j, data[i][j])
}
}
return graph.findConnectedComponents()
}
function main() {
const numberExecutions = 6
const data = JSON.parse(fs.readFileSync('payload.json'))
// Run one time without measuring execution time to let the JIT compiler do
// its work
buildGraphAndFindComponents(data)
let totalElapsed = 0
for (let i = 0; i < numberExecutions; i += 1) {
const elaspedTime = measureExecutionTime(() => buildGraphAndFindComponents(data))
console.log(elaspedTime)
totalElapsed += elaspedTime
}
console.log('average: ' + (totalElapsed / numberExecutions).toFixed(2))
}
main()graph.go
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"time"
)
type Graph struct {
edges map[interface{}]map[interface{}]int
inNeighbors map[interface{}]map[interface{}]bool
expectedNodes int
}
func NewGraph(expectedNodes int) *Graph {
return &Graph{
edges: make(map[interface{}]map[interface{}]int, expectedNodes),
inNeighbors: make(map[interface{}]map[interface{}]bool, expectedNodes),
expectedNodes: expectedNodes,
}
}
func (graph *Graph) Connect(vertexFrom interface{}, vertexTo interface{}, weight int) {
if _, ok := graph.edges[vertexFrom]; !ok {
graph.edges[vertexFrom] = make(map[interface{}]int, graph.expectedNodes)
graph.inNeighbors[vertexFrom] = make(map[interface{}]bool, graph.expectedNodes)
}
if _, ok := graph.edges[vertexTo]; !ok {
graph.edges[vertexTo] = make(map[interface{}]int, graph.expectedNodes)
graph.inNeighbors[vertexTo] = make(map[interface{}]bool, graph.expectedNodes)
}
graph.edges[vertexFrom][vertexTo] = weight
graph.inNeighbors[vertexTo][vertexFrom] = true
}
func (graph *Graph) FindAllOutNeighbors(vertex interface{}) map[interface{}]bool {
keys := make(map[interface{}]bool, len(graph.edges))
for key := range graph.edges[vertex] {
keys[key] = true
}
return keys
}
func (graph *Graph) FindAllInNeighbors(vertex interface{}) map[interface{}]bool {
keys := make(map[interface{}]bool, len(graph.edges))
for key := range graph.inNeighbors[vertex] {
keys[key] = true
}
return keys
}
func (graph *Graph) FindAllVertices() map[interface{}]bool {
keys := make(map[interface{}]bool, len(graph.edges))
for key := range graph.edges {
keys[key] = true
}
return keys
}
func (graph *Graph) FindConnectedComponents() map[interface{}]map[interface{}]bool {
var visit func(interface{}, map[interface{}]bool, *[]interface{})
var assign func(interface{}, interface{}, map[interface{}]map[interface{}]bool)
visit = func(vertex interface{}, unvisited map[interface{}]bool, L *[]interface{}) {
if _, ok := unvisited[vertex]; ok {
delete(unvisited, vertex)
for neighbor := range graph.FindAllOutNeighbors(vertex) {
visit(neighbor, unvisited, L)
}
*L = append(*L, vertex)
}
}
assign = func(vertex interface{}, root interface{}, components map[interface{}]map[interface{}]bool) {
hasBeenAssigned := false
for root := range components {
if _, ok := components[root][vertex]; ok {
hasBeenAssigned = true
break
}
}
if !hasBeenAssigned {
if _, ok := components[root]; !ok {
components[root] = make(map[interface{}]bool)
}
components[root][vertex] = true
for neighbor := range graph.FindAllInNeighbors(vertex) {
assign(neighbor, root, components)
}
}
}
unvisited := graph.FindAllVertices()
L := make([]interface{}, 0, len(unvisited))
for vertex := range graph.FindAllVertices() {
visit(vertex, unvisited, &L)
}
components := make(map[interface{}]map[interface{}]bool)
for i := len(L) - 1; i >= 0; i -= 1 {
assign(L[i], L[i], components)
}
return components
}
func measureExecutionTime(f func()) time.Duration {
start := time.Now()
f()
return time.Since(start)
}
func buildGraphAndFindComponents(data [][]int) map[interface{}]map[interface{}]bool {
graph := NewGraph(len(data))
for i := range data {
for j := range data[i] {
graph.Connect(i, j, data[i][j])
}
}
return graph.FindConnectedComponents()
}
func main() {
const numberExecutions = 6
plan, _ := ioutil.ReadFile("./payload.json")
var data [][]int
err := json.Unmarshal(plan, &data)
if err == nil {
fmt.Errorf("Error: %w", err)
}
// Go doesn't have a JIT compiler, but let's do the same thing we did in JS
// anyway
buildGraphAndFindComponents(data)
var totalElapsed time.Duration
for i := 0; i < numberExecutions; i += 1 {
elaspedTime := measureExecutionTime(func() {
buildGraphAndFindComponents(data)
})
fmt.Println(elaspedTime)
totalElapsed += elaspedTime
}
fmt.Printf("average: %s\n", time.Duration(int64(totalElapsed)/int64(numberExecutions)))
}Hey guys, I have a question that needs to hear your point of view. Most US jobs for back-end I see are hiring Nodejs. Although I love Golang because it's fast and resource usage efficient. But I think the main reason is people want to code and deliver their products faster and Node.js performance is enough for them.
Hope you guys give me more insight about it. Thanks!
Many people say Nodejs is hot and high in demand and also great. However, there are also many people saying golang is faster than nodejs. I just started to learn nodejs ,but i am thinking that nodejs is not going to to be hot like rail and django. Should i learn golang for web development or nodejs?
There is no way anyone can answer that for you, other than pure personal bias. Given you've posted in the go sub, you'll get some go bias.
Node is more popular right now. No one knows what will be in high demand a year from now. Go performs better and is easier to deploy. Node has more libraries, but go has a better standard library, and third party support is growing.
You mention go is fast, and that node is popular, but those are orthogonal. Why are you learning a language at all? If it's for fun, learn what's fun to you. If it's for money, learn what has the most high paying job opportunities in your area. If it's for personal projects, learn what suits the project best.
No one but you can say what language you should learn.
If you ❤️ back end, learn go.
If you ❤️ full stack or front end, learn JS.
Full stack, in my opinion, is a siren song.
It lures developers by massaging their ego: know it all!
It lures developers by calming their fear: you'll get a job!
But it also traps you into being a jack-of-all-trades: your pay will be capped because you aren't specialized.
If you're just starting LEARN AS MUCH AS YOU CAN.
But nobody can really know it all. So when your ❤️ finds its preference, specialize and hone your skills.
As the title, I have no experience in programming. So which programming language should I choose first between these two? Since I want to become a backend developer.
I love Golang, but having heard so many good things about Javascript (like making games, front-end, backend...) and that Javascript is so trending right now, makes me also want to learn it (like with javascript you can have a more larger range of projects...).
If I choose Javascript first, later I'll have to learn Golang. Will learning Javascript first prepare me a good start to learn Golang faster, can learn Golang first provide the same benefits? Or will there be something I miss?
I also looked into the website Practical-go-lessons.com, it is very nice and well structured.
https://i.imgur.com/G59beuG.jpg
Saw this post on the NodeJS sub.
Is this something many people think? Why would you think that Go is hard to justify unless at massive scale?
Go is, in my experience, quite fast to develop with. Especially since it forces good practices and you don’t make as many stupid mistakes along the way.
Anyone agree with the OP and can explain why you think this way?