Programming

Discussion in 'General Chatter' started by Morven, Feb 26, 2015.

  1. :D The benefits of being an artist-programmer hybrid. You're welcome, and thank you for the compliment!
     
    • Like x 1
  2. ADigitalMagician

    ADigitalMagician The Ranty Tranny

    So, I'm just going to explain in one sentence how Python variables work, and @autopsyblue can freak out about it because that is the response I get most often from C programmers:

    All variables in Python (including object fields, globals, locals, method and function identifiers, individual array indexes, parameters, you name it) are passed as pointer by reference in all cases.

    Once you understand that, the "weird" stuff in Python starts making sense.

    Also, once I grasped this simple fact about Python, learning pointers and dereferencing was literally a single moment.
     
  3. :P That's how most object-oriented languages work, I'm not freaked out by that.
     
  4. ADigitalMagician

    ADigitalMagician The Ranty Tranny

    In my experience that isn't how it's done, but okay. :-P (Go doesn't do it, though barely object oriented. I feel like Java doesn't do it that way, either.)
     
  5. Hmmm. Not sure I know enough to say either way.
     
  6. Wiwaxia

    Wiwaxia problematic taxon

    quick question:

    so i've got a situation where i'm trying to write a method that modifies the fields of an object it's in based on the fields of a different object it's passed, and i'm trying to write a function within it to handle the general form of modifying for each pair of external/internal fields. problem is I can't figure out how to pass it the fields within the object themselves to be modified, rather than passing it the values of those fields and having it modify those on a local scope only. I considered using returning, but then if the field doesn't need to be modified, I don't know how to keep if from adding e.g. None or an empty list to the list or set field being modified.

    Code:
        def modify(self,modifierObject):
            def error(want,field,modifierObject=modifierObject):
                return "Expected {} for {} in {}".format(str(want),str(field),str(type(modifierObject)))
            def integerFields(field,name):
                if field:
                    if type(field) == int:
                        return field
                    else:
                        raise TypeError(error(int,name))
                else:
                    return 0
       
           
            self.hp += integerFields(modifierObject.addHp,'addHP')
            self.defence += integerFields(modifierObject.addDefence,'addDefence')
            self.protection += integerFields(modifierObject.addProtection,'addProtection')
            self.fortSave += integerFields(modifierObject.addFortSave,'addFortSave')
            self.refSave += integerFields(modifierObject.addRefSave,'addRefSave')
            self.willSave += integerFields(modifierObject.addWillSave,'addWillSave')
            self.speed += integerFields(modifierObject.addSpeed,'addSpeed')
            self.dropWorth += integerFields(modifierObject.addDropWorth,'addDropWorth')
    
            def (self,givenField,modifiedField,expected):
                if field:
                    if expected == int:
                        if type(givenField)==int:
                            self.modifedField+=givenField
                        else:
                            raise TypeError(error(int,givenField))
                    elif expected == "list or set member":
                        if type(givenField)==str:
                            try:
                                modifiedField.append(givenField)
                            except TypeError:
                                modifiedField.add(givenField)
            
     
  7. BlackholeKG

    BlackholeKG I saw you making fire

    ...I feel like you've probably solved that issue by now, Wax, given the time lapse, so I feel justified in not attempting an answer aha

    Hello, I am reviving this thread because recently (read: a few months back) I revived my programming hobby. I've taught myself C# and am primarily having a shot at programming a game using Monogame (which is like Microsoft XNA, but open source and still supported). I am far from an expert in either, but I am making what is to me some cool stuff nonetheless, and its absorbing a lot of my free time recently, ehe.

    Today I am particularly pleased because I cracked a somewhat difficult task of writing an algorithm to break down arbitrary polygons into triangles based on an array of bounding points, which I can then use to render 2D shapes to the screen. Had to break out all the geometry math that I learned in school and had half-forgotten in order to figure it out ;_; but it's so satisfying to have something that works now! The feeling of accomplishment is real.
     
    Last edited: Mar 26, 2017
    • Like x 3
  8. Immediate gratification is one of the best attractions of programming.
     
    • Like x 2
  9. BlackholeKG

    BlackholeKG I saw you making fire

    Okay, turns out my code wasn't/isn't as non-broken as I thought. Something weird is going on.

    Darnit. I can barely think for tiredness so I guess that full gratification is going to have to wait until tomorrow.
     
  10. BlackholeKG

    BlackholeKG I saw you making fire

    I fixed the thing! Sweet, sweet gratification.

    Mostly, at least. It'll give up if its given input data that it doesn't expect, like in certain configurations where shapes have negative area or such. But if the code is used properly that should never happen unless some other mistake has been made, so I'm good hopefully.
     
    • Like x 1
  11. Part of learning to program safe programs is learning to handle bad user input, though. You should probably make it spit out an error instead. Error handling is an endless slog but important sooooo you just gotta get in the habit.
     
  12. palindromordnilap

    palindromordnilap Well-Known Member

    So, I've been writing a translation for this social network thing, and I don't actually know Ruby or JavaScript so I was just filling in strings following the instructions on the GitHub.
    Except this happens:
    Capture du 2017-04-07 15-23-25.png
     
  13. seebs

    seebs Benevolent Dictator

    Okay, short answer is, somewhere deep in the bowels of the code, a thing is "throwing" an error -- it encountered an error and requested that some caller handle it. And no caller handled it.

    Looking at the diagnostic, it looks like it's probably really the "cannot find module react-intl/locale-data/co", and that in turn suggests that you have a thing called React, and that it wants a module called "locale-data/co", and from other things you've said I'm betting that this is your Corsican language thing. So what you would do is go look at the react-intl/locale-data directory, and look at the things which are there, and possibly create a new thing called "co" like them, only using Corsican.

    Disclaimer: I have no experience with any of the tools you're using.
     
  14. NevermorePoe

    NevermorePoe Nevermore

    does anyone have recommendations for coding tutorials or anything like that?

    [Edit:] or any good starter languages?
     
  15. palindromordnilap

    palindromordnilap Well-Known Member

    The thing is, that isn't actually in the code. I'm assuming it's generated by something else. The other translations didn't seem to get that issue. I'll try taking another look to see if I didn't forget or badly format something.
     
  16. palindromordnilap

    palindromordnilap Well-Known Member

    Here's the documentation on translation, btw. I did pretty much exactly what it said except I edited the French language files instead of the English ones, but that was functionally the same.
     
  17. @NevermorePoe START WITH C. No actually. It's hard to learn for sure, but generally people who start with C are better programmers all the way through.

    If that intimidates you you could start with Java I guess. But C's where it's at, to me.
     
    • Useful x 1
  18. BlackholeKG

    BlackholeKG I saw you making fire

    Yeah, I actually did that in a later version after I realized that the program was still bugging out under certain circumstances. Just drops an error now, like you said.
     
    • Like x 1
  19. Lissa Lysik'an

    Lissa Lysik'an Dragon-loving Faerie

    I started with x86 assembly language :D (thanks, Ancient Guardian, for making it as hard as possible to start with so everything after seems easy).
    C is great for procedural programming - is still one of my two fave languages, and is really good if you expect to be doing low level programming (touching device drivers, for example, or working with limited CPU/memory resources).
    C++ is an alternative starter language because it makes you think about the resources you're using (new/delete instead of relying on garbage collection that other OO languages offer) while giving the advantage of Object Oriented development (useful in many areas, gets in the way in others).
    Starting with something like C# or Java risks not seeing the underlying reasons for why things work the way they do.
     
    • Like x 1
    • Agree x 1
    • Useful x 1
  20. Morven

    Morven In darkness be the sound and light

    I started on 68000 assembly and feel it's helped me immeasurably. This is what your computer is really doing, in terms of externally relevant stuff. At one point I could hand-disassemble x86 from the hex, fairly well, but that's long gone from disuse.

    I think C gives you enough of that to get by with, and the same healthy respect for the brittleness of software. C won't stop you doing stupid things, and that helps learning.
     
    • Agree x 1
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice