« first day (998 days earlier)      last day (3503 days later) » 

4:47 AM
I'm having trouble understanding how to make these togglable cells in presentations in mma. in the notebooks i download from the website training, when i click a title or so it toggles the open cells, however when i create a slideshow from scratch (using the slideshow palette), I always get an edit cursor.
 
 
9 hours later…
1:46 PM
I just got feedback on my first ever computer assignment..... I failed it :'(
"Interfaces and coding style: Not OK. The coding style is not good, the program is almost impossible to debug due to consistent use of argument function calls. Make the program readable!"
I asked the teacher what he meant. He said that he thought he was perfectly clear: You should always try to avoid to give a function as an argument to a function. I can only pass the assignment if I rewrite my code and avoid doing that.
I almost passed out. Not only does he invalidate almost all code that I've written for the last two years, I am now completely at loss of how I should approach programming problems.
I guess I have to warn him to never ever visit MMA.SE because he will not like the code around here...
 
2:16 PM
Was it a MMA coding assignment?
 
2:32 PM
@blochwave No, it was also my first ever Matlab script.
As I understand it for-loops aren't fast in that language either. I'm just a newbie in that language, but it also seems to me that if you use a "functional approach" then you can vectorize things more easily. In his example code he looped through his matrices/vectors and applied functions to each member. This means that if the operations happen to be such that they can be done in a vectorized manner, he won't be able to. I don't see the point in his programming style at all.
 
2:53 PM
0
Q: correct the award of a bounty

van abelI recently start a bounty for a question, but award it to the answer that not the best, then is there any way to correct this? I don't know where to ask this question (and I don't think this is the right place), but any way, help me!

 
@Pickett I suppose he is very committed to the idea that the order of the text in your code should match the order in which it is evaluated as closely as possible. Functions passed to functions should be written first and given a name because they are often evaluated before the function they are passed into. This means reading the code more closely matches stepping through the code with a debugger.
I certainly don't think that necessarily means it's the best way to do things. You can also make the argument that having lots of nested function calls is better because you then read the code almost backwards, so you start by knowing the final output is a GeoPlot, then you gradually look into it to see the contents, etc.
 
@MichaelHale Hm, yes. Maybe that is it.
 
3:12 PM
@Pickett No, he's right. Functions are not first class citizens in MATLAB and passing function handles was only supported as an after thought. Likewise, anonymous functions are also much slower than the equivalent "normal" function.
It used to be the case that for loops performed poorly in MATLAB and heavily vectorized code (which was unreadable to many) would be blazing fast. However, this is not true anymore either. MATLAB uses JIT compilation these days and so when you have a for loop with simple and transparent indexing and built in functions, it compiles the loop and it runs faster than vectorized code.
 
@rm-rf Interesting. What does this mean in practice if I have something like f(g(x,h(y)))? Should I write it like:
var1 = h(y); var2 = g(x,var1); var3 = f(var2)?
And if I have simple anonymous functions, like numeric ones: f = @(x) x^2 - should these go in their own file or is it ok as long as the anonymous function is not computationally expensive?
 
@Pickett Yes, my understanding is that's what your teacher wants you to do. Although I don't think shortString=StringDrop[string,3];ToUpperCase@shortString is any more readable than ToUpperCase@StringDrop[string,3]. Regarding anonymous functions, if the language doesn't support them well, your decision will often be based on how many times the function is called, not how expensive a single call is.
 
3:27 PM
@Pickett Yes, that's generally the norm/convention when writing MATLAB (or procedural languages in general).
 
oh well...
 
It is true that your form is harder to read with all those parentheses. Languages that support functional programming well often tend to have a way to chain/compose them for clarity
like f @ g @ h @ y in Mathematica or f . g . h $ y in haskell, etc.
And yes, the anonymous functions generally are slower than a separate function (in a file) which is slower than writing it out.
I agree with you that I wouldn't put put something simple like x^2 in a file, but if an anonymous function can be avoided, I'd just include it in the code itself.
 
ok, thanks.
 
3:52 PM
@rm-rf What about subfunctions? Would you use those?
(i.e. function that you define inside the file of another function)
Because I use those liberally but he didn't like that either.
 
I've used them a lot myself and haven't noticed any performance drops. Subfunctions should generally be used only when they're truly local to that main function (similar to defining a helper function inside a Module)
 
@Pickett - I suggest you tell him you're used to "functional" programming languages such as MMA and Lisp, and that you're trying to learn "procedural" programming idioms. Lots of us old guys have never seen functional code and it looks outlandish to us. XSLT was a very rude shock to my system...
 
Also, I wouldn't put too much weight to what the teacher says... good coding style can only be achieved by writing code, making mistakes, seeing other peoples code and picking up parts that work, parts that make life easy, the code clearer, better performing and rejecting those that don't fit these.
A teacher shoving down a particular coding style is only going to produce a roomful of bad coders at the end of the semester ;)
That's just my opinion anyway.
 
4:11 PM
@undefined @rm-rf Thanks for your input, I appreciate it.
 
 
4 hours later…
8:07 PM
@Szabolcs both PolarPlot[1/(1 + 1.1 Cos[z]), {z, 0, 2 Pi},
PlotTheme -> {"Scientific", "Grid"}] and PolarPlot[1/z, {z, 0, 1}, PlotTheme -> "Grid"] work on OS X + MMA 10.0.1 for me
 
8:25 PM
@chris What does "work" mean here? Both run in my case, but are extremely slow in comparison to normal plotting operations.
 
8:43 PM
@kirma same here and actually it did crash later!
 
@chris Thanks for testing! I have trouble with this on two different computers. On one the FE hangs completely, on the other it takes a very long time to render the graphics and then it's nearly impossible to resize them.
I eventually reported it on Friday and WRI support said that they can reproduce the extreme slowness (though not the hang),
A surprisingly quick response from support :)
 

« first day (998 days earlier)      last day (3503 days later) »