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
| Aksi | PHP | Ruby | Go |
|---|---|---|---|
| Menjalankan file | php file.php | ruby file.rb | go run file.go |
Package / Dependency Management
| Aksi | PHP | Ruby | Go |
|---|---|---|---|
| Inisialisasi project | composer init | bundle init / manual Gemfile | go mod init nama-module |
| Install package | composer install | bundle install | go get nama-package |
| File dependensi | composer.json | Gemfile | go.mod |
Menjalankan Test
| Aksi | PHP | Ruby | Go |
|---|---|---|---|
| Menjalankan test | phpunit (atau vendor/bin/phpunit) | rspec / ruby test.rb | go test |
Build Program
| Aksi | PHP | Ruby | Go |
|---|---|---|---|
| Compile / Build | Tidak perlu (interpreted) | Tidak perlu (interpreted) | go build menghasilkan binary |
Menjalankan Web Server Sederhana
| Aksi | PHP | Ruby | Go |
|---|---|---|---|
| Development server | php -S localhost:8000 | ruby -run -e httpd . -p 8000 | Harus 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
| Aksi | PHP | Ruby | Go |
|---|---|---|---|
| Print ke terminal | echo "Hello"; | puts "Hello" | fmt.Println("Hello") |
Cek Versi
| Aksi | PHP | Ruby | Go |
|---|---|---|---|
| Cek versi | php -v | ruby -v | go version |
Kesimpulan Singkat
| Bahasa | Tipe | Package Manager | Kompilasi | Fokus |
|---|---|---|---|---|
| PHP | Interpreted | Composer | Tidak | Web scripting |
| Ruby | Interpreted | Bundler | Tidak | Web (Rails), scripting |
| Go | Compiled | Go modules | Ya | Backend, performance |