Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jorgechato/dsl-kata

DSL coding kata
https://github.com/jorgechato/dsl-kata

dsl kata public python

Last synced: 27 days ago
JSON representation

DSL coding kata

Awesome Lists containing this project

README

        

# DSL Kata

Python solution uses a different approach because the language lacks a block syntax and multi-line lambdas.
Each of these objects is built inline using readable method names.

This implementation overloads the operators `__str__` for operations on the text and range fields.

```python
print(
Form(
CharField(name="user", size="140", label="User Name"),
id="adidas-form",
)
)

print("-"*5)

print(
Form(
CharField(name="user", size="140", label="User Name"),
PasswordField(label="Password"),
id="adidas-form",
)
)
```

```html

User Name

-----

User Name

Password

```

## Run

```bash
$ python main.py
```

## Strengths

- Single step for creating the request
- Easy to dynamically create criteria
- Operator overloading improves readability

## Weaknesses

- Repetition of the class name
- Literal list used as argument

## TL;DR

In general, there are 3 types of DSL implementations: `fluent interface`, `readable inline method arguments` and `blocks`.
Fluent interfaces is the most effective approach for the static languages.
For Python, readable inline method arguments seemed to be the most idiomatic.