From 70827fe44d6844528e7dd56637de2f0f3e0cf847 Mon Sep 17 00:00:00 2001 From: Akshay Date: Sat, 1 Aug 2020 17:25:39 +0530 Subject: update irc nick, publish post --- docs/posts/WPA_woes/index.html | 2 +- docs/posts/auto-currying_rust_functions/index.html | 2 +- docs/posts/bash_harder_with_vim/index.html | 2 +- docs/posts/bye_bye_BDFs/index.html | 2 +- docs/posts/call_to_ARMs/index.html | 2 +- docs/posts/color_conundrum/index.html | 2 +- docs/posts/font_size_fallacies/index.html | 2 +- .../index.html | 2 +- docs/posts/gripes_with_go/index.html | 173 +++++++++++++++++++++ docs/posts/hold_position!/index.html | 2 +- docs/posts/my_setup/index.html | 2 +- docs/posts/onivim_sucks/index.html | 2 +- docs/posts/pixel_art_in_GIMP/index.html | 2 +- docs/posts/rapid_refactoring_with_vim/index.html | 2 +- docs/posts/static_sites_with_bash/index.html | 2 +- docs/posts/termux_tandem/index.html | 2 +- docs/posts/turing_complete_type_systems/index.html | 2 +- 17 files changed, 189 insertions(+), 16 deletions(-) create mode 100644 docs/posts/gripes_with_go/index.html (limited to 'docs/posts') diff --git a/docs/posts/WPA_woes/index.html b/docs/posts/WPA_woes/index.html index 0c50385..5121434 100644 --- a/docs/posts/WPA_woes/index.html +++ b/docs/posts/WPA_woes/index.html @@ -76,7 +76,7 @@ $ sudo sv restart dhcpcd I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer. I write open-source stuff to pass time. I also design fonts: scientifica, curie.

-

Send me a mail at nerdy@peppe.rs or a message at nerd@irc.rizon.net.

+

Send me a mail at nerdy@peppe.rs or a message at nerdypepper@irc.rizon.net.

⟵ Back diff --git a/docs/posts/auto-currying_rust_functions/index.html b/docs/posts/auto-currying_rust_functions/index.html index a86667c..62f92bc 100644 --- a/docs/posts/auto-currying_rust_functions/index.html +++ b/docs/posts/auto-currying_rust_functions/index.html @@ -540,7 +540,7 @@ test tests::works ... ok I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer. I write open-source stuff to pass time. I also design fonts: scientifica, curie.

-

Send me a mail at nerdy@peppe.rs or a message at nerd@irc.rizon.net.

+

Send me a mail at nerdy@peppe.rs or a message at nerdypepper@irc.rizon.net.

⟵ Back diff --git a/docs/posts/bash_harder_with_vim/index.html b/docs/posts/bash_harder_with_vim/index.html index 7c9e5d6..303880d 100644 --- a/docs/posts/bash_harder_with_vim/index.html +++ b/docs/posts/bash_harder_with_vim/index.html @@ -86,7 +86,7 @@ Press ENTER or type command to continue I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer. I write open-source stuff to pass time. I also design fonts: scientifica, curie.

-

Send me a mail at nerdy@peppe.rs or a message at nerd@irc.rizon.net.

+

Send me a mail at nerdy@peppe.rs or a message at nerdypepper@irc.rizon.net.

⟵ Back diff --git a/docs/posts/bye_bye_BDFs/index.html b/docs/posts/bye_bye_BDFs/index.html index a2e410d..43d2dfd 100644 --- a/docs/posts/bye_bye_BDFs/index.html +++ b/docs/posts/bye_bye_BDFs/index.html @@ -58,7 +58,7 @@ I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer. I write open-source stuff to pass time. I also design fonts: scientifica, curie.

-

Send me a mail at nerdy@peppe.rs or a message at nerd@irc.rizon.net.

+

Send me a mail at nerdy@peppe.rs or a message at nerdypepper@irc.rizon.net.

⟵ Back diff --git a/docs/posts/call_to_ARMs/index.html b/docs/posts/call_to_ARMs/index.html index f882e6b..a05ed38 100644 --- a/docs/posts/call_to_ARMs/index.html +++ b/docs/posts/call_to_ARMs/index.html @@ -83,7 +83,7 @@ Reading symbols from main... # yay! I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer. I write open-source stuff to pass time. I also design fonts: scientifica, curie.

-

Send me a mail at nerdy@peppe.rs or a message at nerd@irc.rizon.net.

+

Send me a mail at nerdy@peppe.rs or a message at nerdypepper@irc.rizon.net.

⟵ Back diff --git a/docs/posts/color_conundrum/index.html b/docs/posts/color_conundrum/index.html index 0ba7aa5..c7db8cd 100644 --- a/docs/posts/color_conundrum/index.html +++ b/docs/posts/color_conundrum/index.html @@ -60,7 +60,7 @@ I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer. I write open-source stuff to pass time. I also design fonts: scientifica, curie.

-

Send me a mail at nerdy@peppe.rs or a message at nerd@irc.rizon.net.

+

Send me a mail at nerdy@peppe.rs or a message at nerdypepper@irc.rizon.net.

⟵ Back diff --git a/docs/posts/font_size_fallacies/index.html b/docs/posts/font_size_fallacies/index.html index c91eba5..af55661 100644 --- a/docs/posts/font_size_fallacies/index.html +++ b/docs/posts/font_size_fallacies/index.html @@ -82,7 +82,7 @@ Dimensions: 1920x1080 @ 13" (29.5x16.5 sq. cm) I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer. I write open-source stuff to pass time. I also design fonts: scientifica, curie.

-

Send me a mail at nerdy@peppe.rs or a message at nerd@irc.rizon.net.

+

Send me a mail at nerdy@peppe.rs or a message at nerdypepper@irc.rizon.net.

⟵ Back diff --git a/docs/posts/get_better_at_yanking_and_putting_in_vim/index.html b/docs/posts/get_better_at_yanking_and_putting_in_vim/index.html index a009a15..e02f5d2 100644 --- a/docs/posts/get_better_at_yanking_and_putting_in_vim/index.html +++ b/docs/posts/get_better_at_yanking_and_putting_in_vim/index.html @@ -69,7 +69,7 @@ nnoremap gb `[v`] " "a quick map to perform the above< I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer. I write open-source stuff to pass time. I also design fonts: scientifica, curie.

-

Send me a mail at nerdy@peppe.rs or a message at nerd@irc.rizon.net.

+

Send me a mail at nerdy@peppe.rs or a message at nerdypepper@irc.rizon.net.

⟵ Back diff --git a/docs/posts/gripes_with_go/index.html b/docs/posts/gripes_with_go/index.html new file mode 100644 index 0000000..b527b4a --- /dev/null +++ b/docs/posts/gripes_with_go/index.html @@ -0,0 +1,173 @@ + + + + + + + + + + + + + + + Gripes With Go · peppe.rs + +
+
+ ⟵ Back + View Raw +
+
+ 01/08 — 2020 +
+ + 76.71 + + cm +   + + 4.9 + + min +
+
+

+ Gripes With Go +

+
+

You’ve read a lot of posts about the shortcomings of the Go programming language, so what’s one more.

+
    +
  1. Lack of sum types
  2. +
  3. Type assertions
  4. +
  5. Date and Time
  6. +
  7. Statements over Expressions
  8. +
  9. Erroring out on unused variables
  10. +
  11. Error handling
  12. +
+

Lack of Sum types

+

A “Sum” type is a data type that can hold one of many states at a given time, similar to how a boolean can hold a true or a false, not too different from an enum type in C. Go lacks enum types unfortunately, and you are forced to resort to crafting your own substitute.

+

A type to represent gender for example:

+
type Gender int
+
+const (
+    Male Gender = iota  // assigns Male to 0
+    Female              // assigns Female to 1
+    Other               // assigns Other to 2
+)
+
+fmt.Println("My gender is ", Male)
+// My gender is 0
+// Oops! We have to implement String() for Gender ...
+
+func (g Gender) String() string {
+    switch (g) {
+    case 0: return "Male"
+    case 1: return "Female"
+    default: return "Other"
+    }
+}
+
+// You can accidentally do stupid stuff like:
+gender := Male + 1
+

The Haskell equivalent of the same:

+
data Gender = Male
+            | Female
+            | Other
+            deriving (Show)
+
+print $ "My gender is " ++ (show Male)
+

Type Assertions

+

A downcast with an optional error check? What could go wrong?

+

Type assertions in Go allow you to do:

+
var x interface{} = 7
+y, goodToGo := x.(int)
+if goodToGo {
+    fmt.Println(y)
+}
+

The error check however is optional:

+
var x interface{} = 7
+var y := x.(float64)
+fmt.Println(y)
+// results in a runtime error:
+// panic: interface conversion: interface {} is int, not float64
+

Date and Time

+

Anyone that has written Go previously, will probably already know what I am getting at here. For the uninitiated, parsing and formatting dates in Go requires a “layout”. This “layout” is based on magical reference date:

+
Mon Jan 2 15:04:05 MST 2006
+

Which is the date produced when you write the first seven natural numbers like so:

+
01/02 03:04:05 '06 -0700
+

Parsing a string in YYYY-MM-DD format would look something like:

+
const layout = "2006-01-02"
+time.Parse(layout, "2020-08-01")
+

This so-called “intuitive” method of formatting dates doesn’t allow you to print 0000 hrs as 2400 hrs, it doesn’t allow you to omit the leading zero in 24 hour formats. It is rife with inconveniences, if only there were a tried and tested date formatting convention …

+

Statements over Expressions

+

Statements have side effects, expressions return values. More often than not, expressions are easier to understand at a glance: evaluate the LHS and assign the same to the RHS.

+

Rust allows you to create local namespaces, and treats blocks ({}) as expressions:

+
let twenty_seven = {
+    let three = 1 + 2;
+    let nine = three * three;
+    nine * three
+};
+

The Go equivalent of the same:

+
twenty_seven := nil
+
+three := 1 + 2
+nine := three * three
+twenty_seven = nine * three
+

Erroring out on unused variables

+

Want to quickly prototype something? Go says no! In all seriousness, a warning would suffice, I don’t want to have to go back and comment each unused import out, only to come back and uncomment them a few seconds later.

+

Error handling

+
if err != nil { ... }
+

Need I say more? I will, for good measure:

+
    +
  1. Error handling is optional
  2. +
  3. Errors are propagated via a clunky if + return statement
  4. +
+

I prefer Haskell’s “Monadic” error handling, which is employed by Rust as well:

+
// 1. error handling is compulsory
+// 2. errors are propagated with the `?` operator
+fn foo() -> Result<String, io::Error> {
+    let mut f = File::open("foo.txt")?; // return if error
+    let mut s = String::new();
+
+    f.read_to_string(&mut s)?; // return if error
+
+    Ok(s) // all good, return a string inside a `Result` context
+}
+
+fn main() {
+    // `contents` is an enum known as Result:
+    let contents = foo();
+    match contents {
+        Ok(c) => println!(c),
+        Err(e) => eprintln!(e)
+    }
+}
+

Conclusion

+

I did not want to conclude without talking about stylistic choices, lack of metaprogramming, bizzare export rules, but, I am too busy converting my interface{} types into actual generic code for Go v2.

+ +
+ +
+ Hi. + +

I'm Akshay, I go by nerd or nerdypepper on the internet.

+

+ I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer. + I write open-source stuff to pass time. I also design fonts: scientifica, curie. +

+

Send me a mail at nerdy@peppe.rs or a message at nerdypepper@irc.rizon.net.

+
+ + ⟵ Back + View Raw +
+
+ + diff --git a/docs/posts/hold_position!/index.html b/docs/posts/hold_position!/index.html index 61e4768..8948370 100644 --- a/docs/posts/hold_position!/index.html +++ b/docs/posts/hold_position!/index.html @@ -60,7 +60,7 @@ winrestview(view) " restore our original view! I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer. I write open-source stuff to pass time. I also design fonts: scientifica, curie.

-

Send me a mail at nerdy@peppe.rs or a message at nerd@irc.rizon.net.

+

Send me a mail at nerdy@peppe.rs or a message at nerdypepper@irc.rizon.net.

⟵ Back diff --git a/docs/posts/my_setup/index.html b/docs/posts/my_setup/index.html index 996a459..c24c765 100644 --- a/docs/posts/my_setup/index.html +++ b/docs/posts/my_setup/index.html @@ -58,7 +58,7 @@ I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer. I write open-source stuff to pass time. I also design fonts: scientifica, curie.

-

Send me a mail at nerdy@peppe.rs or a message at nerd@irc.rizon.net.

+

Send me a mail at nerdy@peppe.rs or a message at nerdypepper@irc.rizon.net.

⟵ Back diff --git a/docs/posts/onivim_sucks/index.html b/docs/posts/onivim_sucks/index.html index ded6fd9..1549e3e 100644 --- a/docs/posts/onivim_sucks/index.html +++ b/docs/posts/onivim_sucks/index.html @@ -57,7 +57,7 @@ I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer. I write open-source stuff to pass time. I also design fonts: scientifica, curie.

-

Send me a mail at nerdy@peppe.rs or a message at nerd@irc.rizon.net.

+

Send me a mail at nerdy@peppe.rs or a message at nerdypepper@irc.rizon.net.

⟵ Back diff --git a/docs/posts/pixel_art_in_GIMP/index.html b/docs/posts/pixel_art_in_GIMP/index.html index e6661b2..f767de8 100644 --- a/docs/posts/pixel_art_in_GIMP/index.html +++ b/docs/posts/pixel_art_in_GIMP/index.html @@ -101,7 +101,7 @@ I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer. I write open-source stuff to pass time. I also design fonts: scientifica, curie.

-

Send me a mail at nerdy@peppe.rs or a message at nerd@irc.rizon.net.

+

Send me a mail at nerdy@peppe.rs or a message at nerdypepper@irc.rizon.net.

⟵ Back diff --git a/docs/posts/rapid_refactoring_with_vim/index.html b/docs/posts/rapid_refactoring_with_vim/index.html index ee05dc0..b0ed0ad 100644 --- a/docs/posts/rapid_refactoring_with_vim/index.html +++ b/docs/posts/rapid_refactoring_with_vim/index.html @@ -141,7 +141,7 @@ BUFFER: json!( ... ); I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer. I write open-source stuff to pass time. I also design fonts: scientifica, curie.

-

Send me a mail at nerdy@peppe.rs or a message at nerd@irc.rizon.net.

+

Send me a mail at nerdy@peppe.rs or a message at nerdypepper@irc.rizon.net.

⟵ Back diff --git a/docs/posts/static_sites_with_bash/index.html b/docs/posts/static_sites_with_bash/index.html index b2a90a7..80bfe37 100644 --- a/docs/posts/static_sites_with_bash/index.html +++ b/docs/posts/static_sites_with_bash/index.html @@ -79,7 +79,7 @@ I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer. I write open-source stuff to pass time. I also design fonts: scientifica, curie.

-

Send me a mail at nerdy@peppe.rs or a message at nerd@irc.rizon.net.

+

Send me a mail at nerdy@peppe.rs or a message at nerdypepper@irc.rizon.net.

⟵ Back diff --git a/docs/posts/termux_tandem/index.html b/docs/posts/termux_tandem/index.html index b4818cf..37088bb 100644 --- a/docs/posts/termux_tandem/index.html +++ b/docs/posts/termux_tandem/index.html @@ -70,7 +70,7 @@ mtZabXG.jpg p8d5c584f2841.jpg vjUxGjq.jpg I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer. I write open-source stuff to pass time. I also design fonts: scientifica, curie.

-

Send me a mail at nerdy@peppe.rs or a message at nerd@irc.rizon.net.

+

Send me a mail at nerdy@peppe.rs or a message at nerdypepper@irc.rizon.net.

⟵ Back diff --git a/docs/posts/turing_complete_type_systems/index.html b/docs/posts/turing_complete_type_systems/index.html index 3e572e3..cc51210 100644 --- a/docs/posts/turing_complete_type_systems/index.html +++ b/docs/posts/turing_complete_type_systems/index.html @@ -61,7 +61,7 @@ I am a compsci undergrad, Rust programmer and an enthusiastic Vimmer. I write open-source stuff to pass time. I also design fonts: scientifica, curie.

-

Send me a mail at nerdy@peppe.rs or a message at nerd@irc.rizon.net.

+

Send me a mail at nerdy@peppe.rs or a message at nerdypepper@irc.rizon.net.

⟵ Back -- cgit v1.2.3