Click here to Skip to main content
14,549,626 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
Member 798912218-May-20 4:30
MemberMember 798912218-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
Member 798912218-May-20 20:59
MemberMember 798912218-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
Member 798912219-May-20 6:55
MemberMember 798912219-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:
data Location = Location { city :: String }
let home = Location { city = "Boston" }

and 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
factorial 1 = 1
factorial n = n * factorial (n-1)

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

and F# again:
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
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
MemberBryanFazekas18-May-20 2:21 
AnswerRe: What's the Most Concise, Human-Understandable Practical Language? Pin
W Balboos, GHB18-May-20 2:35
mveW Balboos, GHB18-May-20 2:35 
AnswerRe: What's the Most Concise, Human-Understandable Practical Language? Pin
Member 1181677618-May-20 3:47
MemberMember 1181677618-May-20 3:47 
AnswerRe: What's the Most Concise, Human-Understandable Practical Language? Pin
sasadler18-May-20 8:51
Membersasadler18-May-20 8:51 
AnswerRe: What's the Most Concise, Human-Understandable Practical Language? Pin
nedzadarek18-May-20 10:25
Membernedzadarek18-May-20 10:25 
AnswerRe: What's the Most Concise, Human-Understandable Practical Language? Pin
Member 1085545518-May-20 13:45
MemberMember 1085545518-May-20 13:45 
AnswerRe: What's the Most Concise, Human-Understandable Practical Language? Pin
Kirk 1038982118-May-20 14:56
MemberKirk 1038982118-May-20 14:56 
GeneralRe: What's the Most Concise, Human-Understandable Practical Language? Pin
nedzadarek19-May-20 3:55
Membernedzadarek19-May-20 3:55 
GeneralRe: What's the Most Concise, Human-Understandable Practical Language? Pin
Member 798912219-May-20 6:15
MemberMember 798912219-May-20 6:15 
AnswerRe: What's the Most Concise, Human-Understandable Practical Language? Pin
GuyThiebaut19-May-20 0:36
professionalGuyThiebaut19-May-20 0:36 
Generalhtml button not firing on mobile, oh Pin
raddevus11-May-20 9:16
mvaraddevus11-May-20 9:16 
GeneralRe: html button not firing on mobile, oh Pin
Richard Deeming11-May-20 9:31
mveRichard Deeming11-May-20 9:31 
GeneralRe: html button not firing on mobile, oh Pin
raddevus11-May-20 9:39
mvaraddevus11-May-20 9:39 
GeneralRe: html button not firing on mobile, oh Pin
raddevus11-May-20 10:54
mvaraddevus11-May-20 10:54 
GeneralRe: html button not firing on mobile, oh Pin
Marc Clifton11-May-20 9:32
mvaMarc Clifton11-May-20 9:32 
GeneralRe: html button not firing on mobile, oh Pin
raddevus11-May-20 9:41
mvaraddevus11-May-20 9:41 
GeneralGenerated over 5.5 Billion random numbers, but no 0. Pin
raddevus19-Apr-20 7:15
mvaraddevus19-Apr-20 7:15 

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.