Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- [#381](https://github.com/green-code-initiative/creedengo-rules-specifications/pull/381) Add rule GCI 108 Prefer Append Left
- [#380](https://github.com/green-code-initiative/creedengo-rules-specifications/pull/380) Added rule GCI107 : DATA - Avoid Iterative Matrix Operations

### Changed
Expand Down
1 change: 1 addition & 0 deletions RULES.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ Some are applicable for different technologies.
| GCI105 | Python String Concatenation | Python String Concatenation - Use Join Instead or f-Strings instead of += | | 🚫 | 🚫 | 🚫 | 🚧 | 🚫 | 🚫 | 🚫 |
| GCI106 | Avoid Square Root Operations In Loop | Using scalar `math.sqrt` (or `numpy.sqrt` on individual values) inside loops leads to inefficient code | | 🚫 | 🚫 | 🚫 | ✅ | 🚫 | 🚫 | 🚫 |
| GCI107 | Data : Avoid Iterative Matrix Operations | Use vectorization by the usage of the built-in functions of TensorFlow, NumPy or Pandas | | 🚫 | 🚫 | 🚫 | 🚧 | 🚫 | 🚫 | 🚫 |
| GCI108 | Prefer Append Left | When you want to insert an element at the beginning of a list, it's better to use a deques or a double linkedlist. | | ❓ | ❓ | ❓ | 🚀 | ❓ | ❓ | ❓ |
| GCI203 | Detect unoptimized file formats | When it is possible, to use svg format image over other image format | | 🚧 | 🚀 | 🚀 | ✅ | 🚀 | 🚀 | 🚫 |
| GCI404 | Avoid list comprehension in iterations | Use generator comprehension instead of list comprehension in for loop declaration | | 🚫 | 🚫 | 🚫 | ✅ | 🚫 | 🚫 | 🚫 |
| GCI522 | Sobriety: Brightness Override | To avoid draining the battery, iOS and Android devices adapt the brightness of the screen depending on the environment light. | | 🚫 | 🚫 | ✅ | 🚫 | 🚫 | 🚫 | 🚫 |
Expand Down
16 changes: 16 additions & 0 deletions src/main/rules/GCI108/GCI108.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"title": "DATA: Prefer AppendLeft Over Insert(0)",
"type": "CODE_SMELL",
"status": "ready",
"remediation": {
"func": "Constant\/Issue",
"constantCost": "10min"
},
"tags": [
"creedengo",
"eco-design",
"performance",
"data"
],
"defaultSeverity": "Minor"
}
48 changes: 48 additions & 0 deletions src/main/rules/GCI108/python/GCI108.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
When you want to insert an element at the beginning of a list, it's better to use a deques or a double linked list.
Comment thread
dedece35 marked this conversation as resolved.

== Non compliant Code Example

[source,python]
----
numbers.insert(0,val)
----

== Compliant Solution

[source,python]
----
numbers.appendleft(val)
----

== Relevance Analysis

The following results were obtained through local experiments.

=== Configuration

* Processor: Intel(R) Core(TM) Ultra 5 135U, 2100 MHz, 12 cores, 14 logical processors
* RAM: 16 GB
* CO2 Emissions Measurement: Using CodeCarbon

=== Context

We'll analyze the impact of inserting 10**6 elements at index 0 of a list and compare this with inserting the same number of elements using a deque (deque stands for Double-Ended Queue. It is a data structure that allows adding and removing elements from both ends efficiently. Unlike regular queues, which are typically operated on using FIFO (First In, First Out) principles, a deque supports both FIFO and LIFO (Last In, First Out))


Comment on lines +29 to +31

Copilot AI Jul 24, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an extremely long sentence that's difficult to read. Consider breaking it into multiple sentences or moving the deque definition to a separate paragraph.

Suggested change
We'll analyze the impact of inserting 10**6 elements at index 0 of a list and compare this with inserting the same number of elements using a deque (deque stands for Double-Ended Queue. It is a data structure that allows adding and removing elements from both ends efficiently. Unlike regular queues, which are typically operated on using FIFO (First In, First Out) principles, a deque supports both FIFO and LIFO (Last In, First Out))
We'll analyze the impact of inserting 10**6 elements at index 0 of a list and compare this with inserting the same number of elements using a deque.
A deque (short for Double-Ended Queue) is a data structure that allows adding and removing elements from both ends efficiently. Unlike regular queues, which are typically operated on using FIFO (First In, First Out) principles, a deque supports both FIFO and LIFO (Last In, First Out) operations.

Copilot uses AI. Check for mistakes.
=== Impact Analysis

*1. Carbon emissions:*

image::carbon.png[]

*2. Execution time:*

image::time.png[]

=== Conclusion

The results show that using a deque is significantly more efficient than using a list for inserting elements at the beginning. The carbon emissions and execution time are both much lower when using a deque, making it the preferred choice for this operation.

=== References
https://www.geeksforgeeks.org/deque-in-python/
https://github.com/green-code-initiative/creedengo-challenge/issues/46
Binary file added src/main/rules/GCI108/python/carbon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/rules/GCI108/python/time.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/main/rules/GCI97/GCI97.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
],
"defaultSeverity": "Minor"
}


Comment thread
dedece35 marked this conversation as resolved.
2 changes: 1 addition & 1 deletion src/main/rules/GCI97/python/GCI97.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,4 @@ the rule is relevant, it also applies to the case where the user wishes to set h

=== References

https://chrissardegna.com/blog/python-expontentiation-performance/
https://chrissardegna.com/blog/python-expontentiation-performance/
Comment thread
dedece35 marked this conversation as resolved.