hydra-python-agent-gui icon indicating copy to clipboard operation
hydra-python-agent-gui copied to clipboard

Class components can be replaced with functional components

Open AwesomeChap opened this issue 6 years ago • 7 comments

AwesomeChap avatar Oct 27 '19 19:10 AwesomeChap

Is there a reason why we should do this?

xadahiya avatar Oct 28 '19 03:10 xadahiya

Functional components are easier to read, debug, test and generally provide a performance boost as compared to class based components (. In my opinion class components in some situations introduce unwanted complexities, and when code base scales it tends to become difficult to follow the code and for a new comer it can be pretty cumbersome to get started with the project. So that's some of the reasons I believe class components should be replaced with functional components where ever possible.

AwesomeChap avatar Oct 28 '19 05:10 AwesomeChap

@Guttz ^^

xadahiya avatar Oct 28 '19 05:10 xadahiya

Classes provide much more structure and organisation when compared to functions. This is generally accepted. Functional designs enable faster prototyping, but that does not necessarily mean they are better. Anything you can do with a function, you can do with a class, but the opposite is not true.

If you really think there is a piece of code where a functional approach would be better, please give examples/context.

Creating an issue with a generic statement without providing any context/examples seems unhelpful. :/

chrizandr avatar Oct 28 '19 09:10 chrizandr

Anything you can do with a function, you can do with a class, but the opposite is not true.

This statement might be true for earlier versions of react, But today scenario is bit different. With the help of React Hooks you can do most of the things using functional components as you would have with a class component. A single hook namely useEffect can be used like componentDidMount, componentDidUnmount, and componentDidUpdate. React Hooks are very powerful, all depends on how we use them. Many firms using React our transforming their code bases to use functional components as code becomes much cleaner. So even if they scale, code readability and maintenance would not be a problem. I believe that current code base is going to scale in future (depending on changes/improvements/additions to hydra python agent). So that's why I suggested to use functional components. My stress is not on faster prototyping or fast paced development, but rather cleaner performant codebase, which is easy to read, debug and maintain (Which I think is important for an Open Source Project).

AwesomeChap avatar Oct 28 '19 11:10 AwesomeChap

Those are good points, @AwesomeChap. Ofc this is not a one-sided discussion and there are people who don't agree with hooks conception and would opine differently, but overall they're been accepted.

Perhaps the priority might not be the highest one, there might be other things discussed in other issues that would have a bigger impact for now, but this change would also be welcome.

gustavodemorais avatar Oct 29 '19 20:10 gustavodemorais

I want to work on this issue please assign this issue to me

piy1577 avatar Feb 21 '23 21:02 piy1577