Skip to main content

How Strict is Golang? #GolangDev

pixabay.com


Hello everyone, in this occasion I would like to share about the strictness of golang. what kind of strict? let see below.

Golang is the functional programming that really have concern about performance, giving limitation to prevent overuse memory is the big deal. for example, golang has a variative type of data such as int, string, boolean, float, array etc. I wonder that you are thinking about "what kind of strictness that is? its totally similar other language", YES. but golang have specification in numeric type of data such as int have int8, int16, int32, int64. golang also have uint8, uint8, uint32 and uint64 which is its really strict you know. the following number after type of data is stand for the length. Obviously you could use the largest type of data for all the variables, but you know it could overwhelming if you put int64 in "is_valid" variable right? joking :D. golang really care about performance, because each length of variable is matters for memory.

yes! golang its totally directing you to put type of data according to the length. the more you strict about the type of data, the more your apps got faster. 

but in the other side, golang also have flexible type of data, like Any in Swift. you could put a lot of values in variable, its called null interface data type. I know its weird, I totally agree with you, but you know thank god for this type, because we need flexibility also in some cases. such as dealing with JSON or Dictionary values, you can't use other data type instead of interface, maybe you can use array or slice but you need put the seem data type for each key n values. for example .

in above example, you put all the data type as string, it's totally works but "age" key is belongs to numeric data type right? and you unable to do that if you are only using array or slice, that's why we need interface this time. for example


in above example, you could see the example of using null interface data type, we finally enable to put the right data type for "age" keysee the output below.


you could use interface for any kind of cases but it's totally not recommended, because you could ruin the performance. I recommend you only using interface if dealing with Dictionary or JSON cases.

Conclusion

Golang is totally strict language, but it's not a drawback cause the main purposes is to keep the best performance for your apps and not overusing memory. but golang also have flexible data type called null interface, but you are not recommending to put it in all variable you define, it's only use for Dictionary or JSON values.

Popular posts from this blog

Laravel Tips : Membuat Model, Migration dan Controller dengan Sekali Jalan

  php artisan adalah generator laravel yang berfungsi untuk membuat file kodingan dengan mudah, seperti membuat controller, model, seeder, migration dan masih banyak lagi. artisan hanya bisa di lakukan di dalam lingkungan console, seperti cmd dan terminal. berikut akan saya tunjukan cara membuat controller, model, migration menggunakan php artisan. # membuat controller ketikkan perintah di bawah ini php artisan make:controller BlogController # membuat model ketikkan perintah di bawah ini php artisan make:model Blog # membuat migration ketikkan perintah di bawah ini php artisan make:migration blog # membuat seeder ketikkan perintah di bawah ini php artisan make:seeder BlogSeeder # membuat migration, controller, dan model sekaligus ketikkan perintah di bawah ini php artisan make:model -crm Blog perintah di atas akan mengenerate controller dengan nama BlogController dengan keadaan Resource method tertulis, m...

Mengapa .env File Laravel Tidak Terupload / Tercommit ke Git

.env file atau bisa kita bilang "environment file" atau file yang berisi variable constan untuk memberikan value secara global ke dalam aplikasi kita. file ini berisi variable dan value yang sensitif yang membuatnya sangat riskan atau beresiko apabila di ketahui oleh orang yang tidak bertanggung jawab. contoh  seperti berikut ini file .env di atas memiliki informasi sensitif seperti host, user dan password dari database kita. maka dari itu kita sebagai developer harus pintar-pintar untuk memperlakukan .env file ini, secara default apabila kita upload ke hosting atau vps file .env ini tidak akan bisa di akses secara global dari host kita, karna letak root host kita ada di folder public yang notabene berada di satu level ke atas folder dari posisi .env. jadi user awam tidak akan bisa mengakses dari host kita eg : http://angon.dev/.env . nah kalo ke git gmn? apabila kita menggunakan version controller seperti github, gitlab, bitbucket. secara default git akan mem...

Duplicate file remover FULL

kita pasti pernah menyimpan file yang pnting, sangking pntngnya, kita sampai menyimpannya berkali2, atau menyimpan sekali tetapi mengkopinya berkali2.. software ini berfungsi mendelete semua file yang mempunyai duplikat, bagi yang mau, silahkan download disini