Skip to content

georgeY123-AI/Instant_Task_2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 

Repository files navigation

task_2


Task 2

  1. Programming Languages with and without Garbage Collection (GC)

    • List programming languages that have Garbage Collection (GC) and those that do not.
  2. The 13 Principles of Clean Code

    • List and explain the 13 principles of Clean Code.
  3. How to Implement do while in Python

    • Explain how to implement a do while loop in Python.
  4. Comparison Between for and while in Python

    • Compare and contrast the for and while loops in Python.
  5. Equivalent of pass in Java and C++

    • Explain what corresponds to pass in Java and C++.
  6. Popular Tracing Tools in Python

    • List some of the most popular tracing tools used in Python.
  7. How to Write Directly in the Middle of a File

    • Explain how to write directly in the middle of a file in Python.

the answers:

1) Programming Languages with and without Garbage Collection (GC)

Languages with Garbage Collection (GC):

  • Java: Uses GC for automatic memory management.
  • Python: Utilizes GC for memory management.
  • C#: Utilizes .NET's GC system.
  • Ruby: Uses GC for memory management.
  • JavaScript: Uses GC within its execution environment (e.g., V8 in Chrome).
  • Go: Includes GC for memory management.
  • R: Uses GC for memory management.
  • Erlang: Includes GC for memory management.

Languages without Garbage Collection (GC):

  • C: Does not include GC; memory management is manual.
  • C++: Does not include GC but can use external libraries like Boehm GC.
  • Rust: Does not include GC; relies on ownership and borrowing for memory management.
  • Assembly: Does not include GC; memory management is manual.
  • Pascal: Does not include GC; memory management is manual or through memory management functions.

2) The 13 Principles of Clean Code

  1. Meaningful Names: Use descriptive names for variables, functions, and classes.
  2. Functions Should Do One Thing: Functions should have a single responsibility.
  3. Short Functions: Keep functions short and focused.
  4. Use Intention-Revealing Names: Choose names that reveal the intention behind the code.
  5. Avoid Comments: Write code that is self-explanatory; minimize the need for comments.
  6. Testing: Ensure code is thoroughly tested with unit tests and integration tests.
  7. Formatting: Maintain consistent code formatting and style.
  8. Avoid Duplication: Refactor code to eliminate redundancy.
  9. Handle Exceptions Properly: Manage exceptions to keep code clean and maintainable.
  10. Minimize Complexity: Strive to keep code simple and straightforward.
  11. Code Reviews: Regularly review and refactor code to improve its quality.
  12. Use Common Conventions: Follow common coding patterns and practices.
  13. Independence: Write code that is independent of other parts as much as possible.

3) How to Implement do while in Python

Python does not have a direct do while loop construct. You can simulate it using a while loop like this:

while True:
    # Code to execute
    if not condition:
        break

4) Comparison Between for and while Loops in Python

for loop:

  • Iterates Over a Sequence: Typically used for iterating over sequences like lists, strings, or sets.
  • Ease of Use: Clear and straightforward when iterating over known-size collections.
  • Example:
    for i in range(5):
        print(i)

while loop:

  • Condition-Based Iteration: Used when iterating until a specific condition is met.
  • Flexibility: Offers more flexibility but requires careful handling of the condition to avoid infinite loops.
  • Example:
    i = 0
    while i < 5:
        print(i)
        i += 1

5) Equivalent of pass in Java and C++

  • Java: There's no direct keyword equivalent to pass in Java. You can use an empty block like this:

    if (condition) {
        // Do nothing
    }
  • C++: In C++, you can use an empty block similarly:

    if (condition) {
        // Do nothing
    }

6) Popular Tracing Tools in Python

  • PyCharm Profiler: Built-in profiling tool within PyCharm IDE.
  • cProfile: Built-in Python module for performance analysis.
  • line_profiler: Line-by-line profiling tool to identify performance bottlenecks.
  • memory_profiler: Tool for monitoring memory usage.
  • Py-Spy: Simple and powerful sampling profiler for Python applications.
  • Sentry: Error tracking tool that supports Python.

7) Writing Directly in the Middle of a File

You can write to the middle of a file in Python using seek() to position the file pointer where you want to write. Here’s an example:

with open('file.txt', 'r+') as file:
    # Seek to the middle of the file
    file.seek(len(file.read()) // 2)
    # Write text in the middle of the file
    file.write('This is new text')

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published