On the ground of problems with tab indentation, see my former thread, I now instead use spaces as indentation (as I suppose the majority of you do too, or what?)
Using spaces comes at a price, though: Each indentation of mine consists of three spaces. For deeper nested/indented structures of code these, I think, becomes quite tedious to enter.
Therefore, the following question: When using Shift + Enter, that is, creating a new line, is there some way to tweak Maple to automatically position the cursor (inserting automatically the right number of spaces) at the same position as the beginning of the line above it?
spaces, tabs, etc
About the spaces/tabs - I know this is a weird way to go about it, but if I'm doing something that's going to require a lot of tabs, I just create 3 spaces on a blank line, and then copy it to the clipboard and then if I'm doing something that requires any nesting that I want to look nice with indentions/per nest, I just hit "ctrl-V" to insert however many of the 3-space blocks (tabs) I want.
Same thought here
Thanks for your idea, which, I must admit, I have already considered myself. But, so far, I have not used it because I very often copy-paste Maple code snippets back and forth in my programs, so you can imagine the mess which that could result in if I forget what is currently on my clipboard.
Anyway, I still find it very hard to understand that the tabbing problem have not been caught in any testing process at MapleSoft prior to the release of Maple 11. But, of course, I am only here repeating my earlier expressed frustrations.
It was known
As far as I know, it was known, but not considered an important enough problem to hold up the release.
If only there was a way for Maple users to have more input on the relative priority of certain bugs...
I am disappointed with MapleSoft
Honestly to say, I am disappointed with MapleSoft (but maybe it is just me being naive concerning the way software development is done!?), because this, maybe to MapleSoft insignificant, tabbing misbehaviour is a source of daily frustration to me.
Actually, since my update from 9.5 to 11 my research activity using Maple has significantly reduced; all my programs written in 9.5 are no longer readily editable because of this tabbing misbehaviour.
As a direct result of that, I have kind of lost the feeling of fun working with Maple because it feels like it is working against me, in a certain sense analogous to the worst parts of Word's auto-substitutions, etc. Having also spend a lot of money on updating I think you can understand my frustration.
tabs bug and programming style
I agree that sometimes what are objectively very small issues can be subjectively quite large. Both for Maple and for other systems, both for good and for ill.
In the case of tabs, I suspect that Maplesoft did not see the problem as seriously as you, because (according to JacquesC) the developers tend to use external editors.
I do not use such editors, for the same reason as you. For me, though, tabbing is a not an issue, because I rarely indent much. If you are indenting lots, then you are likely writing in an imperative style. Maple provides strong support for that style, but I usually prefer to write in an applicative/functional style (using small procedures and lots of
seq,fold, etc.), for which Maple is also nicely adapted.If you have not tried writing applicatively, you might give it a go. If you are used to imperative writing, applicative can take getting used to, but especially for someone with mathematical training, it can become the preferred option.
Programming style
I have just skimmed trough the page Functional programming, as provided by you, and the related page Imperative programming. You are quite right; I do use the imperative programming style. The reason for that, I suppose, is that in the field of programming I am almost completely self-taught (the only exception, I believe, being a Fortran course back in 1987, at the first year of my university study).
But maybe I should give the functional programming style a try, because, after all, being a theoretical physicist mathematics should not be a complete stranger to me :-).
Use an editor
Myself, whenever I have code that is more than 3-5 lines long, I always switch to a ``programmer's editor'' (like vim or emacs) to do the work. Indenting is then automatic, and various other editing tasks are much simpler. Plus I get syntax-highlighting too, which is now a must for me. I can't stand editing monochrome code anymore, it is just too painful.
Unix ... I am lost!
Thanks for your suggestion.
I have looked a bit at VIM, Emacs, and jEdit (the latter suggested by Will in another thread), but it seems to me, that there are too much Unix hocus-pocus (tar- and gz files, I am lost!). Of course, I might be completely mistaken, and if affirmative, please correct me.
Anyway, I do not think that working in a text editor would really suit me. You see, the way I work is very iteratively, hitting Enter in Maple very often to check that small changes work as intended. This would entail having to copy-paste back and forth very often between the text editor and Maple.
and now am found...
Yes, if you do go the route of using an external editor, you will have to invest some time in setting it up and learning to use it effectively. I use Emacs, for which the investment is larger than most. The reward, however, is commensurate (or is that commiserate 8-).
I almost never copy and paste between the editor and Maple, at least not in the way you envision. When working on a small procedure, I just send the entire procedure to Maple (the Emacs mode has a command for doing so). I can also send it to mint, which does syntax checking and highlights errors. Or click on a procedure name and immediately bring ups its help page. It is quite effective. For larger stuff, I generally have a separate test file, "compile" the code and save it to a library, and then run the test file, which may also have debugging commands embedded. Compilation and execution is done in a separate shell, but is usually done with one or two keystrokes (using the shell's command history).
Overwhelming
Thanks for all your info concerning how to work outside the Maple editor. But, please forgive me, it just seems too overwhelming. I just want to carry on writing some packages of mine, checking some physical equations of mine, etc., without having to learn about shells and editors originating, as far as I have understood, from another operating system such as Unix, just because Maple 11 cannot figure out something as completely trivial as tab indentation.
I know what you mean.... but
It does seem like it would be a rather nice "convenience" item but why do you really need it? I've written some really deeply nested code in regular C as well as Maple without any "dressing it up" with tabs or even line breaks except where things were starting to wrap the screen. Making things look nice is really just for making it easy to go back to later, make it easier for someone else to understand, or at the minimal, so people who look at your code won't think you're some kind of hack.
If you're at the place in a project, consider forgetting about making it look nice until it's working and then go back and make it look presentable.
This feature that you refer to is something I would really like to see Maplesoft add as well, but if I had a choice between something like this and something that really matters at the mathematics end of things, or bug related, I think I'd choose the latter.
maintainable code
Tim, this is not how to write programs. This is how to make a mess of your life, and have lousy programs to boot.
Many people like to take pride in their workmanship. And most people come to view their programs later on.
about pride
I suppose pride is a good thing... or at least something that most of us are burdened by.
Whenever I'm confronted with a situation like this, I think back to a scene in a movie called "A River Runs Through It" The father had his son write an essay. The father reviewed it several times until he was satisfied that his son had done well. After he was satisfied with the work he told his son something like, "Now throw it away and go play".
Not that I'm that way... but sometimes I wish I were.
Aesthetics and maintainability
To me aesthetics is part of any thing I strive for. Without it any achievement of mine becomes just cold to me, like a machine having made something that works, but without the soul of beauty. Our world today is overwhelmingly replete with this ugliness of streamlined efficiency.
Apart from the question of maintainability, that is why indentation in codes is of imperative importance to me, which again is the reason why the present indentation problem in Maple is such a frustration to me.
kudos to you Joe
... for learning Emacs. I no longer work with unix, but back when I did I tried learning the Emacs editor and found it rather overwhelming and ended up just doing everything with the VI editor. As you suggest, it's a very good and powerful editor and I wished I had taken the time back then to learn it.
arena for maintaining code
I'd like say that what Joe has described is a very good way to develop and maintain non-trivial Maple code source.
To my mind, it's not a question of Windows vs Unix. It's a question of scripts & commandline versus GUI, for non-trivial code development and maintenance. Windows too has batch files.
A plaintext file will always be accessible, while .mla and .mw may be less reliable.
The procedures and modules that comprise one's source may be saved into a .mla archive, and used conveniently from any worksheet (not just that one containing the code!) via the libname mechanism.
Source being stored in plaintext files, combined with use of the "TTY" shell-based Maple interface (cmaple.exe), allows one to use the #define and #include directives as implemented in Maple.
External editors can provide very nice Maple language specific syntax highlighting. There are plenty of editors for Windows, even graphical ones, that provide automatic indentation in a solid way.
The Worksheet and Document facilities of the Maple GUI are very nice for developing worksheets and documents. But there are better ways to develop and maintain a Maple code base.
acer
That is how I do it too
And, as far as I know, how it is still done internally at Maplesoft.
Some tools really missing in the setup described by acer are:
1) proper literate programming
2) integrated help file generation
3) integrated unit tests
Nothing simple, I guess
So, the conclusion seems to be that there is no simple solution to a simple problem. What a down.
something "kinda" simple
implementing some of the ideas already presented:
Even though there seems to be no solution to your immediate problem with Maple not doing as you'd like, some of the ideas given here are very useful and can be put to immediate use.
For example, you can download the Windows based, opensource, "tswebeditor" for free:
http://www.tswebeditor.tk/
it does all the neat highlighting, indent, etc.
You can then make a simple file using it, for example, "myFile.whatever", that contains:
MyModule := module()
export tProc1, tProc2;
option package;
tProc1 := proc()
print("this is tProc1");
end proc;
tProc2 := proc(x, y)
x+y
end proc;
end module:
you can then load Maple and enter:
read "c:\\myFile.whatever";
MyModule:-tProc1();
and get the results:
"this is tProc1"
If you want to make any changes, just go back to the editor, make the changes and save, go back to the Maple worksheet and execute the same lines, or any other line to test the results.
using this method, you can create and test code right away, and as Acer suggested, you'll always have it saved in text format - a good thing.
You can put anything in that file, just as if you were in the Maple worksheet. For example, I could have added the line:
plot(sin(x));
on the next line and the "read" would cause that to be plotted as well.
I hope this helps.
Now we are talking
Thanks for this concrete post.
I have just downloaded and installed tsWebEditor, written a short test-module, saved it as a text-file, and imported it into Maple. And it works :-).
I have never before imported anything into Maple, probably quite a surprise to you guys. So these issues are quite new to me, which, I suppose, is the reason that I have felt quite overwhelmed by the content of previous posts in this thread.
Maybe I am becoming a bit to demanding now, but how do I turn on Maple specific highlighting? For instance, I cannot find "Maple" under the list of Languages in Editor Settings -> Code Insight.
read it again
I added something since you may have read that message.
Using the "module" code may have confused you. Be aware that you can "read" anything into maple as if it were a worksheet, so basically all you need in the Maple worksheet is the read... line - that's it. Everything else can be done in the file within the editor. For example if you do:
plot(sin(x));
plot(cos(x));
in that file in the editor and then read it into maple with that one read... line, you will get two plots on the screen.
good luck.
Library archives
The ability to re-use the code can be done with another refinement. Instead of using `read` on the source file one can `savelib` it to a .mla archive. (See ?LibraryTools, or ?savelib).
Once the code is saved into a .mla library, then in any other worksheet or session one can access it simply by appending to `libname`. (See ?libname)
Once comfortable with that, the following observation can be useful. If the code has been abstracted out of the worksheets that run it, then one may never need to simple `read` the source file into any session except the one in which it gets `savelib`d. A natural followup is to then hard-code the appropriate savelib/LibraryTools commands right into the end of the source file. Or comment it out when not being actively developed.
One could even write a batch file that simply runs the source file with the commandline interface. When run, it saves the program to the right .mla.
The tasks are then nicely split:
- editing with your favourite editor
- saving the source to a .mla archive
- adding the right libname to worksheets.
But these actions can all be run concurrently. I usually have a restart in my worksheet, too, so that I can edit, re-load, and re-run examples, all without having to close out my worksheet session.
Another refinement is to have a "standard" place that you put your .mla archives. One can probably create a desktop icon that starts maple with some extra -b options, so that that location is automatically appended to libname.
acer
splitting source code
The Maple initialization file can and should be created/modified. It can reassign libname so that any Maple session can find a user library.
One of the many advantages to coding in an external editor and saving to an mla (Maple archive) rather than using the read commmand in Maple is that you can then use preprocessor macros. The most useful is $include (see ?preprocessor). It allows you to split a module assignment into multiple files. For example:
Whether this is an advantage to the user depends on the ability/preference to work with multiple files versus a single large file. And that depends somewhat on the editor/os environment. If your editor permits working on only one file at a time, then you will want to instantiate multiple editor sessions. That wasn't feasible/practical when I first started writing Maple code, on a win 95 machine, so I usually kept all the source code in one large file.
thanks Joe
You and Acer have provided some really useful information.
mint
Another benefit of having large projects' maple source in text files is that one can run mint against them. That is a syntax and code analyzer for maple.
See ?mint for the help-page. On Windows it's called wmint.exe , and allows one to browse, select, and open a test source file. (Often the extension .mpl is used for such files.)
The mint program may not be as up-to-date as it could be, but it's still useful.
acer
that's really neat
I never even knew that existed.
I just gave it a try and it worked well. When you mentioned a .mpl file, I was thinking it might require a special format but all that was required was that I add the .mpl extention to any plaintext file and run wmint against it - neat!
Thanks.
Sigh
It is a rampant disease in IT, and some connected fields - if it's not new, it can't be good. mint is very very old.
Maple sits in a weird niche, because while it straddles IT and math - and mathematicians know that old theorems are just as good as new ones.
Perhaps we should find a way to reprint the user manual for Maple 3.3 [I have a copy!]. It documents lots of techniques that seem to have all but disappeared from the (offline) documentation of pointy-clicky Maple. The only mention of 'mint' is on p.330 of the Programming Guide, as a footnote to the [horribly slow and even less up-to-date] maplemint.
maplemint
There is also a maplemint procedure. I don't use it, preferring the more capable standalone program, but it can be used inside the GUI.
clarification on process?
I found this thread informative, but I could use a little more help.
Could you kindly elaborate on the steps you use to write code using an external editor? I've written a lot of code in many languages, but I'm having trouble with navigation in Maple, not so much the syntax.
I created a procedure in a worksheet, then with the LibraryBrowser, created a mla in which I stored the procedure.
I see no way to edit this procedure. I tried to create a *.mpl and a *.m file, but the Browser would not let me add the procedure to the mla. In the latter case, it said that the *.m is obsolete.
I would like to, as acer and jacques do, use an external editor. But I don't see how to add a text file source code to the mla.
Lastly, is there documentation on this "development" cycle? I couldn't find it. And the applications engineer from MapleSoft was gonig to have to check and get back to me.
thank you for any help you can offer this neophyte!
eric
it's like compilation
You could think of the process as similar to that of compilation of C source and linking of the .o object into a dynamic library.
In that C analogy, when one wishes to amend the code, one doesn't usually disassemble the object file (though it's possible, sometimes with varying degrees of difficulty). Usually one goes back and edits the source file, and then recompiles and relinks it into a .so/.dll/.dylib.
The usually same is true for Maple, provided that you have the source file. Edit the source file, run maple against it, and then issue a savelib() or LibraryTools call once again to get it into a .mla archive.
If you lack the source file for a procedure, you can often reproduce it by setting interface(verboseproc=3) and calling eval() on the procedure name. If you have issued a writeto() before that eval() call, then you can have the output redirected to a file. A minor amount of cleanup, such as adding a (semi)colon after the `end proc` might well be enough. This sort of approach can reproduce a working, reloadable source file for quite a lot of procedures. But I wouldn't bother with it if I had the source, and I certainly wouldn't bother doing it more than once for a given procedure.
So, I would keep the sources of larger projects in plaintext file. I'd edit them with and fast lightweight editor such as `vi`. I'd familiarize myself with the commandline maple interface (cmaple on Windows), and become familizaried with how to save to .mla archives. As plaintext, I'd never have to worry about losing valuable source embedded in a more easily corruptible or unviewable Worksheet or Document. And I could set my .mapleinit or maple.ini file so that my .mla archives were easily accessible across maple sessions.
Others may prefer to do it differently.
acer
an example
An example. First I create a .mla Maple archive (GUI or commandline session, no matter)
Then I save a procedure to that archive. This bit could be automated by a nice batch file written to run cmaple against input source files which define procedures. The point is that the procedure below would be defined in a plaintext file, and not a .mw or .mws file. The source file would get read into cmaple, not the GUI. The LibraryTools:-Save call could be present in the source file or concatenated by the batch script.
Then, in a new session (GUI or commandline session, your choice) the procedure is available.
> restart: > libname:=kernelopts(homedir),libname: > p(3); 9acer
many thanks!
acer,
thanks! that is very helpful explanation!
i really appreciate your quick and thorough response.
kindest regards,
eric
A surprise
What was the most surprising in this thread for me, was that some people still seem to continue using Maple for more than 3-5 lines of code! I think, I stopped doing that about 5-6 years ago.
Who needs Maple when there are Python, SciPy, SAGE etc. with tons of editors, IDEs, graphics tools, excellent support etc.
_______________
Alec Mihailovs
Maplesoft Member