OfficialAhmed / Officialahmed

0 stars 0 forks source link

Wanted to connect with you. #1

Open NitkarshChourasia opened 11 months ago

NitkarshChourasia commented 11 months ago

Dear Ahmed,

I hope this message finds you well. My name is Nitkarsh, and I am a developer and GitHub user. I am writing to kindly request a conversation with you regarding a specific topic on GitHub.

I came across your profile and noticed your expertise in Python, and I believe your insights would be valuable for the topic I'd like to discuss.

If you have a few minutes to spare, I would greatly appreciate the opportunity to chat with you about Some wonderful project. I'm eager to hear your thoughts and suggestions.

Please let me know the most convenient way and time to chat with you. I'm flexible and willing to accommodate your schedule.

Thank you for your time and consideration. Looking forward to the opportunity to connect with you.

Best regards, Nitkarsh Chourasia

OfficialAhmed commented 11 months ago

Dear Nitkarsh,

Thank you for reaching out to me, and I appreciate your kind words. Id be more than happy to have a conversation with you regarding the topic on GitHub and some wonderful projects.

To make it convenient for both of us, you can reach me via Twitter DM my Twitter Officialahmed0 Please feel free to send me a message there, and we can arrange a time that works best for both of us to have a discussion.

Looking forward to connecting with you and sharing insights on the project.

Best regards, Ahmed

NitkarshChourasia commented 11 months ago

https://github.com/NitkarshChourasia/funPy

Do check it out, tell me what you understand then we can roll out further.

OfficialAhmed commented 11 months ago

A collection of py scripts in one repo

NitkarshChourasia commented 11 months ago

Yes, wanted to improve them, any suggestions? The best scripts are in Python folder and there are the subdirectories: veryEasy, Easy, Medium, hard, veryHard, Expert.

OfficialAhmed commented 11 months ago

I'll take a look at them. If there are many things to improve i'll PR. Are you looking for a specific thing to improve i.e. performance, readability ... ?

NitkarshChourasia commented 11 months ago

How would make a program performance beast? Is there any resource you have?

NitkarshChourasia commented 11 months ago

I am trying to make python program like this:


class Swapper:
    """
    A class to perform swapping of two values.

    Methods:
    -------
    swap_tuple_unpacking(self):
        Swaps the values of x and y using a tuple unpacking method.

    swap_temp_variable(self):
        Swaps the values of x and y using a temporary variable.

    swap_arithmetic_operations(self):
        Swaps the values of x and y using arithmetic operations.

    """

    def __init__(self, x, y):
        """
        Initialize the Swapper class with two values.

        Parameters:
        ----------
        x : int
            The first value to be swapped.
        y : int
            The second value to be swapped.

        """
        if not isinstance(x, int) or not isinstance(y, int):
            raise ValueError("Both x and y should be integers.")

        self.x = x
        self.y = y

    def display_values(self, message):
        print(f"{message} x: {self.x}, y: {self.y}")

    def swap_tuple_unpacking(self):
        """
        Swaps the values of x and y using a tuple unpacking method.

        """
        self.display_values("Before swapping")
        self.x, self.y = self.y, self.x
        self.display_values("After swapping")

    def swap_temp_variable(self):
        """
        Swaps the values of x and y using a temporary variable.

        """
        self.display_values("Before swapping")
        temp = self.x
        self.x = self.y
        self.y = temp
        self.display_values("After swapping")

    def swap_arithmetic_operations(self):
        """
        Swaps the values of x and y using arithmetic operations.

        """
        self.display_values("Before swapping")
        self.x = self.x - self.y
        self.y = self.x + self.y
        self.x = self.y - self.x
        self.display_values("After swapping")

print("Example 1:")
swapper1 = Swapper(5, 10)
swapper1.swap_tuple_unpacking()
print()

print("Example 2:")
swapper2 = Swapper(100, 200)
swapper2.swap_temp_variable()
print(
NitkarshChourasia commented 11 months ago

I want to for example on becoming performance beast how should I do it? Any resources?

NitkarshChourasia commented 11 months ago

I hope this message finds you well. I am reaching out to request your assistance as a code reviewer for my Python project. I greatly value the benefits of pair programming and believe that constructive feedback from an experienced reviewer like you would significantly enhance the quality and efficiency of the codebase.

NitkarshChourasia commented 11 months ago

I just want you to become a reviewer of that repository, to point out the mistakes, that't it. Because I believe pair programming actually teaches you a lot. I am trying something bigger. Just need a reviewer.

OfficialAhmed commented 11 months ago

There are tons of scripts on the repo, reimplementing every single one of em takes a lot of time. Are there certain scripts you'd like me to check out..

Regarding resources on how to enhance the performance there should be online websites that compare 2 implementations of one problem and shows which one is better. But I'm experienced I know which is better for example list comprehension better than pure for-loops if possible implementing and makes it easy to read then l'll go for it etc.

OfficialAhmed commented 11 months ago

OOP is one way to make the code easier to debug and maintain. However, a script that does one thing such as counting odd integers in a list or adding 2 integers is not recommended to use OOP theres no advantage on using it in that case

NitkarshChourasia commented 11 months ago

Hey, Ahmed, So my inquisitive query being which requires someone's assistance and expertise like yours, to further go forward, So, here it is,..

class Swapper:
    """
    A class to perform swapping of two values.

    Methods:
    -------
    swap_tuple_unpacking(self):
        Swaps the values of x and y using a tuple unpacking method.

    swap_temp_variable(self):
        Swaps the values of x and y using a temporary variable.

    swap_arithmetic_operations(self):
        Swaps the values of x and y using arithmetic operations.

    """

    def __init__(self, x, y):
        """
        Initialize the Swapper class with two values.

        Parameters:
        ----------
        x : int
            The first value to be swapped.
        y : int
            The second value to be swapped.

        """
        if not isinstance(x, int) or not isinstance(y, int):
            raise ValueError("Both x and y should be integers.")

        self.x = x
        self.y = y

    def display_values(self, message):
        print(f"{message} x: {self.x}, y: {self.y}")

    def swap_tuple_unpacking(self):
        """
        Swaps the values of x and y using a tuple unpacking method.

        """
        self.display_values("Before swapping")
        self.x, self.y = self.y, self.x
        self.display_values("After swapping")

    def swap_temp_variable(self):
        """
        Swaps the values of x and y using a temporary variable.

        """
        self.display_values("Before swapping")
        temp = self.x
        self.x = self.y
        self.y = temp
        self.display_values("After swapping")

    def swap_arithmetic_operations(self):
        """
        Swaps the values of x and y using arithmetic operations.

        """
        self.display_values("Before swapping")
        self.x = self.x - self.y
        self.y = self.x + self.y
        self.x = self.y - self.x
        self.display_values("After swapping")

print("Example 1:")
swapper1 = Swapper(5, 10)
swapper1.swap_tuple_unpacking()
print()

print("Example 2:")
swapper2 = Swapper(100, 200)
swapper2.swap_temp_variable()
print()

A sample program 1

In these two sample programs avoid, the lengthy and maybe inefficient use of code logic. It was I just wanted to able to get the output of the required problem without using any or avoiding as much as possible any in-built classes and their methods and functions, so was just trying to code all by myself just for learning purposes. Just to know the behind of the black box, if you know what I mean.

A sample program 2

The link to the actual folder I am interested in. Scraped Programs

So, this are the scraped programs which I need specifically help with.

So, what do I want to know? Ahmed. I am learning to use unittest framework in python for testing, purposes. As you can see in those two sample programs, using print statements in very inefficient way to do so. Imagine or see the repository having multiple hundreds of scripts, now the act of manually comparing the output with the input is sort of inefficient, lack of professionlism and what not. I am new to testing framework. Considering the vastness of the project in terms of quantities and the requirement for each script to be properly tested with all edge cases possible. See below: For example, a basic program with testing using all the classes and all implemented. Just a basic python program :

import unittest

def to_add(a, b):
    return a + b

def to_sub(a, b):
    return a - b

def to_multi(a, b):
    return a * b

def to_div(a, b):
    if b == 0:
        raise ValueError("Cannot divide by zero.") # To understand this line of code.
    else:
        return a / b

class TestAddFunction(unittest.TestCase):

    def test_positive_numbers(self):
        result = to_add(5, 10)
        self.assertEqual(result, 15)

    def test_negative_numbers(self):
        result = to_add(-5, -10)
        self.assertEqual(result, -15)

    def test_zero_values(self):
        result = to_add(0, 0)
        self.assertEqual(result, 0)

    def test_large_numbers(self):
        result = to_add(10000000000, 20000000000)
        self.assertEqual(result, 30000000000)

    def test_decimal_numbers(self):
        result = to_add(3.14, 2.71)
        self.assertAlmostEqual(result, 5.85)

    def test_mixed_numbers(self):
        result = to_add(5, -3.5)
        self.assertAlmostEqual(result, 1.5, places=2)

class TestSubFunction(unittest.TestCase):

    def test_positive_numbers(self):
        result = to_sub(10, 5)
        self.assertEqual(result, 5)

    # Add more test cases for substraction function.

class TestMultiFunction(unittest.TestCase):

    def test_positive_numbers(self):
        result = to_multi(5, 10)
        self.assertEqual(result, 50)

    # Add more test cases for multiplication function.

class TestDivFunction(unittest.TestCase):

    def test_positive_numbers(self):
        result = to_div(10, 5)
        self.assertEqual(result, 2)

    def test_divide_by_zero(self):
        with self.assertRaises(ValueError):
            to_div(10, 0)

    # Add more test cases for division function.

if __name__ == "__main__":
    unittest.main()

# Done.

So, considering the nature of the scripts (programming challenges/problems to be solved in python.) Also, considering the nature of the repository (Python folder to be specific), with all the vastness (quantity) of the files.

What will be the best way and method of testing? Should I place the testing class within the script/program itself. Like this A program with unittest framework implemented from line 1 to 85 or should I somehow make another .py file (yes, with naming rules defined by me for management of files) and import the actual script/program in to that .py file which I made for testing purposes and run the tests? What will be the best way to do this?

chatGPT, Answers this:

Hey there,

Thank you for providing the details of your project and your interest in using the unittest framework for testing. Considering best practices and standards in the Python programming and testing world, I would recommend the following approach:

  1. Create a Separate "Tests" Directory: Keep your test files separate from the actual scripts you want to test. This ensures clear organization and makes it easier to manage and run tests.

  2. Name Test Files Appropriately: Name your test files using a pattern like "test_filename.py" to make it clear which script the tests correspond to.

  3. Use Test Classes: For each script you want to test, create a test class within the corresponding test file. This class should inherit from unittest.TestCase.

  4. Write Test Functions: Inside each test class, write test functions to test different aspects of your code. Use descriptive names for your test functions that reflect the behavior being tested.

  5. Import the Script to Be Tested: Import the script you want to test at the beginning of your test file. This way, you can access the functions and classes you want to test.

  6. Organize Test Functions: Organize your test functions to group related tests together. For example, you can group all tests related to a specific function or method under one test class.

  7. Use unittest.main(): At the end of each test file, use if __name__ == "__main__": unittest.main() to automatically discover and run the tests in that file.

Here's how your test directory structure and test file might look:

project_root/
    |- Python/
    |   |- script_to_test.py
    |   |- another_script_to_test.py
    |
    |- tests/
        |- test_script_to_test.py
        |- test_another_script_to_test.py

For example, in "test_script_to_test.py":

import unittest
from script_to_test import to_add, to_sub, to_multi, to_div

class TestScriptToTest(unittest.TestCase):

    def test_to_add_positive_numbers(self):
        result = to_add(5, 10)
        self.assertEqual(result, 15)

    def test_to_add_negative_numbers(self):
        result = to_add(-5, -10)
        self.assertEqual(result, -15)

    # Add more test functions for other functions in script_to_test.py

if __name__ == "__main__":
    unittest.main()

By following this approach, you keep your tests organized, and it becomes easier to scale your testing as your project grows.

Also, I see you have written sample programs to perform swapping. While they are fine for learning purposes, I'd recommend using Python's built-in tuple unpacking for swapping values, which is both efficient and Pythonic:

def swap_tuple_unpacking(x, y):
    x, y = y, x
    return x, y

# Usage example:
a = 5
b = 10
a, b = swap_tuple_unpacking(a, b)
print(a, b)  # Output: 10 5

I hope this guidance helps you structure your testing approach effectively. If you have any more questions or need further assistance, feel free to ask. Happy coding!



Needed your two cents over it.
NitkarshChourasia commented 11 months ago

???

OfficialAhmed commented 11 months ago

I don't really get you there. If you're asking about a way to test the performance for all the scripts, then one way to do it is to import all the scripts into one main script that calculates the time of each program it runs.

Regards

NitkarshChourasia commented 11 months ago

No, best way to test each program in your opinion?

OfficialAhmed commented 11 months ago

It all depends on the scale and what are u trying to test. There's no one preferred way to do it

Unittest is a way to test a multi function program

Calculating the time it spent using time for easier implementation and quick speed execution test

There r many others, I personally don't stick with one, I use different techniques

NitkarshChourasia commented 11 months ago

Okay.

OfficialAhmed commented 11 months ago

Hi there, I'm currently working on a new project on Python language 101 "from-zero-to-a-hero" tutorials I have planned what goes in and everything and wondering if you're willing to collaborate by contributing/documenting the code please DM me on twitter to discuss about it. I'm Planning to publish it soon but wanted to document and explain the scripts in detail.

NitkarshChourasia commented 11 months ago

Yes, why not @OfficialAhmed but the thing is I am locked out of twitter account for some reasons. And It asking for document to let me in. It will take time to do so. I am totally in.

NitkarshChourasia commented 11 months ago

Okay.

OfficialAhmed commented 11 months ago

Sent you an invite to a private project

NitkarshChourasia commented 11 months ago

Yes, saw that.