Using functional language concepts with OO - is there a language?

I recently thought that I do not always use beautiful OO concepts when writing Pythonic programs. In particular, I thought it would be interesting for me to see the language in which I could write a typical web script as

# Fictional language 
# This script combined effect is to transform (Template, URI, Database) -> HTTPOutput

HTTPOutput: 
    HTTPHeaders + Maintext

Flags:                              # This is a transform URI -> Flags 
    value = URI.split('?').after
    refresh = 'r' in value
    sort = /sort=([a-z])/.search(value)

HTTPHeaders:                       # This is a transform Flags -> HTTPHeaders
    'Content-type:...' +  Flags.refresh ? 'Refresh: ...' : ''

Maintext:
    Template.replace('$questions', PresentedQuestions [:20] )

Questions:
    (Flags.sort = 'r') ? RecentQuestions : TopQuestions 

PresentedQuestions:
    Questions % '<h4>{title}</h4><p>{body}</p>'

RecentQuestions:
    Database.Questions . sort('date')  

TopQuestions:
    Database.Questions . sort('votes') 

See what happens? I try to make as many objects as possible; each paragraph declares what I call a transformation. For example, there is a conversion HTTPHeaders. In an imperative language, which will be a declaration of a class, object, and function in combination:

class HTTPHeaders_class
{
     public char* value
     HTTPHeaders_class() 
     {
         value = ... + Flags.refresh ? + ... // [1] 
     }

}

class Flags_class 
{
     public char* flagstring;
     public bool refresh;
     ...
     Flags_class() 
     {
         value = ... /* [3] */ 
         refresh = ...
     }
}

Flags = new Flags_class (URI)
HTTPHeaders = new HTTPHeaders_class (Flags)   // [2]

, , , , , , ; . . , , ( " , " ).

, , , Python, M-V-C Django (), , .

  • value, .
  • HTTPHeader -, , HTTPHeader . HTTPHeader .
  • , URI, . Flags URI HTTPHeaders Flags, . , Database , Questions , , , HTTPOutput .
  • . , , .

, , -, . , , ?

+3
6

- Python, Django. MVC-, Django MVC.

, Declarative programming, . () . , , , .

, Model-View-Controller Django. , , -.

+4

F #. ( OCaml) OO .NET.

+4

, , , Scala OO .

+1

DSL -, Sinatra - DSL. , , . http://www.sinatrarb.com/ - Ruby, , .

+1

Haskell, , . , Flags URI, ; URI - , , -, URI ..

URI, , , , . ( - .) , URI , ; Haskell.

, , , "", , , , .

+1

I see that my favorite language has not been mentioned yet, so I would like to jump in and offer Dyalog APL as a language for 100%. APL has a looong history and was developed when there was no Internet, but Dyalog is the most active provider of APL Implementations, and they also have a fully functional web server , which is provided for free. (A translator is also provided free of charge for non-commercial use.)

+1
source

Source: https://habr.com/ru/post/1710504/


All Articles