Live data from Hacker News

What programming languages are used late at night?

stackoverflow.blog

231–240 of 244 posts

Re: What programming languages are used late at night?

#231
post #226

Earlier quoted context omitted.

I think it's mostly that I need to write it so little, that I never get to become proficient "enough" with it. There is little motivation to invest hours to learn it properly, because a) I get to write bash scripts so little that b) I would forgot half by next time I use it. I think I'm basically stuck on the worst part of learning curve. Btw I use console for pretty much everything from git shell to vim. But when I…

I see. Okay, well, here's how I'd respond to what you've said. The fact that you're already in the console puts you in a pretty good position: now you just need to stay there whenever you perform complex tasks. I have very few bash scripts myself (the little code I actually have saved is scattered everywhere ; most of my scripts are on some disks that are offline at the moment). Rather, I primarily use the shell as a…

I only have about 20 extra minutes, but I'll see if I can give a Haskell version for comparison.

Re: What programming languages are used late at night?

#232
post #226

Earlier quoted context omitted.

I see. Okay, well, here's how I'd respond to what you've said. The fact that you're already in the console puts you in a pretty good position: now you just need to stay there whenever you perform complex tasks. I have very few bash scripts myself (the little code I actually have saved is scattered everywhere ; most of my scripts are on some disks that are offline at the moment). Rather, I primarily use the shell as a…

I only have about 20 extra minutes, but I'll see if I can give a Haskell version for comparison.

Oh, okay! Cool!!

I've had Haskell on my todo list for a little while actually.

Re: What programming languages are used late at night?

#233
post #226

Earlier quoted context omitted.

I think it's mostly that I need to write it so little, that I never get to become proficient "enough" with it. There is little motivation to invest hours to learn it properly, because a) I get to write bash scripts so little that b) I would forgot half by next time I use it. I think I'm basically stuck on the worst part of learning curve. Btw I use console for pretty much everything from git shell to vim. But when I…

I see. Okay, well, here's how I'd respond to what you've said. The fact that you're already in the console puts you in a pretty good position: now you just need to stay there whenever you perform complex tasks. I have very few bash scripts myself (the little code I actually have saved is scattered everywhere ; most of my scripts are on some disks that are offline at the moment). Rather, I primarily use the shell as a…

Well it's 51 minutes later, and I got to the third bullet point :D

EDIT: I tried to focus on readability here. Things could be quite a bit more concise but that requires firmer grasp of interactions between >>=, , and point-free functions.

Here's what I have so far:

    {-# LANGUAGE OverloadedStrings #-}
    module Main where
    
    import Prelude hiding (appendFile)
    import Data.Monoid (())
    import Network.Wreq
    import Control.Lens
    import Control.Concurrent.Async
    import Data.ByteString.Lazy (ByteString, appendFile)
    
    main = do
      urls  (take 5 url, body)) (zip urls responseBodys)
          httpUrls = filter (\(url,_) -> url == "http:") responseInfos
          httpsUrls = filter (\(url,_) -> url == "https") responseInfos
      mapM_ (appendFile "output1.txt") httpUrls
      exampleSiteResponses  IO [String]
            go urls = do
              line  [line]) -- lol, this is a very bad way to snoc

Re: What programming languages are used late at night?

#234
post #226

Earlier quoted context omitted.

I see. Okay, well, here's how I'd respond to what you've said. The fact that you're already in the console puts you in a pretty good position: now you just need to stay there whenever you perform complex tasks. I have very few bash scripts myself (the little code I actually have saved is scattered everywhere ; most of my scripts are on some disks that are offline at the moment). Rather, I primarily use the shell as a…

Well it's 51 minutes later, and I got to the third bullet point :D EDIT: I tried to focus on readability here. Things could be quite a bit more concise but that requires firmer grasp of interactions between >>=, , and point-free functions. Here's what I have so far: {-# LANGUAGE OverloadedStrings #-} module Main where import Prelude hiding (appendFile) import Data.Monoid (( )) import Network.Wreq import Control.Lens…

And surprisingly, I can actually follow it. (I have that thing where people say "yeah I can read this but don't expect me to write it" right now though...)

This is very interesting. Does Haskell not have reasonably easy-to-use EOF indication?

I'm reasonably impressed this is as short as it is; being able to shove everything into maps (and get concurrency for free) is nice.

I can understand why Haskell is less widely used though; this is... OH, "take 5" is substring, that's why you did "http:" and "https"!

...I was going to say "hard". :P

Thanks for taking the time to write this!!

Re: What programming languages are used late at night?

#235
post #226

Earlier quoted context omitted.

I see. Okay, well, here's how I'd respond to what you've said. The fact that you're already in the console puts you in a pretty good position: now you just need to stay there whenever you perform complex tasks. I have very few bash scripts myself (the little code I actually have saved is scattered everywhere ; most of my scripts are on some disks that are offline at the moment). Rather, I primarily use the shell as a…

Well it's 51 minutes later, and I got to the third bullet point :D EDIT: I tried to focus on readability here. Things could be quite a bit more concise but that requires firmer grasp of interactions between >>=, , and point-free functions. Here's what I have so far: {-# LANGUAGE OverloadedStrings #-} module Main where import Prelude hiding (appendFile) import Data.Monoid (( )) import Network.Wreq import Control.Lens…

Eh, I had a mistake.

    {-# LANGUAGE OverloadedStrings #-}
    module Main where
    
    import Prelude hiding (appendFile)
    import Data.Monoid (())
    import Network.Wreq
    import Control.Lens
    import Control.Concurrent.Async
    import Data.ByteString.Lazy (ByteString, appendFile)
    
    main = do
      urls  (take 5 url, body)) (zip urls responseBodys)
          httpUrls = fmap fst (filter (\(url,_) -> url == "http:") responseInfos)
          httpsResponses = fmap snd (filter (\(url,_) -> url == "https") responseInfos)
      mapM_ (appendFile "output1.txt") httpsResponses
      exampleSiteResponses  IO [String]
            go urls = do
              line  [line]) -- lol, this is a very bad way to snoc

Re: What programming languages are used late at night?

#236

Earlier quoted context omitted.

Well it's 51 minutes later, and I got to the third bullet point :D EDIT: I tried to focus on readability here. Things could be quite a bit more concise but that requires firmer grasp of interactions between >>=, , and point-free functions. Here's what I have so far: {-# LANGUAGE OverloadedStrings #-} module Main where import Prelude hiding (appendFile) import Data.Monoid (( )) import Network.Wreq import Control.Lens…

Eh, I had a mistake. {-# LANGUAGE OverloadedStrings #-} module Main where import Prelude hiding (appendFile) import Data.Monoid (( )) import Network.Wreq import Control.Lens import Control.Concurrent.Async import Data.ByteString.Lazy (ByteString, appendFile) main = do urls (take 5 url, body)) (zip urls responseBodys) httpUrls = fmap fst (filter (\(url,_) -> url == "http:") responseInfos) httpsResponses = fmap snd (fi…

Huh. So Haskell is the language of the missing apostrophe instead of the missing semicolon. (In all fairness, so is Lisp, but it puts the apostrophes on the other side.)

I'm curious about "(zip urls response" though. Does that extend to the "responseInfos)" on the next line, or am I reading it wrong?

(I noticed the "fmap fst" and "fmap snd".)

Wonders where to start to figure out how this works

Re: What programming languages are used late at night?

#237
post #226

Earlier quoted context omitted.

I think it's mostly that I need to write it so little, that I never get to become proficient "enough" with it. There is little motivation to invest hours to learn it properly, because a) I get to write bash scripts so little that b) I would forgot half by next time I use it. I think I'm basically stuck on the worst part of learning curve. Btw I use console for pretty much everything from git shell to vim. But when I…

I see. Okay, well, here's how I'd respond to what you've said. The fact that you're already in the console puts you in a pretty good position: now you just need to stay there whenever you perform complex tasks. I have very few bash scripts myself (the little code I actually have saved is scattered everywhere ; most of my scripts are on some disks that are offline at the moment). Rather, I primarily use the shell as a…

I made a more compact version closer to what I might write in a hurry.

    {-# LANGUAGE OverloadedStrings #-}
    module Main where
    
    import Prelude hiding (appendFile)
    import Data.Monoid (())
    import Network.Wreq
    import Control.Lens
    import Control.Concurrent.Async
    import Data.ByteString.Lazy (ByteString, appendFile)
    import Data.List
    
    main = do
      urls >= mapM_ (appendFile "output2.txt" . view responseBody)
    
    promptUserURLs :: IO [String]
    promptUserURLs = go []
      where go :: [String] -> IO [String]
            go urls = do
              line  [line]) -- lol, this is a very bad way to snoc

NOTE: To make this faster I create a custom Library that re-exports these common pieces. So for me I'd erase those 7 lines of imports and trade them for one. It also has something like promptUserURLs already there. So in that case it looks like:

    {-# LANGUAGE OverloadedStrings #-}
    module Main where
    
    import QuickScriptLibrary
    
    main = do
      urls >= mapM_ (appendFile "output2.txt" . view responseBody)

Re: What programming languages are used late at night?

#238
post #226

Earlier quoted context omitted.

I see. Okay, well, here's how I'd respond to what you've said. The fact that you're already in the console puts you in a pretty good position: now you just need to stay there whenever you perform complex tasks. I have very few bash scripts myself (the little code I actually have saved is scattered everywhere ; most of my scripts are on some disks that are offline at the moment). Rather, I primarily use the shell as a…

I made a more compact version closer to what I might write in a hurry. {-# LANGUAGE OverloadedStrings #-} module Main where import Prelude hiding (appendFile) import Data.Monoid (( )) import Network.Wreq import Control.Lens import Control.Concurrent.Async import Data.ByteString.Lazy (ByteString, appendFile) import Data.List main = do urls >= mapM_ (appendFile "output2.txt" . view responseBody) promptUserURLs :: IO [S…

Wow. Interesting. This is really cool, being able to learn like this :3

I must admit I have so many questions, like what the dot does, what fst and snd and >>= and OverloadedStrings and zip do... :)

Oh, and what "snoc" means.

Re: What programming languages are used late at night?

#239
post #236

Earlier quoted context omitted.

Eh, I had a mistake. {-# LANGUAGE OverloadedStrings #-} module Main where import Prelude hiding (appendFile) import Data.Monoid (( )) import Network.Wreq import Control.Lens import Control.Concurrent.Async import Data.ByteString.Lazy (ByteString, appendFile) main = do urls (take 5 url, body)) (zip urls responseBodys) httpUrls = fmap fst (filter (\(url,_) -> url == "http:") responseInfos) httpsResponses = fmap snd (fi…

Huh. So Haskell is the language of the missing apostrophe instead of the missing semicolon. (In all fairness, so is Lisp, but it puts the apostrophes on the other side.) I'm curious about "(zip urls response" though. Does that extend to the "responseInfos)" on the next line, or am I reading it wrong? (I noticed the "fmap fst" and "fmap snd".) Wonders where to start to figure out how this works

Yep, I've missed apostrophe's quite a few times. It's was a common cause of infinite loops for me in the past, but I suppose I've trained myself to spot them more quickly.

Perhaps zip can be more simply explained by a simple example:

    out: zip ["a","b","c"] [0,1,2]
    out: [("a",0),("b",1),("c",2)]

    out: fmap fst [(0,1),(2,3),(4,5)]
    out: [0,2,4]

    out: fmap snd [(0,1),(2,3),(4,5)]
    out: [1,3,5]

Re: What programming languages are used late at night?

#240
post #236

Earlier quoted context omitted.

Huh. So Haskell is the language of the missing apostrophe instead of the missing semicolon. (In all fairness, so is Lisp, but it puts the apostrophes on the other side.) I'm curious about "(zip urls response" though. Does that extend to the "responseInfos)" on the next line, or am I reading it wrong? (I noticed the "fmap fst" and "fmap snd".) Wonders where to start to figure out how this works

Yep, I've missed apostrophe's quite a few times. It's was a common cause of infinite loops for me in the past, but I suppose I've trained myself to spot them more quickly. Perhaps zip can be more simply explained by a simple example: out: zip ["a","b","c"] [0,1,2] out: [("a",0),("b",1),("c",2)] out: fmap fst [(0,1),(2,3),(4,5)] out: [0,2,4] out: fmap snd [(0,1),(2,3),(4,5)] out: [1,3,5]

Ohhhhh. zip is cool! And I wondered whether "fst" was "first" and "snd" was "second"... is there a "trd" and "fth"?

Also - is [] a list (or mixed type) and () an array (or same-item type)?

Post reply on HN