Perbandingan Command Dasar PHP vs Ruby vs Go untuk Developer Web

Jika kamu seorang developer web yang ingin menjelajahi berbagai bahasa pemrograman, memahami perintah dasar dalam PHP, Ruby, dan Go sangat penting. Artikel ini merangkum perbedaan dan persamaan command line dari ketiganya.

Menjalankan File

AksiPHPRubyGo
Menjalankan filephp file.phpruby file.rbgo run file.go

Package / Dependency Management

AksiPHPRubyGo
Inisialisasi projectcomposer initbundle init / manual Gemfilego mod init nama-module
Install packagecomposer installbundle installgo get nama-package
File dependensicomposer.jsonGemfilego.mod

Menjalankan Test

AksiPHPRubyGo
Menjalankan testphpunit (atau vendor/bin/phpunit)rspec / ruby test.rbgo test

Build Program

AksiPHPRubyGo
Compile / BuildTidak perlu (interpreted)Tidak perlu (interpreted)go build menghasilkan binary

Menjalankan Web Server Sederhana

AksiPHPRubyGo
Development serverphp -S localhost:8000ruby -run -e httpd . -p 8000Harus buat file dan go run

Contoh Go file (main.go):

package main
import ("fmt"; "net/http")
func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "Hello!")
}
func main() {
    http.HandleFunc("/", handler)
    http.ListenAndServe(":8000", nil)
}

Print ke Terminal

AksiPHPRubyGo
Print ke terminalecho "Hello";puts "Hello"fmt.Println("Hello")

Cek Versi

AksiPHPRubyGo
Cek versiphp -vruby -vgo version

Kesimpulan Singkat

BahasaTipePackage ManagerKompilasiFokus
PHPInterpretedComposerTidakWeb scripting
RubyInterpretedBundlerTidakWeb (Rails), scripting
GoCompiledGo modulesYaBackend, performance