44

At my university, I have a yearly essay. I'm allowed to use any technology for implementing it. I've been coding it in C++ with Qt. I thought of about Wolfram Mathematica because I have some experience in it.

I need such functionality:

  • Timers — for calling functions by timer
  • Threads (or Processes are good too)
  • User-friendly GUI (buttons, input forms)
  • Be able to catch when user clicked left/right mouse buttons or key on keyboard
  • Dynamic graphics (with changing graphics in time)
  • Launching applications as a standalone executable file

I'm ready to put more effort into it. But I wonder whether I'm burying myself alive trying to implement things which Mathematica isn't devoted to do.

I would appreciate links to topics marked with questions signs.

How bad is this idea? What are your opinions? Should I do it in C++? (Doing it in Mathematica would be challenging for me.)

enter image description here

Tebe
  • 571
  • 5
  • 7
  • 6
    why downvote? Pls, downvote me, but give explanations why – Tebe Nov 27 '13 at 19:30
  • 2
    Hi gekannt! It is difficult to ask this kind of thing here, because it involves opinions and discussion, and these are not the preferred type of question (see here). I would suggest that you try a small proof of concept using CDF technology - if it looks promising, spend a bit more time on it. The demonstrations site gives a good idea of what visuals you can expect. – cormullion Nov 27 '13 at 19:55
  • 5
    I see this as a question along the lines "Does Mathematica have these listed capabilities, or something fairly close?" Strikes me as a perfectly reasonable query. Re Threads, there is support for parallelism but not sure what might be needed. I think the rest is all available, albeit the "launch as stand-alone" would require at least CDF Player on the receiving end. If I understand correctly what's wanted, which I may well have wrong. – Daniel Lichtblau Nov 27 '13 at 20:11
  • 4
    You are doing a school project that involves all that? This sounds like an operating system you will be building :) But you can browse http://demonstrations.wolfram.com/ and see what kind of apps are there. Some are simple and some are more complex. Mathematia is more higher level language than C++. If you want to do lots of system level stuff, it might not be the best for that. But if you want to spend more time on the science and analysis and the GUI part, then Mathematica is best for that. It makes building GUI much simpler than Qt and Java. – Nasser Nov 27 '13 at 20:12
  • 2
    @DanielLichtblau so you wouldn't recommend C++ over Mathematica then? :) – cormullion Nov 27 '13 at 20:21
  • 16
    In my opinion, Mathematica is not great for this kind of application. Mathematica is great for interactive use, and also for creating functions that a user might work with interactively. But it's not well suited for making standalone GUI programs. It's great for making a quick and dirty Manipulate during interactive work, and much more convenient than anything else I know. But once you need to make that GUI refined, foolproof, and fast, it becomes very painful. – Szabolcs Nov 27 '13 at 20:28
  • @Cormullion I agree you have a point, to the effect that the question could get into religious war territory. And I will also say that it's quite possible that C++ might be the better choice (sorta depends on the pesky details..). I was just trying to give a rough indication to the effect that Mathematica might be a reasonable choice for the stated purpose. (And yeah, I thought your comment was funny and gave it a checkmark). – Daniel Lichtblau Nov 27 '13 at 21:01
  • @cormullion and Nasser on the contrary the demonstrations site has very rigid specifications which result in quite a limited subset (extremely limited with interface design) of what can be produced. The CDF examples are more indicative of what can be produced as a stand alone app -- but even then they are just examples. – Mike Honeychurch Nov 27 '13 at 21:48
  • Not sure whether the question belongs here. For a start is the assignment to write an essay or to build an app? Maybe to write an informative essay you need to build the app (?) The short answer is that Mathematica can create a stand alone interface along the lines of what you seek -- please see the CDF examples. But I think building interfaces for CDF deployment is a relatively steep learning curve (for professional/commercial deployment). If you already know how to do this in another language then it is probably more efficient to stick with that. If you decide to do this in Mma ... – Mike Honeychurch Nov 27 '13 at 21:54
  • ...then I'd suggest starting by pulling apart the CDF examples created by Wolfram Research and learn how they did it. – Mike Honeychurch Nov 27 '13 at 21:55
  • @MikeHoneychurch I think what is called an essay at the OP's uni might be called a project, at least in the mathematical sciences, in the US. – Michael E2 Nov 27 '13 at 23:29
  • 8
    I wish WRI would make an actual compiler that generates a .EXE. Matlab has one (even though the generated code runs at the same speed as the interpreted version since it is not a real compiled native, but to Matlab pcode, but runs under a run-time library (the actual engine), which is native), it still allow one to make a .EXE of a Matlab GUI apps. I think WRI can make a similar thing. That will go a long way to making Mathematica more used. Make it free compiler, no restriction. – Nasser Nov 27 '13 at 23:46
  • @MichaelE2 thanks for clarifying. I suspected it might have been english as a second language problem. – Mike Honeychurch Nov 27 '13 at 23:57
  • Although I regularly, consistently get 2 downvotes everytime I post a solution that uses JLink, I want to mention the fact that using JLink and/or NETLink for several tasks is not only an "acceptable", but even recommended way to implement solutions that require features that go beyond "stock" M. JLink and NETLink and MathLink are officially part of M, and the marketing materials support this. The o/p is talking about threads and kernels, and you obviously can get more threads than kernels (which is a licensing restriction, not a technical one), so linking to the JVM or .Net is perfectly – Andreas Lauschke Jan 01 '14 at 21:38
  • valid. In addition, by using the JVM or .Net you have multiple programming languages available as well. I think the misunderstanding that many/most M hobbyist users have is that they are too much in love with the M language that they forget that M in and of itself is primarily a technology platform (I can support this with official marketing materials). WRI claims publicly that all of Java has become part of M (same would be true for .Net, by analogy). And you simply can't control threads from M, you need a parallelism framework such as is implemented in the JVM and in .Net. – Andreas Lauschke Jan 01 '14 at 21:42
  • Both posters below (as of 20140101, evening EST) confirm the problems you're getting into when trying to develop UIs. Obviously, you can create UIs in M that you can't create in the JVM or .Net, but also likewise, you can create UIs in the JVM and .Net that you can't create in M. In the end, what's possible vs. what's not possible depends on the question. The M f/e and the CDF are great if all you want is features already supported by the M system. Go beyond it, and you're stuck. Already the first item in the o/p's list, timers, is not really doable in a practical manner. And the timers in – Andreas Lauschke Jan 01 '14 at 21:46
  • "stock" M defer to Java, we just don't realize it, because it's "hidden" in code that calls into Java under the hood. Ultimately, this group should decide what they/we mean by referring to M. The language, or the technology platform. The hobbyist users in this group, which comprise a large chunk, if not the majority, will see M as the language only. They want to see solutions only that can be punched into the M f/e. But M is much more. M is an enabling platform (again, I'm using official marketing materials). And what also doesn't help is the o/p's reference to a uni project. – Andreas Lauschke Jan 01 '14 at 21:49
  • That already makes it valid to nix this question. But ultimately, I think this question should be discussed in a much broader context, maybe on the community platform, because it's valid outside a uni context. – Andreas Lauschke Jan 01 '14 at 21:53
  • @gekannt I don't think that the last comment in your question is necessary. Let people choose if they want to upvote or not. I believe that your question can really help people to know about how hard is to develop interfaces with MMA. It's not a Linux/Windows question type, maybe a Paintbrush/Photoshop. – Murta Jan 02 '14 at 03:16

2 Answers2

56

As an Eterprise CDF user, I can say I have really tried, and my current opinion is that creating a standalone GUI program with the Wolfram Language is not an easy/commercial/deliverable task at the moment. Here are my points:

  1. All the interface controls are very limited. You will have a lot of difficulty to do basic things like make Tab jump between fields, make your interface evaluate when Enter is pressed, or just put form fields in the right positions.
  2. For free text fields, export to clipboard or create a pdf/xls/txt file with your report is possible only with the Enterprise version.
  3. To distribute the program you (and anyone who recieves it) have to install Mathematica Player, you can't create a standalone executable. It's strange to use a language that can't be easily delivered.
  4. You can't pack your CDF in one file. For big projects, you need to distribute a folder with a file structure inside it, which is very clumsy.
  5. Normally, when you use Dynamic or something similar, your CDF opens with a gray screen with a button that have to be unblocked, giving your work a very unprofessional appearance. enter image description here
  6. You need to see Mathematica advertise ever time you open your Mathematica Player (even in Enterprise edition). enter image description here
  7. You can't hide things like database connections inside your code, it's very easy to get the string inside java components. For business applications, you need to refresh data dynamically, and you can't do this in a secure way.
  8. Lack of complete/structured code examples with database connection, nice GUI interface and professional look. You can find some very specific examples like these at wolfram.com, but only very simple toy examples.

These are the main reasons I don't recommend CDF for professional standalone applications, in my vision they are good for toy code, students and individual data exploration. I love Mathematica, but today I have given up developing this kind of application in CDF, maybe Wolfram Language might do something better in the future.

Murta
  • 26,275
  • 6
  • 76
  • 166
  • #1. I wouldn't say that the interface is limited (can you give examples?) but it certainly can be frustrating. Additionally Wolfram made this several versions ago and ticked the box and then moved on without fixing the bugs in subsequent versions. So for creating layouts it is 95-99% ok but the breakages are frustrating. – Mike Honeychurch Nov 27 '13 at 22:58
  • #4 What makes you think that you cannot pack your CDF into one file? ...even for big projects. – Mike Honeychurch Nov 27 '13 at 22:59
  • #5 if you are in a untrusted directory this would occur. But why not startup with a blank panel ad only display content when it is trusted? – Mike Honeychurch Nov 27 '13 at 23:01
  • #6 I've run Player Pro and am not quite sure what you mean. Can you show a screen grab? – Mike Honeychurch Nov 27 '13 at 23:01
  • 1
    About #1, just try to make "Tab" and "Enter" works... Try to designe e nice frame with some fields and make the data be validated without use regular expressions. You have need a lot of dynamics with EventHandler, with very unstable behavior. – Murta Nov 27 '13 at 23:03
  • re #1 I've not encountered problems using "Tab". As far as validation goes how data is validated depends on the data which makes it a case by case problem. I have not experienced problems but then I do not use your data so cannot speak for any problems you may have encountered. – Mike Honeychurch Nov 27 '13 at 23:06
  • About 4#, when your project is a little bigger, you create some packs to organize your functions. You can read packs in DynamicModule, but it has to be in a separate file, so in the actual model you have to distribute a folder with your project inside. I have talked to @AndreKuzniarek this year, the pretend to make it possible in the future, like a ZIP CDF. – Murta Nov 27 '13 at 23:06
  • 3
    #5, it's not a good designe. Imagine today, my users have to open the Mathematica Player, see the advertise screen, click on Enable Dynamics, all the time. – Murta Nov 27 '13 at 23:08
  • #7 & #8 security is definitely an issue but I think database connections, at least for databases supported with bundled connectors, is straight forward. The CDF examples are a good place for people such as this guy to learn about this stuff. Of course they are toy examples but contains some useful tricks. – Mike Honeychurch Nov 27 '13 at 23:08
  • re: #5 I thought with CDF enterprise you can get rid of the trusted path message? For example with the Wolfram CDF examples there are no trusted path warnings. – Mike Honeychurch Nov 27 '13 at 23:10
  • About #6 Agree, post updated. – Murta Nov 27 '13 at 23:12
  • re: #4 you are choosing to organize your code that way. I think that misrepresents what the limitations are. That does not mean you cannot have it all in one file. You certainly can have it all in one file. – Mike Honeychurch Nov 27 '13 at 23:13
  • 1
    rere #4 Yes, you can put all in a giant DynamicModule, but your code get a mass for big projects, impossible to debug in small pieces. There is no SaveDefinition for it as we have in Manipulate. If you want to change part of you code, you have to take all it to outsite the DynamicModule, change it, and put it there again. This is all solved using packages. – Murta Nov 27 '13 at 23:16
  • re #6 set the option so that you do not display that opening splash screen (for Player Pro deployment anyway) – Mike Honeychurch Nov 27 '13 at 23:17
  • There is a SaveDefinitions as of V9 but I never use it. I stick with Initialization – Mike Honeychurch Nov 27 '13 at 23:18
  • rere #6 there is no option for that, I have asked the support. The answer is maybe in next version. – Murta Nov 27 '13 at 23:18
  • There is no SaveDefinitions for DynamicModule. I use Initializations to load my packs, but we come back to item #4 problem. – Murta Nov 27 '13 at 23:22
  • 1
    Actually there is a SaveDefinitions. It is undocumented but is there and it works. Rolf Mertig drew it to my attention. But having said that I never use it. My current project is about 60 pages of code and i have no issue testing all functions separately but including all code within one DM and having it initialize. – Mike Honeychurch Nov 27 '13 at 23:25
  • we are having a Q&A which is outside the scope of what they want here. Maybe email me and we can continue. – Mike Honeychurch Nov 27 '13 at 23:26
  • To explain why I use separated packs will not help other users. I agree with your last Q&A out of scope :). – Murta Nov 27 '13 at 23:29
  • 1
    I completely agree with your points Murta, though I did give up development much earlier due to the lack of detailed examples, limitations and not being standalone. It really makes distributing stuff among colleagues nearly impossible. I also edited your words, hope you don't mind (though I left the very stylistic "I loves Mathematica" in order to maintain uniqueness :) ) – István Zachar Nov 30 '13 at 12:20
  • @IstvánZachar, much better English after your edition! tks – Murta Nov 30 '13 at 21:49
  • 2
    Lots of up ticks to comments and upvotes to this Q&A. This obviously reflects users frustrations but these frustrations stem in part from a lack of understanding of dynamics in Mma and perceived limitations. While it might be useful to have more examples from Wolfram how many users critical of what can/can't be done have pulled apart the existing CDF examples and studied how they work? So in summary I think what I am reading means users skills can be summarized as kernel >> front end >>>> dynamics. This can be seen in many questions in which the problem is not what Mma can do ... – Mike Honeychurch Dec 02 '13 at 20:51
  • ...but the lack of understanding of dynamics of the user and also a lot of times failing to RTFM. – Mike Honeychurch Dec 02 '13 at 20:52
  • Very interested to know if your point of view has changed since this post 3 years ago ... Also, did you find a good alternative (Python , R, Java, ... ) to "replace" MMA ? (I am lot interested in "Dynamics" right now and wondering if I should dig deeper in that direction for deploying GUI app, ...) – SquareOne Feb 02 '17 at 22:32
  • And I just saw this video about the future of CDF (an web deployement) from the WTC2016 where your #4 is discussed (if I understand well ?). – SquareOne Feb 02 '17 at 22:40
21

My experience is that while Mathematica does present some headaches with creating consistent layouts the limitations in creating a professional looking app are limited by your ability to do graphic design. For example most reading this could create a web page. But how many could create a cool looking web page? So there are two aspect: underlying code and functionality and interface appearance. The later is the domain of graphic designers. I certainly do not have abilities in this area but given a layout provided to me by a graphic designer IMO anything would be possible in a Mma interface.

With the caveat that I am aesthetically challenged, here is an example of a simple plotting interface. Some tabs at the top to tab between a plotter and user preferences. Some buttons. Some openers.

enter image description here

Click on the import data button to import data from an Excel file and select columns

enter image description here

Plot the data:

enter image description here

enter image description here

For me the limitations are my imagination [which can be a big limitation :)]. Which is not to say that this couldn't be done easier in another language, just that a lot more can be done with Mathematica than I think people realize.

Mike Honeychurch
  • 37,541
  • 3
  • 85
  • 158
  • 2
    +1 Beautiful CDF. I miss real examples like that in Wolfram page. It's all this code inside one DynamicModule block? Or you use Manipulate with SaveDefinitions? – Murta Nov 28 '13 at 00:45
  • 1
    @Murta the functions are developed in a separate notebook and saved as a .m. I then cut and paste all the functions from .m into Initialization:>{ paste}. For me it is not such a big deal to do that. This is one single DynamicModule. I do not use SaveDefinitions. If I have this in a non trusted path unfortunately the warning is displayed. Wolfram need to provide a means to override this but I think you can in CDF Enterprise?? But I have actually installed this as a palette for plot styling so no warnings. – Mike Honeychurch Nov 28 '13 at 00:58
  • @Murta I learnt a lot from the webaddashboard CDF made by Wolfram. It is worth taking the time. – Mike Honeychurch Nov 28 '13 at 01:02
  • Unfortunately current version of CDF Enterprise (V9) don't fix it. I understand the way you work. In my flow, I have two big standard packs with a lot of functions that I always use (database connection, company standard layouts, personal functions). The code get confuse if I have to copy and past it all the time I change some functions inside this, so I prefer to delivery the separated files using Import inside DynamicModule with Initialization (with the onus of the folder structure). – Murta Nov 28 '13 at 01:07
  • @Murta last year I did write some code to collect functions tagged in a certain way and stick them in Initialization as part of a build of the DM but there were occasional fails and eventually I just found cut and paste just as easy. – Mike Honeychurch Nov 28 '13 at 01:10
  • I hate to worry you. I see you used buttons. I got stuck now with basic binding of button to function when it gets pressed. How did you do it? Now I have : http://mathematica.stackexchange.com/questions/37971/bindevent-binding-own-function?noredirect=1#comment113730_37971 – Tebe Nov 28 '13 at 22:28
  • @gekannt I do not use the GUIKit so I cannot answer your problem. – Mike Honeychurch Nov 28 '13 at 22:48
  • Would you share the code for your example? – murray Feb 09 '16 at 16:36
  • Excellent CDF. Could you please share the example code, or some more hint of the code? I'll be grateful for your kindness. – yulinlinyu Dec 21 '16 at 12:17
  • At some point I will stick this on GitHub – Mike Honeychurch Dec 21 '16 at 22:59
  • @MikeHoneychurch, I'm really expecting for this interesting CDF – yulinlinyu Dec 22 '16 at 07:22