20TD02U_Libraries - itnett/FTD02N GitHub Wiki

Remembering: "What is a library in programming? List some common libraries."

Library in Programming: A library in programming is a collection of pre-written code, functions, and routines that developers can use to optimize their workflows, enhance functionality, and avoid reinventing the wheel. Libraries provide reusable components that can be incorporated into various programs.

Common Libraries:

  1. NumPy: Used for numerical computing in Python.
  2. Pandas: Used for data manipulation and analysis in Python.
  3. Matplotlib: Used for creating static, interactive, and animated visualizations in Python.
  4. Requests: Used for making HTTP requests in Python.
  5. Scikit-learn: Used for machine learning in Python.
  6. React: Used for building user interfaces in JavaScript.
  7. jQuery: Used for simplifying HTML DOM tree traversal and manipulation in JavaScript.
  8. Lodash: Used for providing utility functions for common programming tasks in JavaScript.
  9. TensorFlow: Used for machine learning and neural networks in Python.
  10. Boost: A set of libraries for the C++ programming language.

Example Imports: Se skriptet her

Understanding: "Explain the importance of libraries in software development. Provide examples."

Importance of Libraries in Software Development:

Libraries are crucial in software development for several reasons:

  1. Efficiency: Libraries save time by providing pre-written code that developers can reuse, reducing development time.
  2. Reliability: Libraries are often well-tested and maintained by the community or organizations, ensuring reliability.
  3. Focus on Core Logic: By leveraging libraries, developers can focus on the core logic of their applications instead of spending time on routine tasks.
  4. Enhanced Functionality: Libraries often provide advanced features and functionalities that would be complex and time-consuming to develop from scratch.

Examples:

  • NumPy: Allows efficient handling of large arrays and matrices, essential for scientific computing. Se skriptet her

  • Pandas: Simplifies data manipulation and analysis with powerful data structures. Se skriptet her

  • Requests: Simplifies making HTTP requests. Se skriptet her

Applying: "Demonstrate how to use a specific library for a task, such as data manipulation with Pandas."

Using Pandas for Data Manipulation: Se skriptet her

Analyzing: "Analyze the performance impact of using different libraries for similar tasks."

Performance Analysis:

Task: Sorting a Large List of Numbers

  1. NumPy: Se skriptet her

  2. Python's Built-in Sort: Se skriptet her

Analysis:

  • NumPy: NumPy’s sort function is optimized for performance with large datasets, utilizing efficient algorithms and low-level optimizations.
  • Built-in Sort: Python’s built-in sort function is highly efficient but may not match the performance of NumPy for large numerical arrays due to additional overhead.

Evaluating: "Evaluate the trade-offs between using standard libraries versus custom implementations."

Trade-offs:

  1. Standard Libraries:

    • Pros:
      • Time-saving and efficient.
      • Well-tested and reliable.
      • Community support and documentation.
    • Cons:
      • May include unnecessary features, leading to larger dependencies.
      • Less control over implementation details.
  2. Custom Implementations:

    • Pros:
      • Tailored to specific needs.
      • Potentially more lightweight and efficient for very specialized tasks.
    • Cons:
      • Time-consuming to develop and test.
      • Higher maintenance burden.
      • Risk of bugs and security vulnerabilities.

Example Comparison:

  • Sorting:
    • Using NumPy or Python’s built-in sort is generally preferable for most use cases due to their efficiency and reliability.
    • A custom sorting algorithm might be justified in scenarios requiring highly specialized sorting criteria not efficiently handled by standard libraries.

Creating: "Develop a custom library for a specific need in your project. Document its usage."

Custom Library: String Utilities

Library Code: string_utils.py Se skriptet her

Documentation:

  1. reverse_string(s): Reverses the input string.
  2. is_palindrome(s): Checks if the input string is a palindrome.
  3. to_uppercase(s): Converts the input string to uppercase.
  4. count_vowels(s): Counts the number of vowels in the input string.

Example Usage: Se skriptet her

This custom library provides a set of utility functions for string manipulation, demonstrating the process of creating, using, and documenting a custom library.