Click here to Skip to main content
15,887,214 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: What's the Most Concise, Human-Understandable Practical Language? Pin
Richard Deeming18-May-20 1:33
mveRichard Deeming18-May-20 1:33 
GeneralRe: What's the Most Concise, Human-Understandable Practical Language? Pin
kalberts18-May-20 4:30
kalberts18-May-20 4:30 
GeneralRe: What's the Most Concise, Human-Understandable Practical Language? Pin
Richard Deeming18-May-20 4:39
mveRichard Deeming18-May-20 4:39 
GeneralRe: What's the Most Concise, Human-Understandable Practical Language? Pin
kalberts18-May-20 20:59
kalberts18-May-20 20:59 
GeneralRe: What's the Most Concise, Human-Understandable Practical Language? Pin
Richard Deeming18-May-20 23:40
mveRichard Deeming18-May-20 23:40 
GeneralRe: What's the Most Concise, Human-Understandable Practical Language? Pin
kalberts19-May-20 6:55
kalberts19-May-20 6:55 
GeneralRe: What's the Most Concise, Human-Understandable Practical Language? Pin
Richard Deeming19-May-20 7:31
mveRichard Deeming19-May-20 7:31 
AnswerRe: What's the Most Concise, Human-Understandable Practical Language? Pin
Stuart Dootson18-May-20 0:59
professionalStuart Dootson18-May-20 0:59 
Javascript is obviously dynamically typed - but as I gravitate towards statically typed languages, I'll go for a language like Ocaml, Haskell or F#. They all define record types similarly, but with slightly different keywords and syntax.

I'll give an example in Haskell:
haskell
data Location = Location { city :: String }
let home = Location { city = "Boston" }

and F#
F#
type Location = { City : string }
let home = Location { City = "Boston" }

// Or we can use anonymous records....
let other_home = {| City = "Boston" |}

johnywhy wrote:
I mean, easy to understand at a glance.

I find Haskell's syntax pretty clear for pure functions. Having pattern matching brought out to the top level of function definitions makes it similar to have you might write a piece-wise definition of said function. Having function signatures be optional (the compiler will work out what the signature should be if you leave it out) leaves code less cluttered
Haskell
factorial 1 = 1
factorial n = n * factorial (n-1)

list_length [] = 0
list_length (first_element:rest) = 1 + list_length rest

and F# again:
F#
let rec fac n =
    match n with
    | 1 -> 1
    | n -> n * fac (n-1)

let rec length list =
    match list with
    | [] -> 0
    | first :: rest -> 1 + length rest

johnywhy wrote:

What's "Concise"?


johnywhy wrote:

What's "Practical"


I'll probably select F#. It's a .NET language, so can use .NET libraries. I like how the various features work together to provide powerful facilities with little code. An example - some code taken from the Microsoft website to download a bunch of URLs in parallel, with async/await
F#
open System.Net
open Microsoft.FSharp.Control.WebExtensions

// Defines a list of pairs of strings
let urlList = [ "Microsoft.com", "http://www.microsoft.com/"
                "MSDN", "http://msdn.microsoft.com/"
                "Bing", "http://www.bing.com"
              ]

let fetchAsync(name, url:string) =
    // The async block means this fucntion defines a task to be run asynchronously
    async {
        try
            let uri = new System.Uri(url)
            let webClient = new WebClient()
            // In async {}, let! operates a bit like Javascript's 'async' keyword
            let! html = webClient.AsyncDownloadString(uri)
            printfn "Read %d characters for %s" html.Length name
        with
            | ex -> printfn "%s" (ex.Message);
    }

let runAll() =
    // F# pipelines process the originating sequence
    // with each function in the pipeline
    urlList
    |> Seq.map fetchAsync     // Generate a task for each name,url pair
    |> Async.Parallel         // Dispatch all tasks in parallel
    |> Async.RunSynchronously // And wait for them all to complete
    |> ignore                 // And ignore any return value, as we only care about side-effects

runAll()
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

AnswerRe: What's the Most Concise, Human-Understandable Practical Language? Pin
BryanFazekas18-May-20 2:21
BryanFazekas18-May-20 2:21 
AnswerRe: What's the Most Concise, Human-Understandable Practical Language? Pin
W Balboos, GHB18-May-20 2:35
W Balboos, GHB18-May-20 2:35 
AnswerRe: What's the Most Concise, Human-Understandable Practical Language? Pin
Member 1181677618-May-20 3:47
Member 1181677618-May-20 3:47 
AnswerRe: What's the Most Concise, Human-Understandable Practical Language? Pin
sasadler18-May-20 8:51
sasadler18-May-20 8:51 
AnswerRe: What's the Most Concise, Human-Understandable Practical Language? Pin
nedzadarek18-May-20 10:25
nedzadarek18-May-20 10:25 
AnswerRe: What's the Most Concise, Human-Understandable Practical Language? Pin
B Alex Robinson18-May-20 13:45
B Alex Robinson18-May-20 13:45 
GeneralRe: What's the Most Concise, Human-Understandable Practical Language? Pin
Vikram A Punathambekar26-Jun-20 2:57
Vikram A Punathambekar26-Jun-20 2:57 
AnswerRe: What's the Most Concise, Human-Understandable Practical Language? Pin
Kirk 1038982118-May-20 14:56
Kirk 1038982118-May-20 14:56 
GeneralRe: What's the Most Concise, Human-Understandable Practical Language? Pin
nedzadarek19-May-20 3:55
nedzadarek19-May-20 3:55 
GeneralRe: What's the Most Concise, Human-Understandable Practical Language? Pin
kalberts19-May-20 6:15
kalberts19-May-20 6:15 
GeneralRe: What's the Most Concise, Human-Understandable Practical Language? Pin
johnywhy23-Oct-21 3:45
johnywhy23-Oct-21 3:45 
GeneralRe: What's the Most Concise, Human-Understandable Practical Language? Pin
johnywhy23-Oct-21 3:50
johnywhy23-Oct-21 3:50 
AnswerRe: What's the Most Concise, Human-Understandable Practical Language? Pin
GuyThiebaut19-May-20 0:36
professionalGuyThiebaut19-May-20 0:36 
AnswerRe: What's the Most Concise, Human-Understandable Practical Language? Pin
James Curran17-Jun-20 20:40
James Curran17-Jun-20 20:40 
GeneralRe: What's the Most Concise, Human-Understandable Practical Language? Pin
johnywhy23-Oct-21 3:39
johnywhy23-Oct-21 3:39 
AnswerRe: What's the Most Concise, Human-Understandable Practical Language? Pin
johnywhy22-Oct-21 8:07
johnywhy22-Oct-21 8:07 
Generalhtml button not firing on mobile, oh Pin
raddevus11-May-20 9:16
mvaraddevus11-May-20 9:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.