Skip to content

Explore how a simple word-counting problem can be solved in multiple programming paradigms—Pipeline, Kick-forward, Quarantine, and "The One"—using Java, JavaScript, and Haskell. This repo showcases how design constraints shape thinking, encouraging creative, functional, and type-safe approaches to software construction

License

Notifications You must be signed in to change notification settings

24luca24/programming-style

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

CountFrequency - Exercises

Programming stile is a subject where the goal is to discover different way to program. Each of the src subfolder are a style of coding the same program. The program is a word counter. We have 2 type of input: -small (input-small.txt) -large (input-large.txt) In input the program takes in input also a stopword file (stop_words.txt). The goal is to filter out the stopword from the text in input and to count how many occurrencies of every single word appear; finally the program must return the top N words (th one that appear the most in the document) Given that this is a relative simple task, it became a little bit challenging when the teacher introduced constraint. For each style we have different one. This allow us to think about different ways (and not the most convinient and already known) way to resolve the problem.

🛠️ Technologies Used

Language Badge
Java Java
JavaScript JavaScript
Haskell Haskell

Pipeline Style

  • The functions MUST do one computation at time
  • In the main all the functions used to achieve the goal should be composed in a Pipeline Style
  • Avoid (as much as we can) impure action

Kick-forward Style

Variation of the Pipeline style, with the following additional constraints: - Each function takes an additional parameter, usually the last, which is another function. - The function parameter is applied at the end of the current function. - The function parameter is given, as input, what would be the output of the current function. - The larger problem is solved as a pipeline of functions, but where the next function to be applied is given as a parameter to the current function.

Quarantine Style

  • Core program functions have no side effects of any kind, including IO.
  • All IO actions must be contained in computation sequences that are clearly separated from the pure functions.
  • All sequences that have IO must be called from the main program.

The One

  • Existence of an abstraction to which values can be converted. This abstraction provides operations to (1) wrap around values, so that they become the abstraction; (2) bind itself to functions, to establish sequences of functions.
  • Larger problem is solved as a pipeline of functions bound together, with unwrapping happening at the end.
  • Use “strong types”: avoid circumventing the type checker (e.g., avoid casts and avoid Object as a type).

🔄 How to run Java

  • in this particular style we have got another class to compile before running the TermFrequency.java file, so before you need to do:
javac MyMonad.java

🔄How to run program

🔄 How to run Java

Javac TermFrequency

then

Java TermFrequency (input-small.txt / input-large.txt) n (n where n is a the top frequency word you want to retrieve; test was done with 2 for small-input and 25 for large one. Below ypu will find a list of the correct output)

🔄 How to run Javascript

node TermFreqeuncy (input-small.txt/input-large.txt) n

🔄How to run Haskell

  • To compile:
ghc TermFrequency.hs 
  • To run:
./TermFrequency < input-small.txt

About

Explore how a simple word-counting problem can be solved in multiple programming paradigms—Pipeline, Kick-forward, Quarantine, and "The One"—using Java, JavaScript, and Haskell. This repo showcases how design constraints shape thinking, encouraging creative, functional, and type-safe approaches to software construction

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published