Flutter is a UI Toolkit built by Google which use Dart programming Language and is used to build any Mobile Apps. We code Flutter apps on the channel and make coding related videos.
0 Subs - 1st January 2021 10,000 Subs - 23 July 2021 20,000 Subs - 27 September 2021 30,000 Subs - 14 December 2021 40,000 Subs - 7 February 2022 50,000 Subs - 26 Mars 2022 60,000 Subs - 8 May 2022 70,000 Subs - 9 May 2022 80,000 Subs - 11 May 2022 90,000 Subs - 12 May 2022 100,000 Subs - 18 May 2022
People are overusing this "return early" technique! I've even seen it in places where it's not needed at all and actually makes the code more difficult to maintain. I mean, people seem afraid to use the "else" keyword these days, and it's because of videos like this one, who call nesting bad. It's become ridiculous!
Can someone explain what Repositories (Entities) do and why then it goes to Repositories (Models)? Why doesn't it go directly from Repositories (Entities) to DataSource? What does Repositories (Models) do?
Store all conditions as booleans at the top of the code (you can cast if you need to). Use the booleans in the if-statements. Now there's no nesting, and there's also only one return value
When you're trying to figure out alignment of your widgets (particularly, at 1:45:00), you can do Ctrl-Shift-P (not sure about mac) in VS Code and type "Toggle Debug Painting" to enable "Flutter: Toggle Debug Painting". This will let you see how big the columns/rows are, how much space they're using, why things are located at certain places and so on. Also thanks for the tutorial, it helps a lot!
While nested ifs is never a solution, having a lot of return blocks is not that good either (not sure as of right now, but Sonar also had a "clean code" rule that enforced a single return value per function, and I also recall cyclomatic complexity was affected by the amount of returns. I'd rather have a single "isUserLoggedInAndAdmin" which wraps all the required logic (and can be used everywhere else) abd a single if/else block. Much more readable and easier to debug as specific logic is wrapped where is actually belongs, imho You could even have two functions if you want to enforce maximum modularity: "isUserLoggedIn" and "isUserAdmin". This may look overkill because your example is using basic booleans, but try fetching those statuses out of a token or a db every time on your code and it quickly becomes a copy/paste smell on unexperienced hands..
Its funny how often wrong gets redefined in programming. Way...back When I was a kid, functions have a single exit point. So you had to nest by definition.
1.this is just an example, everybody need to calm down with the "security" stuff... 2.early return is not necessarily a better option 3.try to avoid big nested IF statement.. obviously 4.nobody cares about your unit test, except maybe at university 5.Vive le Quebec !!
Better yet, use an assertion and handle the exception. Why have a function that is supposed to do something and just silently fails while printing a log. Thats just bad code right there. Best bet here is 3 assertions and then a if (wifi && login && admin) to further protect it
I guess you've never heard of, "one way in, one way out." There is also the problem of lazy coders throwing a quick line of code at the end of a function, thinking it will be run when the function exits. There are uses for early returns, but I don't think readability is a good one.