Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Monthly Food For Programmers

  1. C

    9 vote(s)
    45.0%
  2. Python

    8 vote(s)
    40.0%
  3. I will suggest a different language in my post

    3 vote(s)
    15.0%
  4. No. Don't waste your time.

    0 vote(s)
    0.0%
  1. Nov 8, 2006 #1
    I'm considering starting a journal, where every month I post an article that analyzes some aspect of programming subjectively. The article will consider a problem, analyze it in depth, and delve in to a solution with snippets. All the while, it will hopefully teach readers about some more advanced theoretical concepts in programming, given that the reader has the fundamental basics of the language covered. Simultaneously, the article will explain the code to those that are just beginning to learn the language and implicitely define any vital terminology and mathematical concepts above the level of Calculus.

    I am not claiming, in the slightest, that I am one of the top programmers here. I definitely don't believe that. However, I know I have information that I can share and hopefully help others with.

    If you like my idea, and would honestly like to see it in action... I need your genuine response to this idea. I really don't feel like wasting my time because a couple of people thing it's "neat" or "useful". If people feel they could benefit from this, please let me know! I'd be more than happy to help some people out with this monthly food.

    I have attached a poll at the top for the language which you think I should consider writing the articles for. I have considered the languages Python and C, because I think I may enjoy writing it more. Doing a language like PHP would consider practical applications of these programs, more than it would actually incorporate theoretical concepts of mathematics and computer science. This, unfortunately, strays away from the purpose of these articles. You can find documentation for languages like PHP anywhere, that's not the point of this.

    C and Python can both be looked at very closely. C is the industries' most commonly used language two years consecutively, and a vital language for any person interested in programming, to know. I'd also expect more people here to know it than any other language.

    Python, although the more lesser acknolweded, is the steam train of programming. You can never stop finding useful imports or ways to approach a problem. A while ago, I posted on another forum "500 ways to program numbers 1 to 10", a thread where the main goal was to come up with as many ways to output the numbers 1 to 10 in a programming language of your choice. About 80 of those posts were by me, and almost every one was written in Python, approaching the problem differently and uniquely each time.

    The advantage of Python over C is we can also dive in to more concepts like object-oriented programming with inheritence, metaclasses, functions that modify themselves, and the list goes on. I'm just a bit iffy about doing Python because I'm afraid not as many will tune in or benefit from the endeavour.

    Please do tell me what you honestly think.

    - Sane
     
    Last edited: Nov 8, 2006
  2. jcsd
  3. Nov 8, 2006 #2

    0rthodontist

    User Avatar
    Science Advisor

    Sounds like a good idea! I'd like to see Common Lisp. You've got more interesting language features with that than with most anything else. Haskell is prettier but not as powerful :frown: . Besides, the world needs more functional programmers.
     
  4. Nov 8, 2006 #3
    Well, the problem with choosing an understudied and underused language like Lisp or Haskell, is not as many people will be able to draw the information as easily from the article. Examples will not do them any justice. As well, readers would have a more difficult time applying what they've learned, and even finding the article online in the first place. I doubt many people go looking around for articles written in Haskell or Lisp.

    But do consider, that C is a functional programming language. Although it can synthetically behave as an object-oriented language, it is indeed functional.
     
  5. Nov 8, 2006 #4

    0rthodontist

    User Avatar
    Science Advisor

    A functional programming language is one in which every function is well-defined given its inputs--every function is a mathematical function of its inputs. Haskell is a pure functional programming language. C is not a functional programming language. Technically Lisp is also not a functional programming language, but it shares many features with pure functional programming.

    Lisp is an incredibly well-studied language, maybe the most well-studied language, having been around far longer than all but one language in current use, and having traditionally been used in largely academic settings. Lisp is very different from most other languages, and that alone makes it worth studying.

    If you ask me, inspiring one programmer to use Lisp is better than drilling 5 programmers in C.
     
  6. Nov 8, 2006 #5

    Hurkyl

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    As much as I like category theory, it's hard to imagine wanting to programming in it. :tongue:

    I agree that it's weird to hear C called a functional language -- that said, you can do functional programming in it.

    Interestingly, the C++ template mechanism is purely functional, and the STL encourages functional approaches to problems. (unfortunately, you still have to go to third-party libraries to get all the useful primitives you'd want)
     
  7. Nov 9, 2006 #6
    I know C is not used as an example for representing functional programming languages, but it can deliver the same behaviour in some respects. For example, you could program Python's map function in C, by using function pointers, which replicates a higher order function. However... it's not intentened to be as functional as certain languages like APL or Haskell.
     
    Last edited: Nov 9, 2006
  8. Nov 9, 2006 #7
    I would absolutely love to see this in Java, I am interested n learning mathematical programing in Java for applications to Physics and Math
     
  9. Nov 9, 2006 #8

    -Job-

    User Avatar
    Science Advisor

    It sounds like a good idea. I think a language that has some interesting features is Javascript.
    One of my favorites is eval(str), which evaluates and runs a string of code.
    An object's methods and properties are indexed by name, so you have true reflection. For example, you can do:
    Code (Text):
    MyObj.MyMethod(param1)
    or you can do:
    Code (Text):
    MyObj["MyMethod"](param1)
    So you can turn this:
    Code (Text):

    function HidePanel(i){
        switch(i){
            case 1:
                this.Panel1.style.visibility = 'hidden';
                break;
            case 2:
                this.Panel2.style.visibility = 'hidden';
                break;
            case 3:
                this.Panel3.style.visibility = 'hidden';
                break;
            case 4:
                this.Panel4.style.visibility = 'hidden';
                break;
            case 5:
                this.Panel5.style.visibility = 'hidden';
                break;
            case 6:
                this.Panel6.style.visibility = 'hidden';
                break;
            case 7:
                this.Panel7.style.visibility = 'hidden';
                break;
        }
    }
     
    Into this:

    Code (Text):

    function HidePanel(i){
        this["Panel" + i].style.visibility = 'hidden';
    }
     
    You can also store functions in variables and pass them around, for example:
    Code (Text):

    Alert = function(){
        alert('hello world');
    }
    //you can assign to event handlers
    //the following sets an object's click to alert 'hello world'
    MyObj.onclick = Alert;
    //you can call it whenever
    Alert();
    //you can pass it along as a parameter to some other function
    function CallFunction(func){
        func();
    }
    CallFunction(Alert);
     
    All of these features allow you to compress your code, for example, or do some interesting recursive or self-writing functions.

    I would be more willing to read something about Python for example, than C or Java since of these 3 Python is the one i haven't used.
     
    Last edited: Nov 9, 2006
  10. Nov 9, 2006 #9
    Unfortunately, I've never actually bothered to look at Java myself. Haven't liked what I've seen. :yuck:

    That's the beauty of a high level language. You'll see these ideas to be even more apparent in Python. You've noticed the desired intentions of a good high level language: elegance, clarity, and simplicity. That is what Python is all about.

    The high-level language aspect of Javascript would not be a good reason to look at it, since javascript is used as a means to an end, not an end in itself. We use it for applications in dynamic webpage content manipulation, when the alternatives are either impossible or irrational. Nothing more. It's not going to be a language I use to talk about implementing crytography or BSTs in. That's the equivilent of trying to use your lawn mower, in order to clear snow from your driveway. :uhh:

    Furthermore, wouldn't it be better for this to be a language that you already know? You should realise that this isn't a tutorial for the language itself. It's about learning how to combine computer science with advanced mathematics (and some Physics, if I have the time). You would want knowledge of the language first. This is why I'm leaning a bit more towards C.
     
    Last edited: Nov 10, 2006
  11. Nov 10, 2006 #10

    0rthodontist

    User Avatar
    Science Advisor

    :surprised What if you change the name of one of the panels?
     
  12. Nov 10, 2006 #11
    :surprised What if you delete one of the functions from the program?

    It's all relative. If you're going to change the names of the panels, then the program has to be changed with it. Hopefully, whoever's mantaining the website's design will know enough to keep it in the format expected by the javascript. Otherwise, it's not going to be changed.
     
  13. Nov 10, 2006 #12

    -Job-

    User Avatar
    Science Advisor

    Exactly, besides, if i change the names around then the original code is not going to work any better either anyway.

    Sane, whatever you write if it's well written i'll read it, i can read about anything in CS. Share the knowledge :).
     
  14. Nov 10, 2006 #13

    robphy

    User Avatar
    Science Advisor
    Homework Helper
    Gold Member

    I like Python.
    For the tasks that I use it for, it's often cleaner than a comparable program in C and in Java, and less cryptic than Perl. When augmented with the VPython package, creating visualizations and real-time animations is easy. Since the Numeric package (soon to be replaced by NumPy) is bundled with VPython, efficient matrix and array operations are optimized.
     
  15. Nov 10, 2006 #14

    0rthodontist

    User Avatar
    Science Advisor

    Well, what if you remove a panel? I very much like the ability of a compiler (or interpreter) to detect when I'm trying to refer to a name that doesn't exist.
     
  16. Nov 10, 2006 #15
    @0rthodontist : In that case, Mozilla will throw an informative warning in the top right corner (red alert icon). Internet Explorer will just say something's wrong in the bottom left corner (yellow alert icon).

    @-Job- : I hope it can be well written. I have some good ideas of how to go about organizing this all, and what to talk about. I am already starting to write things down in my mind. Hopefully this can go well.
     
    Last edited: Nov 10, 2006
  17. Nov 10, 2006 #16
    I like Python too. Its OO is much cleaner and more complete than C++, and not just type-oriented.

    Sane, I don't know if I would find your proposed column beneficial, rather than, in your words, neat or useful (I guess I don't see the distinction). That's kind of like trying to know if you like apples or if they're good for you without ever eating one.

    Why not give it a try? If you've got something to contribute, you'll probably find an audience. I don't know how many physicists make their way down here, but in my experience, most physicists would be well served by seeing some more computational concepts.

    Tim
     
  18. Nov 10, 2006 #17

    0rthodontist

    User Avatar
    Science Advisor

    But when will it throw the warning? I would be pretty surprised if it can detect the missing panel before it actually causes a runtime error.
     
  19. Nov 10, 2006 #18

    Hurkyl

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    And you wouldn't want it to try -- part of the point of javascript is that you can generate pages on the fly, so a perfectly reasonable timeline would look like:

    (1) Write a function that manipulates a panel
    (2) Create the panel
    (3) Invoke the function


    edit: Thinking about it some more, I notice that the kind of error you describe is essentially the same thing that leads to a null pointer exception. Surely you're okay with those being runtime errors?
     
    Last edited: Nov 10, 2006
  20. Nov 10, 2006 #19

    -Job-

    User Avatar
    Science Advisor

    Since there's no compiler for Javascript (interpreted language), you detect errors by running. Instead of compiling, you run your code in FireFox, for example. The exception is thrown at runtime.
    Javascript is probably the least debug-friendly language though.

    EDIT: I agree with Hurkyll as well.
     
    Last edited: Nov 10, 2006
  21. Nov 10, 2006 #20
    @0rthodontist : I don't even get the point you're trying to make ...

    @nmtim : Yes. Understandable. The distinction for me between "useful and nice" and "beneficial", would be the latter requires the reader to make use of the information and benefit, whereas the former only implies that it could be possible.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Monthly Food For Programmers
Loading...