Funny that you say that, as when I learnt Scala at uni maybe 6 years ago, they did not start with normal loops but got straight into the functional way of doing things.
To me it seems that scala introduced loops and all of the other imperative concepts to make migration of codebases from Java to Scala easy, however it seems that having so many features makes it lack a certain philosophy and direction.
@@rockthejvm but 'for loop' doesn't have mutable indexing statement like "i = i+1" inside its block. so should it be safer in concurrent-workload environment?
You mentioned how foreach is different from that of Java and that here it is higher order function taking another function as argument. When I opened this foreach function by the standard library, I see it is actually using a while loop to iterate over the elements. So does it not make it same as Java ?
I would agree that functions are better than loops in dealing with data structures, but what about the case where I want to loop in a game? Maybe I'm programming a chess game and I want to alternate between 2 players and that requires a loop. Do I stick to loops or should I use recursion for that?
You can still use recursion, of course. Look, loops aren't the devil. You can use them, that's why the language supports them. The point I want to make in the video is that learning Scala needs to come with learning a different mindset, and learning just the Scala syntax while keeping the old imperative mindset is a disservice to the learner.
@@rockthejvm Ah thanks for replying quickly! I've decided to use loops for the main part of the game, since recursion and passing state is pretty tedious with that, but I'll put them off for other parts of the program.
Funny that you say that, as when I learnt Scala at uni maybe 6 years ago, they did not start with normal loops but got straight into the functional way of doing things.
That's the idea! I'm simply amazed how many Scala tutorials and trainings start with variables and loops.
To me it seems that scala introduced loops and all of the other imperative concepts to make migration of codebases from Java to Scala easy, however it seems that having so many features makes it lack a certain philosophy and direction.
Thank you for all your content. I already finished your Udemy Scala courses and they are amazing. I am about to start the Spark course, soooo excited!
Glad you like them!
Your channel getting hits rapidly, keep going ! Awesome content
You surely have amazing content in your channel Daniel.!! Love the fact that you also have the information documented in your blogs.!
Much appreciated - more to come!
@@rockthejvm Awesome, will look forward to it.. :)
So do you think for comprehensions are good or bad? They seem similar to 'do' notation in Haskell.
For comprehensions are actually pretty awesome, because they're expressions not instructions.
great series thanks
What do you think about regular 'for loop' (eg. in Java)? Is it better or safer than 'while loop'?
It's not the syntactic form that makes the difference. The Java for/while loops mean the same thing.
@@rockthejvm but 'for loop' doesn't have mutable indexing statement like "i = i+1" inside its block. so should it be safer in concurrent-workload environment?
You mentioned how foreach is different from that of Java and that here it is higher order function taking another function as argument. When I opened this foreach function by the standard library, I see it is actually using a while loop to iterate over the elements. So does it not make it same as Java ?
The difference is in how you think code.
I would agree that functions are better than loops in dealing with data structures, but what about the case where I want to loop in a game? Maybe I'm programming a chess game and I want to alternate between 2 players and that requires a loop. Do I stick to loops or should I use recursion for that?
You can still use recursion, of course.
Look, loops aren't the devil. You can use them, that's why the language supports them. The point I want to make in the video is that learning Scala needs to come with learning a different mindset, and learning just the Scala syntax while keeping the old imperative mindset is a disservice to the learner.
@@rockthejvm Ah thanks for replying quickly! I've decided to use loops for the main part of the game, since recursion and passing state is pretty tedious with that, but I'll put them off for other parts of the program.
Bought all three of your courses on Udemy. Thank you
Enjoy them!