In line execution inside function

I really like in line execution of julia code.
However if I put my code inside a main() function (to avoid global variables) I can’t get in line execution inside the main().
Is there a solution to this?
Thank you.

You can step through the code with the debugger, but it is not really the same thing :confused:
If you want to evaluate the code line by line, are you sure that the global variable performance hit is actually hurting you that much? When you pass such a global variable to a function, the function will run compiled and type stable anyway. You pay the biggest price for globals when they are used in ways other than as inputs to functions at the top level.

1 Like

Thank you.
I’m studying the examples with Flux on github and I see that it’s better to organize the code into functions, so I started doing that too.
Do you think is better to put the main code out of a function?

It really depends on

  1. If the price for the global variables is high
  2. The benefit to your workflow from having them global

If you are just starting out with flux, maybe keeping it global will help you get started faster. When you have converged on a model and optimizer, you can organize your code into functions to get the performance benefit.

1 Like