Programming Notes ✍️ – Telegram
Programming Notes ✍️
12 subscribers
65 photos
1 file
22 links
Download Telegram
image_2024-02-25_17-53-02.png
356 KB
وقتی که حتی روی یه فانکشن ساده هم دیباگر میزنی تا بفهمی داره توی call stack چه غلطی میکنه
recursive binary search implementation :
def binary_search_recv(list, number , low , high):
if low > high:
return -1

mid = (low + high)
guess = list[mid]

if guess == number:
return mid

if guess > number:
return binary_search_recv(list , number , low , mid - 1)
else:
return binary_search_recv(list, number , mid + 1 , high)

note:
_ with every recall using return with their function will cause re-run the function with their provided (args)
_ in the recall method the state of the variables must have to be passed because of reruring the function proccess
Factory Implementation

from abc import ABC, abstractmethod


class FormatNotFound(Exception):
pass

class File(ABC):
def __init__(self, file):
self.file = file

@abstractmethod
def make(self):
pass

def call_edit(self):
product = self.make()
result = product.edit(self.file)
return result


class JsonFile(File):
def make(self):
return Json()


class XmlFile(File):
def make(self):
return Xml()


class Json:
def edit(self, file):
return f'working on {file}.json'


class Xml:
def edit(self, file):
return f'working on {file}.xml'


def client(file, format):
try:

formats = {
'json': JsonFile
, 'xml': XmlFile
}
result = formats[format](file)
return result.call_edit()
except KeyError:
raise FormatNotFound



if __name__ == '__main__':
print(client('test', 'json'))
factory has 3 component :
1. Creator
2. Product
3. Client
for the golang programming language composition over inheritance is consider the most important basic part
A struct is C's and C++'s notion of a composite type, a datatype that composes a fixed set of labeled fields or members. It is so called because of the struct keyword used in declaring them, which is short for structure or, more precisely, user-defined data structure.
osi model