imperative-programming

What GUI libraries are not object-oriented? [closed]

。_饼干妹妹 提交于 2019-12-06 06:43:58
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . I have been using C a lot lately, and want to explore programming more than just console applications. However, most GUI libraries are

Convert recursive binary tree traversal to iterative

馋奶兔 提交于 2019-12-05 20:52:11
I was asked to write the iterative version, but I wrote the recursive version i.e. void inorderTraverse(BinaryTree root) { if(root==NULL) printf("%d",root->id); else { inorderTraverse(root->left); printf("%d",root->id); inorderTraverse(root->right); } } I'm not looking for the code, I want to understand how this can be done. Had it been just the last recursive call, I would have done void inorderTraverse(BinaryTree root) { while(root!=NULL) { printf("%d",root->id); root=root->right; } } But how do I convert to an iterative program when there are two recursive calls? Here are the type

Are programs in functional languages more likely to have stack overflows?

青春壹個敷衍的年華 提交于 2019-12-05 10:32:28
I am starting to learn ocaml, and am really appreciating the power of recursion in the language. However, one thing that I am worried about is stack overflows. If ocaml uses the stack for function calls, won't it eventually overflow the stack? For example, if I have the following function: let rec sum x = if x > 1 then f(x - 1) + x else x;; it must eventually cause a stack-overflow. If I was to do the equivalent thing in c++ (using recursion), I know that it would overflow. So my question is, is there built in safeguards to prevent functional languages from overflowing the stack? If not, are

What GUI libraries are not object-oriented? [closed]

醉酒当歌 提交于 2019-12-04 13:45:42
I have been using C a lot lately, and want to explore programming more than just console applications. However, most GUI libraries are object-oriented, and it is very difficult to program with them in programming languages which are not object-oriented such as C. Even object-oriented GUI libraries such as GTK+ that are designed for C require a lot of boilerplate. Because I am having difficulty with these object-oriented libraries I am wondering what GUI libraries are not object-oriented? I don't know of any modern GUI toolkit that isn't object oriented. OO is simply a very useful programming

Replacing functions with Table Lookups

▼魔方 西西 提交于 2019-12-03 06:02:17
I've been watching this MSDN video with Brian Beckman and I'd like to better understand something he says: Every imperitive programmer goes through this phase of learning that functions can be replaced with table lookups Now, I'm a C# programmer who never went to university, so perhaps somewhere along the line I missed out on something everyone else learned to understand. What does Brian mean by: functions can be replaced with table lookups Are there practical examples of this being done and does it apply to all functions? He gives the example of the sin function, which I can make sense of,

Why are simple for loop expressions restricted to integer ranges?

南笙酒味 提交于 2019-12-01 15:06:30
According to the F# spec (see §6.5.7 ), simple for loops are bounded by integer ( int aka int32 aka System.Int32 ) limits start and stop , e.g. for i = start to stop do // do sth. I wonder why the iteration bounds for this type of for loop are required to be int32 . Why not allow uint32 ? int64 ? bigint ? I'm aware that sequence iteration expressions ( for ... in ... ) can iterate over arbitrary sequences; that however requires allocating an iterator and calling MoveNext and Current and what not and can thus be considerably less efficient than a plain loop could be (increment counter, compare,

Why are simple for loop expressions restricted to integer ranges?

谁说胖子不能爱 提交于 2019-12-01 13:58:25
问题 According to the F# spec (see §6.5.7), simple for loops are bounded by integer ( int aka int32 aka System.Int32 ) limits start and stop , e.g. for i = start to stop do // do sth. I wonder why the iteration bounds for this type of for loop are required to be int32 . Why not allow uint32 ? int64 ? bigint ? I'm aware that sequence iteration expressions ( for ... in ... ) can iterate over arbitrary sequences; that however requires allocating an iterator and calling MoveNext and Current and what

Haskell vs. procedural programming in the real world [closed]

我们两清 提交于 2019-11-30 01:14:19
These days I'm getting seriously into functional programming. While I'm really excited about Haskell and the possibilities it seems to offer, I can also see now that it is going to take me a while to learn. In an SO question on How to learn Haskell an answer states that it'll take months if not years to actually "master" it. Now, I know C, PHP, some object oriented stuff, etc. And having been told that Haskell isn't much used out there in "the real world", will I be better off improving my skills in the regular languages I know? Is Haskell worth the struggle? In this question on Why people

Mixing object-oriented and functional programming

自闭症网瘾萝莉.ら 提交于 2019-11-29 22:58:09
What languages are available that promote both object-oriented and functional programming? I know that any language that supports first-class functions can be considered functional, but I'm looking for a syntax that's specifically targeted for both coding styles. Using such a language, I'm imagining isolating all state changes to a single portion of code and having the rest of the program be purely functional. Just thinking of it makes me drool (debugging heaven!). So far I've discovered Scala although I've only just heard of it (and it looks amazing). Are there any big contenders in this

Idiomatic clojure for progress reporting?

馋奶兔 提交于 2019-11-28 16:51:28
How should I monitor the progress of a mapped function in clojure? When processing records in an imperative language I often print a message every so often to indicate how far things have gone, e.g. reporting every 1000 records. Essentially this is counting loop repetitions. I was wondering what approaches I could take to this in clojure where I am mapping a function over my sequence of records. In this case printing the message (and even keeping count of the progress) seem to be essentially side-effects. What I have come up with so far looks like: (defn report [report-every val cnt] (if (= 0