one of the most annoying things for me in Mathematica, is that printing or returning expressions generated using local module variable contains those extra $nnnn. There are some hacks to go around these, but these do not work when one wants to use other functions. For example compare:
@HenrikSchumacher difference between Block and module is tricky. according to post here mathematica.stackexchange.com/questions/559/… "Block therefore affects the evaluation stack, not just the literal occurrences of a symbol inside the code of its body. Its effects are much less local than those of lexical scoping constructs" so I think lexical scoping (module) is safer to use, specially for large code.
@RolfMertig thanks. I know there are ways around these, https://mathematica.stackexchange.com/questions/137036/print-expressions-using-local-variables-in-module-without-dollar-sign-is-that-p but the issue is can get complicated. For example: << MaTeX` foo[] := Module[{x, y, s}, s = MaTeX[ x^2 + 3 y]; Print[s] ]; foo[] I do not know how to use MakeBoxes in the above.
@Nasser I think the main concern in using Block would be dynamics so if you run it like PreemptProtect @ Block[... it should be fine. I mean, Table and friends they all use Block under the hood. So at the end I would not even bother with PreemptProtect
@C.E. ok, right, then I guess it depends of the use case.
@C.E. @b3m2a1 I have a question, index.html files are now supported by cloud but I wonder how to use relative sources robustly. I can't use `/assets/logo.png` because `/` refers to cloud base which will almost never be your index.html container.
One could use `./assets/logo.png` and it will work when you start your app from `{cloudbase}/something/myApp/` (index.html dropped) but the way index.html is supported makes `{cloudbase}/something/myApp` (without final /) a valid URL too. It will be found but it will be corrupted because lack of `/` means that `./assets` points to `/something/asset…
@Nasser I think Block is generally fine to use as the main container for the code of a function for as long as that function cannot receive any symbols as input (either directly or indirectly).
For example, f[n_] := Block[{x}, D[x^n, x] /. x -> 1] is not safe because f[a] is a but f[x] is unexpectedly 1. However, if we had f[n_?NumericQ] then it would have been fine.
@C.E. Here the issue is not Block, but the definition of g[]. Solve[2x==1,x] simply doesn't work if x has a value. That could be a global value too, not only a value temporarily set by Block.
With Block, the global symbol x stays the same global symbol x. Only its assigned value changes temporarily. With Module we get an entirely different symbol.
Thus, for as long as we only use a symbol as a "variable", to hold a value, either Block or Module is fine. Once that symbol is allowed to be used as a mere symbol, e.g. in a symbolic calculation, the differences become important.
@Kuba Would you happen to know how it is decided how many moderators an SE site has?
I'm asking, because while math.SE has 10, we have currently only on 2 active. How does a site increase their number of moderators? Last time, when you were elected, we lost Verbeia. So it was a zero-sum-game.
@halirutan I only participated in this and last elections so I don't have much experience or an overview of other subsites, it may differ. From my experience: elections and its specification is not automatic and we certainly are not limited to 5. But I will search around later, have to go now.
@Szabolcs I intentionally made a problematic definition of g, the problem that you are pointing out is what I wanted to convey. Sure, the problem is similar to that of using global variables. But I would also say that we shouldn't use global variables. There are cases where Block and global variables can be used efficiently, they just shouldn't be the first option.
@C.E. But when working interactively, we always use global variables, no? Of course those wouldn't conflict with symbols in a package context. Only global package variables would.
@Kuba Can multiple moderators be appointed after an election?
@C.E. I'm not trying to nitpick, just to show that "avoid Block" is not a universally applicable guideline.
@Szabolcs I think it is a good guideline. I don't like that Block is not local. If I were to use Block, I would have to have a specific reason for it. But I see where you're coming from, I think.
@halirutan It is most likely based on actual need + volume of flags... Currently, JM, Mr.W and myself are mostly inactive, leaving Kuba as the sole active moderator. For that reason, adding +1 makes sense.
However I don't think we need more than that — even though I'm "inactive", I do check in and read things at least 3-4 days/week and I have no flags to handle while I'm online. For some stats, in the past month there were 72 flags of which Kuba handled 32 and the rest were handled automatically by the community. The average resolution time was ~1 hour. This is a fantastic stat for a community and 32/month is not too high for a moderator either so 1 more would be just right.
@VincenzoOliva WA is typically a couple of versions behind Mathematica. That means that the bug may have been fixed, if it is a bug. On the other hand, one cannot be sure that they haven't introduced a new bug, either.