Skip to content

Commit 96b5b4b

Browse files
committed
docs(paradigms): add detailed explanation of Declarative Programming with Java examples
What - Documented the concept of **Declarative Programming** vs **Imperative Programming**. - Highlighted key characteristics: - Focus on *what* to achieve, not *how* to achieve it. - High-level abstraction with less boilerplate code. - Execution strategy left to underlying system (e.g., SQL engine, Streams). - Provided concrete examples across multiple domains: - **SQL** → `SELECT * FROM students WHERE marks > 90` (declarative query). - **Java Streams** → `list.stream().filter(...).map(...).toList()` (functional transformations). - **HTML/CSS** → structure and styling declaratively described. - Outlined benefits: - Conciseness, readability, maintainability. - Easier parallelization via declarative APIs. - Added **Java-specific comparison**: - Imperative sum of even numbers (loops + conditions). - Declarative sum using Streams API (`filter`, `mapToInt`, `sum`). Why - Declarative programming is central to modern Java (Streams, Lambdas, functional style). - Developers often confuse *control flow* with *business logic*; declarative style separates the two. - This doc clarifies when and why declarative approaches are preferred in enterprise apps. Logic 1. **Definition** - Declarative = specify outcome, not steps. - Contrasted with imperative = specify exact flow (loops, state changes). 2. **Key Characteristics** - Abstraction of execution. - Focus on results instead of algorithmic details. - Reduction of verbosity and control structures. 3. **Examples** - SQL → declare query logic without procedural fetch. - Streams → pipelines describe transformation, not iteration. - HTML → structure declaration, not rendering process. 4. **Java Focus** - Streams API embodies declarative patterns (map/filter/reduce). - Shows improved readability and parallelization compared to traditional loops. Real-life applications - **Database queries (SQL)**: write intent-driven queries, let DBMS handle execution plan. - **Back-end APIs (Java Streams)**: declarative transformations for business rules. - **UI layer (HTML/CSS)**: declaratively specify layout and style, browsers handle rendering. - **Parallel data processing**: declarative pipelines allow frameworks to optimize multithreaded execution. Notes - Declarative ≠ “no control,” but rather offloading control to libraries/engines. - Imperative code is sometimes necessary for low-level optimization, but declarative style is preferred for clarity. - Java’s `Stream.parallel()` demonstrates how declarative style enables automatic performance improvements. Signed-off-by: https://github.com/Someshdiwan <[email protected]>
1 parent cc58f23 commit 96b5b4b

File tree

1 file changed

+0
-0
lines changed

1 file changed

+0
-0
lines changed

0 commit comments

Comments
 (0)