<p>What are your opinions on developing for the command line first, then adding a GUI on after the fact by simply calling the command line methods?</p>

<p>eg.</p>

<blockquote>
  <p>W:\  todo AddTask "meeting with John, re: login peer review" "John's office" "2008-08-22" "14:00"  </p>
</blockquote>

<p>loads <code>todo.exe</code> and calls a function called <code>AddTask</code> that does some validation and throws the meeting in a database.   </p>

<p>Eventually you add in a screen for this:  </p>

<pre>
============================================================

Event:    [meeting with John, re: login peer review]

Location: [John's office]  

Date:     [Fri. Aug. 22, 2008]  

Time:     [ 2:00 PM]

[Clear]  [Submit]

============================================================
</pre>

<p>When you click submit, it calls the same AddTask function.</p>

<p>Is this considered:  </p>

<ul>
<li>a good way to code</li>
<li>just for the newbies</li>
<li>horrendous!.</li>
</ul>

<p><strong>Addendum:</strong>  </p>

<p>I'm noticing a trend here for "shared library called by both the GUI and CLI executables." Is there some compelling reason why they would have to be separated, other than maybe the size of the binaries themselves? </p>

<p>Why not just call the same executable in different ways:</p>

<ul>
<li><code>"todo /G"</code>  when you want the full-on graphical interface</li>
<li><code>"todo /I"</code>  for an interactive prompt <em>within</em> <code>todo.exe</code> (scripting, etc)</li>
<li>plain old <code>"todo &lt;function&gt;"</code> when you just want to do one thing and be done with it.</li>
</ul>

<p><strong>Addendum 2:</strong>  </p>

<p>It was mentioned that "the way [I've] described things, you [would] need to spawn an executable every time the GUI needs to do something."  </p>

<p>Again, this wasn't my intent. When I mentioned that the example GUI called "the same <code>AddTask</code> function," I didn't mean the GUI called the command line program each time. I agree that would be totally nasty. I had intended (see first addendum) that this all be held in a single executable, since it was a tiny example, but I don't think my phrasing necessarily precluded a shared library.</p>

<p>Also, I'd like to thank all of you for your input. This is something that keeps popping back in my mind and I appreciate the wisdom of your experience.</p>

[{'answer_id': 18990, 'author': 'Stu', 'author_id': 414, 'author_profile': 'https://Stackoverflow.com/users/414', 'pm_score': 3, 'selected': False, 'text': "<p>Put the shared functionality in a library, then write a command-line and a GUI front-end for it. That way your layer transition isn't tied to the command-line.</p>\n\n<p>(Also, this way adds another security concern: shouldn't the GUI first have to make sure it's the RIGHT todo.exe that is being called?)</p>\n"}, {'answer_id': 18994, 'author': 'Shog9', 'author_id': 811, 'author_profile': 'https://Stackoverflow.com/users/811', 'pm_score': 1, 'selected': False, 'text': "<p>Kinda depends on your goal for the program, but yeah i do this from time to time - it's quicker to code, easier to debug, and easier to write quick and dirty test cases for. And so long as i structure my code properly, i can go back and tack on a GUI later without too much work.</p>\n\n<p>To those suggesting that this technique will result in horrible, unusable UIs: You're right. Writing a command-line utility is a terrible way to design a GUI. Take note, everyone out there thinking of writing a UI that <em>isn't</em> a CLUI - don't prototype it as a CLUI.</p>\n\n<p>But, <em>if you're writing new code that does not itself depend on a UI</em>, then go for it.</p>\n"}, {'answer_id': 18995, 'author': 'Matt Hamilton', 'author_id': 615, 'author_profile': 'https://Stackoverflow.com/users/615', 'pm_score': 3, 'selected': False, 'text': '<p>Joel wrote an article contrasting this ("unix-style") development to the GUI first ("Windows-style") method a few years back. He called it <a href="http://www.joelonsoftware.com/articles/Biculturalism.html" rel="nofollow noreferrer">Biculturalism</a>.</p>\n\n<p>I think on Windows it will become normal (if it hasn\'t already) to wrap your logic into .NET assemblies, which you can then access from both a GUI and a PowerShell provider. That way you get the best of both worlds.</p>\n'}, {'answer_id': 18998, 'author': 'Cristian', 'author_id': 680, 'author_profile': 'https://Stackoverflow.com/users/680', 'pm_score': 2, 'selected': False, 'text': '<p>It\'s probably better to start with a command line first to make sure you have the functionality correct. If your main users can\'t (or won\'t) use the command line then you can add a GUI on top of your work.</p>\n\n<p>This will make your app better suited for scripting as well as limiting the amount of upfront <a href="http://en.wikipedia.org/wiki/Bikeshedding" rel="nofollow noreferrer">Bikeshedding</a> so you can get to the actual solution faster.</p>\n'}, {'answer_id': 18999, 'author': 'Steve', 'author_id': 2019, 'author_profile': 'https://Stackoverflow.com/users/2019', 'pm_score': 2, 'selected': False, 'text': "<p>If you plan to keep your command-line version of your app then I don't see a problem with doing it this way - it's not time wasted. You'll still end up coding the main functionality of your app for the command-line and so you'll have a large chunk of the work done.</p>\n\n<p>I don't see working this way as being a barrier to a nice UI - you've still got the time to add one and make is usable etc.</p>\n\n<p>I guess this way of working would only really work if you intend for your finished app to have both command-line and GUI variants. It's easy enough to mock a UI and build your functionality into that and then beautify the UI later.</p>\n\n<p>Agree with Stu: your base functionality should be in a library that is called from the command-line and GUI code. Calling the executable from the UI is unnecessary overhead at runtime.</p>\n"}, {'answer_id': 19001, 'author': 'AgentConundrum', 'author_id': 1588, 'author_profile': 'https://Stackoverflow.com/users/1588', 'pm_score': 2, 'selected': False, 'text': '<p>@jcarrascal  </p>\n\n<p>I don\'t see why this has to make the GUI "bad?"<br>\nMy thought would be that it would force you to think about what the "business" logic actually needs to accomplish, without worrying too much about things being pretty. Once you know what it should/can do, you can build your interface around that in whatever way makes the most sense. </p>\n\n<p>Side note: Not to start a separate topic, but what is the preferred way to address answers to/comments on your questions? I considered both this, and editing the question itself. </p>\n'}, {'answer_id': 19002, 'author': 'bmavity', 'author_id': 2001, 'author_profile': 'https://Stackoverflow.com/users/2001', 'pm_score': 2, 'selected': False, 'text': '<p>I think it depends on what type of application you are developing. Designing for the command line puts you on the fast track to what Alan Cooper refers to as "Implementation Model" in <a href="http://books.google.com/books?id=04cFCVXC_AUC&amp;dq=alan+cooper+implementation+model&amp;pg=PP1&amp;ots=jfukV6o2oL&amp;source=citation&amp;sig=_T9wipBcKuO-eobfI3cjvzzsOak&amp;hl=en&amp;sa=X&amp;oi=book_result&amp;resnum=11&amp;ct=result" rel="nofollow noreferrer">The Inmates are Running the Asylum</a>. The result is a user interface that is unintuitive and difficult to use.</p>\n\n<p>37signals also advocates designing your user interface first in <a href="http://gettingreal.37signals.com/ch09_Interface_First.php" rel="nofollow noreferrer">Getting Real</a>. Remember, for all intents and purposes, in the majority of applications, the user interface <em>is</em> the program. The back end code is just there to support it.</p>\n'}, {'answer_id': 19027, 'author': 'Mike Stone', 'author_id': 122, 'author_profile': 'https://Stackoverflow.com/users/122', 'pm_score': 2, 'selected': False, 'text': '<p>I did exactly this on one tool I wrote, and it worked great.  The end result is a scriptable tool that can also be used via a GUI.</p>\n\n<p>I do agree with the sentiment that you should ensure the GUI is easy and intuitive to use, so it might be wise to even develop both at the same time... a little command line feature followed by a GUI wrapper to ensure you are doing things intuitively.</p>\n\n<p>If you are true to implementing both equally, the result is an app that can be used in an automated manner, which I think is very powerful for power users.</p>\n'}, {'answer_id': 19031, 'author': 'wusher', 'author_id': 1632, 'author_profile': 'https://Stackoverflow.com/users/1632', 'pm_score': 0, 'selected': False, 'text': "<p><strike>Command line tools generate less events then GUI apps and usually check all the params before starting. This will limit your gui because for a gui, it could make more sense to ask for the params as your program works or afterwards. </p>\n\n<p>If you don't care about the GUI then don't worry about it. If the end result will be a gui, make the gui first, then do the command line version. Or you could work on both at the same time.</strike></p>\n\n<p>--Massive edit--</p>\n\n<p>After spending some time on my current project, I feel as though I have come full circle from my previous answer. I  think it is better to do the command line first and then wrap a gui on it. If you need to, I think you can make a great gui afterwards. By doing the command line first, you get all of the arguments down first so there is no surprises (until the requirements change) when you are doing the UI/UX. </p>\n"}, {'answer_id': 19046, 'author': 'Steve', 'author_id': 2019, 'author_profile': 'https://Stackoverflow.com/users/2019', 'pm_score': 0, 'selected': False, 'text': "<p>@Maudite</p>\n\n<p>The command-line app will check params up front and the GUI won't - but they'll still be checking the <em>same</em> params and inputting them into some generic worker functions.</p>\n\n<p>Still the same goal. I don't see the command-line version affecting the quality of the GUI one.</p>\n"}, {'answer_id': 19048, 'author': 'Jon Limjap', 'author_id': 372, 'author_profile': 'https://Stackoverflow.com/users/372', 'pm_score': 3, 'selected': False, 'text': "<p>My technique for programming backend functionality first without having the need for an explicit UI (especially when the UI isn't my job yet, e.g., I'm desigining a web application that is still in the design phase) is to write unit tests. </p>\n\n<p>That way I don't even need to write a console application to mock the output of my backend code -- it's all in the tests, and unlike your console app I don't have to throw the code for the tests away because they still are useful later.</p>\n"}, {'answer_id': 19059, 'author': 'Michael Stum', 'author_id': 91, 'author_profile': 'https://Stackoverflow.com/users/91', 'pm_score': 1, 'selected': False, 'text': '<p>I usually start with a class library and a separate, really crappy and basic GUI. As the Command Line involves parsing the Command Line, I feel like i\'m adding a lot of unneccessary overhead.</p>\n\n<p>As a Bonus, this gives an MVC-like approach, as all the "real" code is in a Class Library. Of course, at a later stage, Refactoring the library together with a real GUI into one EXE is also an option.</p>\n'}, {'answer_id': 19090, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': "<p>If you do your development right, then it should be relatively easy to switch to a GUI later on in the project.  The problem is that it's kinda difficult to get it right.</p>\n"}, {'answer_id': 19094, 'author': 'Kristopher Johnson', 'author_id': 1175, 'author_profile': 'https://Stackoverflow.com/users/1175', 'pm_score': 1, 'selected': False, 'text': '<p>John Gruber had a good post about the concept of adding a GUI to a program not designed for one: <a href="http://daringfireball.net/2004/04/spray_on_usability" rel="nofollow noreferrer">Ronco Spray-On Usability</a></p>\n\n<p>Summary: It doesn\'t work.  If usability isn\'t designed into an application from the beginning, adding it later is more work than anyone is willing to do.</p>\n'}, {'answer_id': 19101, 'author': 'Christopher Mahan', 'author_id': 479, 'author_profile': 'https://Stackoverflow.com/users/479', 'pm_score': 0, 'selected': False, 'text': "<p>Do a program that you expose as a web-service. then do the gui and command line to call the same web service. This approach also allows you to make a web-gui, and also to provide the functionality as SaaS to extranet partners, and/or to better secure the business logic.</p>\n\n<p>This also allows your program to more easily participate in a SOA environement. </p>\n\n<p>For the web-service, don't go overboard. do yaml or xml-rpc. Keep it simple.</p>\n"}, {'answer_id': 19136, 'author': 'BCS', 'author_id': 1343, 'author_profile': 'https://Stackoverflow.com/users/1343', 'pm_score': 1, 'selected': False, 'text': '<p>A better approach might be to develop the logic as a lib with a well defined API and, at the dev stage, no interface (or a hard coded interface) then you can wright the CLI or GUI later</p>\n'}, {'answer_id': 19179, 'author': 'Mark Cidade', 'author_id': 1659, 'author_profile': 'https://Stackoverflow.com/users/1659', 'pm_score': 5, 'selected': True, 'text': '<p>I would go with building a library with a command line application that links to it. Afterwards, you can create a GUI that links to the same library. Calling a command line from a GUI spawns external processes for each command and is more disruptive to the OS.</p>\n\n<p>Also, with a library you can easily do unit tests for the functionality.</p>\n\n<p>But even as long as your functional code is separate from your command line interpreter, then you can just re-use the source for a GUI without having the two kinds at once to perform an operation.</p>\n'}, {'answer_id': 19244, 'author': 'grom', 'author_id': 486, 'author_profile': 'https://Stackoverflow.com/users/486', 'pm_score': 0, 'selected': False, 'text': '<p>In addition to what <a href="https://stackoverflow.com/questions/18984/what-do-you-think-of-developing-for-the-command-line-first#18990">Stu</a> said, having a shared library will allow you to use it from web applications as well. Or even from an IDE plugin.</p>\n'}, {'answer_id': 19841, 'author': '17 of 26', 'author_id': 2284, 'author_profile': 'https://Stackoverflow.com/users/2284', 'pm_score': 1, 'selected': False, 'text': "<p>I would not do this for a couple of reasons.</p>\n\n<p>Design:</p>\n\n<p>A GUI and a CLI are two different interfaces used to access an underlying implementation.  They are generally used for different purposes (GUI is for a live user, CLI is usually accessed by scripting) and can often have different requirements.  Coupling the two together is not a wise choice and is bound to cause you trouble down the road.</p>\n\n<p>Performance:</p>\n\n<p>The way you've described things, you need to spawn an executable every time the GUI needs to d o something.  This is just plain ugly.</p>\n\n<p>The right way to do this is to put the implementation in a library that's called by both the CLI and the GUI.</p>\n"}, {'answer_id': 27017, 'author': 'Thomas Vander Stichele', 'author_id': 2900, 'author_profile': 'https://Stackoverflow.com/users/2900', 'pm_score': 0, 'selected': False, 'text': "<p>There are several reasons why doing it this way is not a good idea.  A lot of them have been mentioned, so I'll just stick with one specific point.</p>\n\n<p>Command-line tools are usually not interactive at all, while GUI's are.  This is a fundamental difference.  This is for example painful for long-running tasks.</p>\n\n<p>Your command-line tool will at best print out some kind of progress information - newlines, a textual progress bar, a bunch of output, ... Any kind of error it can only output to the console.</p>\n\n<p>Now you want to slap a GUI on top of that, what do you do ? Parse the output of your long-running command line tool ? Scan for WARNING and ERROR in that output to throw up a dialog box ?</p>\n\n<p>At best, most UI's built this way throw up a pulsating busy bar for as long as the command runs, then show you a success or failure dialog when the command exits.  Sadly, this is how a lot of UNIX GUI programs are thrown together, making it a terrible user experience.</p>\n\n<p>Most repliers here are correct in saying that you should probably abstract the actual functionality of your program into a library, then write a command-line interface and the GUI at the same time for it.  All your business logic should be in your library, and either UI (yes, a command line is a UI) should only do whatever is necessary to interface between your business logic and your UI.</p>\n\n<p>A command line is too poor a UI to make sure you develop your library good enough for GUI use later.  You should start with both from the get-go, or start with the GUI programming.  It's easy to add a command line interface to a library developed for a GUI, but it's a lot harder the other way around, precisely because of all the interactive features the GUI will need (reporting, progress, error dialogs, i18n, ...)</p>\n"}, {'answer_id': 41648027, 'author': 'SystematicFrank', 'author_id': 253098, 'author_profile': 'https://Stackoverflow.com/users/253098', 'pm_score': 0, 'selected': False, 'text': '<p>That is exactly one of my most important realizations about coding and I wish more people would take such approach.</p>\n\n<p>Just one minor clarification: The GUI should not be a wrapper around the command line. Instead one should be able to drive the core of the program from either a GUI or a command line. At least at the beginning and just basic operations.</p>\n\n<p><strong>When is this a great idea?</strong></p>\n\n<p>When you want to make sure that your domain implementation is independent of the GUI framework. You want to code <em>around</em> the framework not <em>into</em> the framework</p>\n\n<p><strong>When is this a bad idea?</strong></p>\n\n<p>When you are sure your framework will never die</p>\n'}]
['https://Stackoverflow.com/questions/18984', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1588/']