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

The Advantage of Using HTTP Default Authorization Scheme #DigitalSecurity

pixabay.com Hello Everyone, This day I would like to introduce you to the default header for authorization in HTTP. HTTP auth scheme is a guide or standardization scheme for the authorization header in the HTTP protocol. this standard is using key Authorization in the header and followed by a value that usually filled by key or token. for example : Authorization : <type> <key/token> this standard is the solution of the key header for authorization that really random was provided by developers to build an authorization header for their application, in my experience, developers used to "token" for their key in the header that usually followed by the hash value. the random key makes developers using more time for writing code for getting header key and validating the value which is you could use the library and focus on writing the logic of your application. Depend on Mozilla site , HTTP auth scheme divided by 4 types, such as : Basic  (see  RF

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, model

Automatic API Documentation Swagger in Golang #GolangDev

pixabay.com In this article, I'll explain how to generate an API blueprint instantly using SwagGo in Golang. API blueprint is a document that contains a bunch of API endpoints, its slickly same as documentation but less description, it's allow another programmer to read and see all the available endpoint and try it out with sandbox feature. Swagger is one of the most used API blueprints right now, it's available in free but limited usage. if you wanna use the free credit, you need to understand YAML notation, you can read the example notation in swagger official documentation. but again, it's really hard and takes an expensive time to arranges all the notation to achieve a good API blueprint. fortunately, there are tools in Golang that allow us to generate the YAML notation and automatically generate the blueprint page with only using markup notation, and it's FREE unlimited for self-host, insane right? SwagGo tools are available here , the documentation is very cl