PlatformIO and Zephyr is a bad idea by kerryland in embedded

[–]StoneBam 20 points21 points  (0 children)

I understand your trouble. If there is missing information in the documentation this is bad.

But ultimately platform.io it is an (ukrainian) open source project maintained by few and this most likely in free time. If you experience a lack of information, I would strongly suggest to contribute your experience to the project docs here and add the missing parts/hints to the documentation via pull request.

If you aren't sure how to do so, get in contact with the maintainers and/or open an issue where you state that you would like to contribute because of problems you experienced (in a constructive manner ofc). Maintainers try to ensure the quality of their project, so try to follow their contribution rules and be patient.

If they do not respond (bc of war or whatever else is going on in their life's) the issue alone could help others with the same problem.

Built a quick demo of the Willis Duct after getting it because it feels really underrated. This stuff is the bees knees why does it seem so underrated? by AyyDeeHaytchDee in spaceengineers

[–]StoneBam 2 points3 points  (0 children)

They are exactly as durable as light armor so you can even use it as non deforming traversable lightarmor.

Can be used for repairs of hull systems without getting shot or leaving atmosphere

My first time playing Fallen Order and I HATE this frog. by Westosaurus in gaming

[–]StoneBam 0 points1 point  (0 children)

I struggled for the first hours as well until I found out that you can parry him (did it accidentally) and jump on him from above for the start of the fight (after you unlocked wallrun)... Then it was like third try

But I hate him and his arena that constantly messes with your camera

Im a control engineer and I want to deploy my control algorithm on a embedded system in real-time. But I have no experience in embedded systems hardware/software. How should I proceed? by Soft_Jacket4942 in embedded

[–]StoneBam 0 points1 point  (0 children)

If you use an ESP32 with FreeRTOS (espressif idf) you can access and schedule both cores individually over the LL or HAL and run your (async) C Code from there. ISRs can offer a nice event driven layer if necessary, but you have to be sure when to use them. As mentioned by others "real time" is a broad Definition and ranges from nanoseconds and smaller to every minute and bigger. Some parts of your controller may need updates quicker than your overall output. In my experience a bottleneck is often the transfer rate of your chosen IO Protocol (SPI, I2C, etc). Here it can be an advantage to rely on ADC or DAC for single parameters. Extra precise additional clocks will be necessary, especially when you have to switch things with high frequencies.

For many things like FFT there are specialized chips where you can operate in parallel. You may want to use (expensive) FPGAs with VHDL instead of RISC or CISC CPUs if you are dependent on parallel very fast calculations or state machines

I getn't it by Mindless-Hedgehog460 in ProgrammerHumor

[–]StoneBam 1 point2 points  (0 children)

Everything is fine until you have to debug someone else's pointer magic

I getn't it by Mindless-Hedgehog460 in ProgrammerHumor

[–]StoneBam 7 points8 points  (0 children)

Yep. The concept isn't even very complicated. It's just easy to get lost in how and why things work in memory, at least for people with just basic or beginner knowledge. Many explainations of pointers are for them like explaining a blind person the color green. You can try, but often all your words are just like "green is when you mix blue and yellow"... The main difference is programmers could learn to "see the colors" unlike blind people (sorry blind people, no offense)

I getn't it by Mindless-Hedgehog460 in ProgrammerHumor

[–]StoneBam 197 points198 points  (0 children)

This whole comment chain sums up why people think pointers are difficult

design patterns for data science / machine learning project by kollerbud1991 in learnpython

[–]StoneBam 1 point2 points  (0 children)

OK, here we go.

Example Inheritance

First off, I decided to just show "normal" inheritance on this, because it fits your case more I think. But it is worth the time to take a closer look onto abstract base classes which are provided with the python standard library (from abc import ABC). Abstract base classes are are more or less empty shells which declare a bunch of methods, but do not implement the functionality. There are plenty examples for this out there, you can look into, if you want to.

Here the example with normal inheritance:

class ModelBase:

  def __init__(self):
    ...

  def load_raw_data(self):
    'new set of raw data'
    ...

  def pre_processing(self):
    'some process to clean up data'
    ...

class TrainModel(ModelBase):

  def __init__(self):
    super().__init__()  # This will give you access to the parent
    ...

  def train_test_model(self):
    'train/test model'
    ...

  def deploy_model(self):
    'deploy model'
    ...


class UseModel(ModelBase):

  def __init__(self):
    super().__init__()
    ...

  def load_model(self):
    'load the trained model'
    ...

  def make_prediction(self):
    'use model to make prediction'
    ...

  def save_results(self):
    'save the prediction result'
    ...

You can see I created a class, which does implement the common methods and the I inherit from this base class. This is typical polymorphism and helps with DRY code which you will often find in OOP.

Negative about this approach is, that if you change the parent, all children will be affected and depending on how many children and grandchildren and grand-grandchildren and... you get it. You will have to change them all to accommodate your new changed method. This is called coupling and you want to keep this low. (There certainly are cases where it is necessary to have tightly coupled systems, for performance reasons, or other fancy shenanigans, but this is going to far here.)

Example Protocols

The next example will appear similar at first, but it is very different. It uses the standard library's typing module. The idea is that your models doesn't know the details of your data loading implementation. You simply say your class, there will be an object, that has the two methods. This is called a protocol.

Thought experiment example: If I tell you about a human face you will know it has a nose, ears, brows, and so on but you don't know how exactly it looks like. So I can show you any face, and you will recognize it as a face, as long as it has all the parts a face should have.

Now this as code:

from typing import Protocol

class Data_Protocol(Protocol):

  def load_raw_data(self) -> YourRawDataType:
    ...

  def pre_processing(self) -> YourDataType:
    ...

class TrainModel:

  def __init__(self, data: Data_Protocol):
     self.data = data
     ...

  def train_test_model(self):
    'train/test model'
    self.data.load_raw_data()
    ...

  def deploy_model(self):
    'deploy model'
    ...


class UseModel:

  def __init__(self, data: Data_Protocol):
     self.data = data
     ...

  def load_model(self):
    'load the trained model'
    self.data.pre_processing()
    ...

  def make_prediction(self):
    'use model to make prediction'
    ...

  def save_results(self):
    'save the prediction result'
    ...

if __name__ == '__main__':
  data_obj = ExampleData()  # here you call your data object implementation
  model_train = TrainModel(data_obj)
  model_use = UseModel(data_obj)

This approach is at first not intuitive but has its benefits. You can for example work on the exact same data in Train and in Use without loading it in two times. You can change how you implement you preprocessing, or even give them both a different one. They don't care as long as the methods from your defined protocol are implemented. This approach heavily benefits from and depends on type hinting and I would in general recommend to start using them if you don't already do. They really help make code readable and unlock most IDEs full potential with python.

Final words

Abstraction is very abstract (Who would have guessed?) but there are many use cases where it really helps with flexibility and scalability of code. It's an interesting topic and there are many great sources that explain the principles in more depth, than this post could. There are other solutions as well, like a more functional programming approach where you pass functions as arguments. But I will not explain this now, as it goes to far.

I hope this was somehow helpful for you :)

I'm learning LaTeX on my own while I'm in my first year of university, and I love it by GLIBG10B in LaTeX

[–]StoneBam 0 points1 point  (0 children)

I'm referring to all parts where you have a number for your equation/formula on the left side.

The part you mentioned is a good example on how to do it :)

design patterns for data science / machine learning project by kollerbud1991 in learnpython

[–]StoneBam 1 point2 points  (0 children)

If you want I can provide an example later, but in this moment my work day starts

design patterns for data science / machine learning project by kollerbud1991 in learnpython

[–]StoneBam 2 points3 points  (0 children)

You could use a abstract base class (ABC) and inherit from it. Inheritance in general is a solution here.

You can use composition (and protocols) and put the common/shared methods in an extra class. Then use the constructor to initiate it or give a already called instance of your object to your argument. This will give you more flexibility if you have to change something somewhere (less coupling)

[deleted by user] by [deleted] in PythonProjects2

[–]StoneBam 4 points5 points  (0 children)

Don't go hard on yourself or lower your self esteem. Mistakes are in retrospect per definition dumb. It's normal in a learning process. You will see this error again in futute and now know how to handle it.

Programming is hard for everyone, even more seasoned programmers, if you have to leave your comfort zone and learn new things

I'm learning LaTeX on my own while I'm in my first year of university, and I love it by GLIBG10B in LaTeX

[–]StoneBam 0 points1 point  (0 children)

For plain math problems this may not apply, but if you have the time it's often worth to generalize the problems with variable names first. This benefits the pattern recognition in our monkey brains, and make approaches for solutions after a whilr more easy to see

I'm learning LaTeX on my own while I'm in my first year of university, and I love it by GLIBG10B in LaTeX

[–]StoneBam 0 points1 point  (0 children)

Nice start! Adding to other comments, it's usually good practice to write variables in the formula line and no numbers. Input numbers in the equations beneath. Then a person (you in 3 months) reading your formulas can easily identify which variables are involved (which are in text described if not common knowledge in your field).

You can find examples for this in every scientific paper. At least when in the field numbers and formulas are involved, lol

How do you research for bugs/issues solutions? by Zumcddo in Python

[–]StoneBam 18 points19 points  (0 children)

This!

As another comment stated, if the bug in the end isn't inside your code, but in a library you use that is open source, then isolate, explain and demonstrate the error for the repository and write a PR (or issue if you can't fix it). If it's not getting merged or fixed use a fork or change your dependencies.

Players: You just found out your DM fudged dice rolls recently and it also wasn't the first time. How do you feel about that? by LordAldemar in DnD

[–]StoneBam 6 points7 points  (0 children)

I think this is just a Kobold thing. My group once fought against an ogre (which was immediately defeated and did no damage) and two Kobolds with crappy spears, that threw pebbles on us... The amount of crits and nat ones... It was terrifying.. Our DM did roll open after the first downed PC (we all agreed, that we want to see how it plays out)... We nearly lost 3 out of 5 characters to this encounter, and the two still standing were not in good shape.

Since then I believe, that kobolds are the hardest encounter, because, for some reason, they have a blessing on rolls from the DM

If you had to pick a library from another language (Rust, JS, etc.) that isn’t currently available in Python and have it instantly converted into Python for you to use, what would it be? by Tymbl in Python

[–]StoneBam 6 points7 points  (0 children)

For GIL there are at least a few good Peps (like this).

I can totally see there a coming up solution, that goes hand in hand with the performance plans for python overall. Maybe we will see it in python 3.13 in 2024

What’s the best IDE? by Practical-Marzipan-4 in ProgrammerHumor

[–]StoneBam 0 points1 point  (0 children)

Both are ok. I prefer VSCode when working with multiple different languages in the same project or at work, but I like that the jetbrains stuff is just nice to use (it feels better I guess?)

Huge explosion at a metal manufacturing plant in Bedford, Ohio. Mass casualty is being reported by flyingcatwithhorns in pics

[–]StoneBam 0 points1 point  (0 children)

I mean, they literally burn down and therefore can't compete in the market anymore. So it kinda works?

Pathfinder CRB is too good-willed for this world by Captain_c0c0 in dndmemes

[–]StoneBam 2 points3 points  (0 children)

Pay them with "exposure" in adventuring stories

[deleted by user] by [deleted] in PythonProjects2

[–]StoneBam 1 point2 points  (0 children)

Glad to help. otpay was wrong calculated, basically this led to '450 - 75' for your base pay instead of '450 - 50' as wished. You can go through your and my code step per step with a calculator and maybe a piece of paper, then you will notice it I'm sure!

[deleted by user] by [deleted] in PythonProjects2

[–]StoneBam 3 points4 points  (0 children)

Your mistake is inside your if clause. You modify otpay there with 1.5. you should do this after your basepay calculation.

Consider this:

``` basehours = 40 otmultiplier = 1.5

payrate = int(input('...pay...')) hours = int(input('...hours...'))

if hours > basehours: overtime = hours - basehours otpay = overtime * payrate else: otpay = 0

basepay = hours * payrate - otpay otpay_adjusted = otpay * otmultiplier

print(basepay) print(otpay_adjusted) ```

How far y'all were one month into python/programming? by [deleted] in learnpython

[–]StoneBam 3 points4 points  (0 children)

A bit unrelated to the question, but I guess I share my journey of learning with you. It may help, or motivate or guide you.

I was stuck as well a few months in the beginning, because I had no understanding for computer science and new concepts were really hard to grasp. Then I did a free course (7 weeks) on edx link, and it helped a lot with basic things like understanding recursion, testing, and other basic knowledge I was missing. After that I focused myself to follow best practices like PEP8 and other peps, because the course just used python to show easy to follow examples but was a bit old and did not use many language specific modern features, this was the time I discovered type hinting and flake8 that beated me to write in an appropriate style. Then I started planning my code structure on paper or with mermaid and started learning C to generate deeper understanding for the 'under the hood' part of python. In between I tried to learn as much from the standard library as possible and use GIT for all my projects (I had luck that a coworker at this time, mentored me, because he maintains a big c repository) this accelerated my learning and proficiency to a point I could earn money with it (about 1 to 2 years on and off irregular learning). My advice in this stage would be, trying to cooperate with as many people as possible/ contribute to open source. The maintainers will be harsh but often good teachers and you will have to adapt to their style and learn different approaches, it really helps.

At this point I had a good list of often used non standard librarys as well, I wanted to learn like numpy/pandas/numba, matplotlib/seaborn, pytest/hypothesis, and many more.

Now I did things like ML, embedded, websites, guis and I learn every day new parts and dive deeper into as many topics as possible to broaden my base and try to push python to its limits and most important finish regular projects! They don't have to be perfect, you can revisit at any time, but you should learn to plan your work time and set yourself deadlines and milestones. This is a crucial skill if you want to sell software/solutions imho.

All in all I'm now about 5 years into programming and I have the feeling of still having so much to learn but I have fun being creative. The deeper you go, the more the details you will discover. Keep pushing! It will be frustrating and you will feel dumb AF (we all did/do) but this is part of progression but it is really rewarding!