cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

What is the programming paradigm in Mathcad?

rking-2
1-Newbie

What is the programming paradigm in Mathcad?

I have some experience in C language, and I know the structured programming, and in the structured programming there are no the "functions": break and continue as there are in MathCad programming.

Prog_Mathcad.png

In Mathcad the programing paradigm is object oriented, declarative or another?

1 ACCEPTED SOLUTION

Accepted Solutions
StuartBruff
23-Emerald II
(To:rking-2)

rking-2 wrote:

I have some experience in C language, and I know the structured programming, and in the structured programming there are no the "functions": break and continue as there are in MathCad programming.

In Mathcad the programing paradigm is object oriented, declarative or another?

Mathcad is a mix of declarative and functional.  Functions are (almost) first class objects and can be passes as arguments and returned from programs / functions.   With the addition of a few simple functions to cater for implicit loops, I can often write a worksheet in a functional form that transfers well to, for example, Haskell.

I suggested object-oriented as an extension about a decade ago (my, how tempus has fugited!). 

Stuart

View solution in original post

8 REPLIES 8
StuartBruff
23-Emerald II
(To:rking-2)

rking-2 wrote:

I have some experience in C language, and I know the structured programming, and in the structured programming there are no the "functions": break and continue as there are in MathCad programming.

In Mathcad the programing paradigm is object oriented, declarative or another?

Mathcad is a mix of declarative and functional.  Functions are (almost) first class objects and can be passes as arguments and returned from programs / functions.   With the addition of a few simple functions to cater for implicit loops, I can often write a worksheet in a functional form that transfers well to, for example, Haskell.

I suggested object-oriented as an extension about a decade ago (my, how tempus has fugited!). 

Stuart

RichardJ
19-Tanzanite
(To:rking-2)

C has both break and continue statements, and they do the same things as the break and continue statements in Mathcad.

Trying to compare C to Mathcad is kind of like trying to compare a fish to a dog. They are so far apart that it probably doesn't make much sense. If you do want to make such a comparison, then in addition to what Stuart has said Mathcad worksheets can also include things that are best thought of as objects (such as graphs and controls). I certainly wouldn't call it "object oriented" though.

Perhaps we could give you a better answer if we knew the reason behind your question.

Hello Richard

The C language has statements "break" and "continue" of course the C language, but they are not accepted by the structured programming, the book "C how to program" of Deitel and other say it.

My question is motivated to find a language with the same paradigm of Mathcad programing (or at least the same statements) and practice because I have not found much information programming in Mathcad.

LucMeekes
23-Emerald III
(To:rking-2)

"because I have not found much information programming in Mathcad":

Look up the "Help" in the "Resources" tab and open the help book on "Programs". There you will find information on programming and some examples.

There's also a "Programming Tutorial" in the "Tutorials" book in the "Help".

Success!

Luc

StuartBruff
23-Emerald II
(To:rking-2)

rking-2 wrote:

Hello Richard

The C language has statements "break" and "continue" of course the C language, but they are not accepted by the structured programming, the book "C how to program" of Deitel and other say it.

My question is motivated to find a language with the same paradigm of Mathcad programing (or at least the same statements) and practice because I have not found much information programming in Mathcad.

"Structured Programming" is only a methodology for writing programs.  It is a good idea, but it should not be taken as the Ultimate Word - it can, paradoxically, make programs more difficult to read, by adding extra layers of nesting and "control" variables to allow a single point of exit from a block of code.   C has break & continue, Javascript has them, Swift (Apple's new language) has them, Java has them, Python has them, etc, etc.   I generally use structured programming, with a somewhat functional style (preferring to keep functions as small and general purpose as I can), but appropriately used break & continue statements can make a program not only shorter but more readable, both of which decrease the chances of coding errors creeping in and make the code easier to maintain.

Stuart

Some bedtime reading ... 😉

coding style - Are `break` and `continue` bad programming practices? - Programmers Stack Exchange

Knuth - 1974 - Structured Programming With Go to Statements

http://cs.stanford.edu/people/eroberts/papers/SIGCSE-1995/LoopExits.pdf

RichardJ
19-Tanzanite
(To:rking-2)

I have to agree with Stuart, and disagree with whatever book(s) you have been reading. The objective of structured programming is to create code in chunks that are easy to understand (and therefore less prone to errors) and reusable. If I have a short loop, it is much easier to see what a break or continue statement will do than it is to see what some contrived conditional statement will do. The fact that the loop has more than one exit point does not inherently make it difficult to understand what it does. It could be argued that such a statement in the middle of a very large loop is a non-obvious trap, but it could also be argued that in well structured code such a very large loop should not exist in the first place,

As for the paradigm of Mathcad:

Mathcad is a whiteboard interface that is, mostly, WYSIWYG. Placement of statements is free form, and they are executed from top left to bottom right. The statements can be function definitions, variable assignments, special blocks of code such as solve blocks, etc. A special type of variable is provided, a range variable, that acts as an iterator, or loop variable. Some people, especially those coming from Excel, write worksheets where every step of the calculation creates a new vector or matrix of data, and range variables are used extensively. While that is possible, it is what I (and many others) would consider bad programming. The right way to do it is to create a series of dependent functions that carry the variables of interest to the end of the calculations, and then calculate the final result. Of course, some intermediate results may also be of interest, but the principal is the same. Range variables should almost never be used for anything other than indexing into vectors or matrices, or to define the range of the independent variable on a graph. In addition to the above, a worksheet can have blocks of text (basically, extensive comments), graphs, controls (in Mathcad 15, not in Prime) etc.

Note that in the above, I said nothing about "programs". You can do a lot without programs, and in fact there was no such feature until (I think) Mathcad 6. Programs exist because it's very difficult to do certain things without them, and even if you can it may be very hard to understand how it works. Programs can be very large, but then they are hard to understand, so a better way to structure them is again as dependent functions, each of which may be just math expressions, or small programs. The final program then calls those functions, so it's more compact and easier to understand. So programs should rarely be large, which is why the use of continue, break, and return statements is acceptable.

In a Mathcad document, most of the structure is at the worksheet level, not within any (hopefully) small program that is a part of that larger structure.

StuartBruff
23-Emerald II
(To:RichardJ)

Nice summary Richard. 

VladimirN
24-Ruby II
(To:rking-2)

Video "Programming with Mathcad Prime" on PTC's Learning Exchange site: Tutorial: Programming

Top Tags