Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 600 601 [602] 603 604 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 908465 times)

Orange Wizard

  • Bay Watcher
  • mou ii yo
    • View Profile
    • S M U G
Re: if self.isCoder(): post() #Programming Thread
« Reply #9015 on: February 13, 2016, 03:36:50 am »

Most languages don't require you to care how the hardware works, though. Your standard C++ compiler or PyPy or whatever will do most of the optimisations for you anyway, and that's assuming your program needs optimal performance in the first place.
So I don't think "Lisp doesn't require intimate knowledge of machine processes" makes much sense as an argument. Programming in Lisp is a different way of thinking, but it's not that different.

The Robinson roguelike is being programmed in Clojure. If that dev can do these sorts of things, I think writing a game in Lisp is perfectly within the realms of possibility.

I mean, I wouldn't want to do it, but it's definitely doable.
There's bound to be SDL/OpenGL wrappers for it somewhere.
« Last Edit: February 13, 2016, 03:38:38 am by Orange Wizard »
Logged
Please don't shitpost, it lowers the quality of discourse
Hard science is like a sword, and soft science is like fear. You can use both to equally powerful results, but even if your opponent disbelieve your stabs, they will still die.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9016 on: February 13, 2016, 04:09:11 am »

Mike Acton's code optimization videos show that just swapping around the x and y loops of a nested loop can slow the code down by a factor of 20 or more. And we're not talking any fancy optimizations or even a different algorithm there: that's for almost identical-looking code running the same algorithm but not taking into account memory access order. So, yeah, I'd say this is probably the single biggest "free" speed boost you're going to get: organize your data so that reads are sequential in memory whenever possible.

The 200ms vs 400ms comparision is unfair: in the real-world you're looking at orders of magnitude slower code by not taking real-world platform characteristics into account. One area that didn't get mentioned is games. When you have 16ms to compute a frame and you want a million polygons on-screen, everything needs to be optimal. That's because anything that's slower than needed eats into your budget for something else. This is obviously important no matter what language you're talking about.
« Last Edit: February 13, 2016, 04:19:16 am by Reelya »
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9017 on: February 13, 2016, 04:19:15 am »

Yeah, algorithmic complexity is ridiculously important. AFAIK Reelya's example with x and y refers to something like this:

Code: [Select]
for (x=0;x<20;x++) {
  for (y=0;y<20;y++) {
    stuff(array[x][y]);
  }
}
/** The above code is much, much faster than the below. */
for (x=0;x<20;x++) {
  for (y=0;y<20;y++) {
    stuff(array[y][x]);
  }
}

IIRC the code is much, much faster for the former mostly because of branch prediction and/or cache misses. I'd probably be able to tell which if I think about it harder, more likely cache misses than branch prediction but it could be both.

Orange Wizard

  • Bay Watcher
  • mou ii yo
    • View Profile
    • S M U G
Re: if self.isCoder(): post() #Programming Thread
« Reply #9018 on: February 13, 2016, 04:33:43 am »

AFAIK Reelya's example with x and y refers to something like this
Oh, that's useful to know. Thanks.
Logged
Please don't shitpost, it lowers the quality of discourse
Hard science is like a sword, and soft science is like fear. You can use both to equally powerful results, but even if your opponent disbelieve your stabs, they will still die.

Antsan

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9019 on: February 15, 2016, 06:09:21 am »

I don't know why anybody would chose not to use an IDE, honestly.
Because most IDEs are visually cluttered, rely on the use of the mouse and often enough automatically generate files I have no control over.
I prefer to use Emacs.

I had to use VS for software testing work for a while. It took minutes to load the rather large project I had to test, because it did all kinds of indexing work I never had anything to do with up-front, blocking the stuff I actually needed to do, like only compiling the damn program so I could test the latest version.

So one of my classes (Principles of Languages) is done in a version of Scheme (specifically Racket, more specifically the legacy Racket language "Pretty Big"). While (being forced into) doing everything recursively is an interesting way of thinking, the lack of the program data divide is being pretty cool, and experiencing the great satisfaction being gained when a 3 line program solves your whole program is pretty awesome; it's horriblefying. I mean I don't particularly enjoy the idea of having to take multiple hours to come up with 4-line simple programs that I could crank out non-recursive versions (that probably work faster due to the C++ compiler) for in like 5 minutes. :P It's not helped by the fact that normal Racket has several very helpful functions that our legacy version doesn't support either. :-\
The time taken to come up with the solution is only a matter of training and writing looping constructs in Scheme should be entirely possible.
Of course they'll be expanded into recursive code, but why should you care about that? The compiler will be doing tail call optimization on it either way, if it is possible to do so.

Quote
And ye gods the parenthesis. I can't imaging how normal coders in similar languages survive; it's already gotten bad enough that I've pretty much said "Screw the 'recommended' official coding style, C's 1TBS style here I come!", since at least it wrassles the parenthesis beast enough to make stuff somewhat intelligible, albeit only a little.
*i2amroy goes and cries into his drink
Use parenthesis highlighting. I am working in Common Lisp, the parenthesis don't even register anymore. I am way more put off by all the different and sometimes seemingly superfluous brackets/parenthesis/other delimiters in languages like C/C++. Why the heck do I need to put parenthesis around the frikkin check in branching constructs, even when I'm only referencing a single variable? Why do I need to remember which bracket to use for what purpose?
Once again, it's a matter of training/what you're used to.

Also, the parenthesis allow automatic code formatting, which again helps in spotting structural errors. Sometimes when I change some code and remove closing parenthesis in the process, I check whether I have the correct number of them by re-indenting the following line until it ends up where it was before. It's almost fool-proof.

Quote
(It is kinda funny that my professor for the class is one of those hardcore LISP guys who never really gave up on the idea that LISP is "the future of programming". :P I mean don't get me wrong, LISP-related languages have their uses in places like pioneering new research algorithms and other specific types of work that benefit from it's advantages [though even in some of those fields they're starting to be beat out by things like Python for similar benefits or C++ for speed requirements], but they aren't exactly the language the vast majority of people reach for when they think "I want to code X to do Y", even when said people have been exposed to the benefits of LISP-y languages. Is it a nice tool that you should definitely learn? Yeah, even if only for the practice in a very different way of thinking. But as for "the future of programming", it's almost certainly never going to be the generic language that people grab first when they just need to code a generic something up.)
The thing is, languages with proper macros are the most general – I haven't found a single way of programming that wouldn't be available in Common Lisp via macros and reader macros. There's even a library (a library!) out there taking most of the parenthesis out of Common Lisp. I'm not using it, since I like my parenthesis and the resulting automatic indentation.

I like Lisp on a theoretical level, but for actual development I'd rather throw bits of boilerplate together than muck around with billions of operators and brackets.
If your program becomes this complex, you use macros to cut down on the complexity. It helps with readability, bug avoidance and boilerplate. It also reduces the use of parentheses dramatically.

As much as I hate to admit it, the boilerplate that most languages impose upon coders is generally meant to allow us to catch our mistakes before we run it. We can't do static analysis in lisp, we have to crawl through the branches of the code seeking the error. In C++, you can do magic with templates and make the compiler sweat until it tests those things for you. With C#, the code contracts can do the same, but without invoking the dark voodoo that are Turing complete templates.
Yeah, static checking isn't really a thing, but testing libraries are.
Also having a REPL in which I can just run parts of my code without needing to compile and run the whole program is damn awesome. I can narrow down algorithmic bugs way easier with a REPL than with static checking.
Actually static checking could probably done in part via macros.

I don't think it's the right language for every level of development.  But I think it would be pretty well-suited for a lot of the stuff I do, which is largely data curation, routing, and filtering.
Sure, if it's good for what you commonly do than more power to you. Languages are tools and all that jazz, and you shouldn't be trying to nail screws in with a hammer. But for "expressivity" (Note:, there are a lot of definitions about what exactly it means for a language to "expressive", so pardon me if I'm using a different one here), I think I'm gonna have to say that in the vast majority of cases the human mind when thinking of a step by step process thinks in a way that is much more similar to a language like C++ with it's step and state focused paradigm than that of recursive functional languages. The proof of this can be observed simply by opening up a nearby cookbook, or by googling "instructions to do X" on google where X is anything that you want. I can almost assure you that the instructions you find there will be much more likely to be based around sequential steps with iteration than recursive calls.
Doug Hoyte argued like this in his book "Let Over Lambda": Programming is not so much a process of adding functionality to a codebase but rather a process of changing functionality of a program. The easier it is to change code, the better. He then goes on to introduce a few macros which allows turning a lambda expression into a kind of contextual object by just adding one character and one line. He then implements a Forth dialect in Common Lisp, perfectly embeddable.
The point is: Yes, different languages for different tasks, but Lisp just is able to emulate every other language, conceptually and in Common Lisp even in syntax.

Quote
For brackets I think my big problem is simply that because everything uses a relatively same syntax it makes things a lot harder to parse visually, and as such will never be quite as easy as if the syntax was different for different things. It's like if every single building in a town, houses, school, hospital, fire department, police station, was built out of the exact same color yellow brick with fairly similar layouts. Sure I could get a GPS and that would help me find what I wanted, but it would still never be as easy as if every house was built of blue brick, every school of green, every hospital of white, and so forth (though as noted that would lose me the ability to build, say, a red house as the expense of being able to more easily find a hospital when I needed one).
My experience is the exact opposite. I don't mean to say that Lisp necessarily is easier to read but rather that Lisp is not harder to read by design, but because you're used to something else.

Quote
Java to me has always seemed like a language that took the extreme utility that composes C/C++ and added just enough Python to it to lose all of the benefits that C/C++ provide, but not enough Python to actually gain the benefits of the easier syntax/etc. that Python provides. :P (The "run on anything" is kinda a nice feature, though).
"Run on anything" is not a feature of the language, it's only the fact that implementations exist for all major platforms. It assume Java doesn't run on TempleOS – just like most other languages.

Most languages don't require you to care how the hardware works, though. Your standard C++ compiler or PyPy or whatever will do most of the optimisations for you anyway, and that's assuming your program needs optimal performance in the first place.
So I don't think "Lisp doesn't require intimate knowledge of machine processes" makes much sense as an argument. Programming in Lisp is a different way of thinking, but it's not that different.
I think you are underestimating the difference between languages which can add syntax on the fly and languages which cannot.
I, personally, implemented objects with lazy evaluation of their slots and on top of that a library for Algebraic Data Types and pattern matching on those types. I can use these together with iterative syntax, object orientation, data flow programming, functional programming, imperative programming and whatnot, all in one language and if there's a feature I don't already have, there's probably a library out there or I can implement one myself, and it will probably only take a few hours to get a first usable version.

There's two valid criticisms of Lisp I can get behind, though:
1. The lack of maintained libraries.
2. Maybe another language compiles to faster code elsewhere.
The first is a problem of the community, not the language (but still a very real problem) and the second is a non-problem in most cases. At least Common Lisp can do quite a bit of non-obvious optimization, though, and as opposed to C and other languages like it these optimizations can be hidden away and made more readable via macros.


College is probably not doing a favor to Lisp languages, because they pretend as if Lisp was only functional programming because they want to use it to teach functional programming. It is not. It supports functional programming. But you can do everything else in it, too, and for Common Lisp many of these things are even in the standard.
They should be using Haskell instead and use Lisp to teach macros.
Logged
Taste my Paci-Fist

doomchild

  • Bay Watcher
  • Official Pace Car for the Apocalypse
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9020 on: February 15, 2016, 06:18:09 am »

Haskell just makes me angry.  As a developer who is significantly weaker in math than others, it feels like its syntax was built from day one to be completely incomprehensible to someone without a PhD in tensor mechanics, or some other specific branch of mathematics whose teaching requires extra janitorial staff just to clean up the brains splattered on the walls after class.  On top of which, a lot of the documentation seemed to require a deep knowledge of what I would consider to be fairly esoteric concepts (anytime a document contains the word "ergofunctor", I immediately begin looking for the hidden camera).  I take full responsibility for the fact that this all might be insecurity on my part.

On the topic of parenthesis management (emacs does a good job for me), have you looked at Parinfer?  It seems like an interesting way to automate the task of keeping things in sync properly.
Logged
Quote from: webadict
I could care less what you are now, because what you will be is dead.

Antsan

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9021 on: February 15, 2016, 06:25:15 am »

Parinfer is new to me. I'll have a look at it later today.

I actually quite like Haskell. I'm relatively good at math, though.
Most math problems are problems of insecurity. There was a study where students were confronted with math problems. For one group it was obvious that they were math problems, for the other the math parts were obscured in some way. The second group did significantly better.

Yeah, Haskell has lots of technical language. I don't get along with it either. Still think it's a beautiful language worth learning.
Logged
Taste my Paci-Fist

doomchild

  • Bay Watcher
  • Official Pace Car for the Apocalypse
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9022 on: February 15, 2016, 06:32:02 am »

If I decide to teach myself a functional language, it'll probably be either F# or some variant of ML (OCaml being the most likely).  I've dabbled briefly with F# before, and since I already know the .NET platform pretty well, it's not too hard to get used to.  OCaml looks interesting largely because it's so different, but I could very well get frustrated with it, too.  I'm rather mercurial that way.
Logged
Quote from: webadict
I could care less what you are now, because what you will be is dead.

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9023 on: February 15, 2016, 02:32:25 pm »

I refuse to look inside that thing.  I would love a better-performing, less awful version of SS13, but apparently it's just not in the cards.
it's over 350k lines of code, really hard to port. you should look into SS14, tho, i think that's active again.

also the fun part about working with a shitty language like byond is the people (not me lmao i suck) finding the dumbass quirks that make loops run 50% faster for no real reason. like that time we found out that calling del() to gc a datum loops through world and manually deletes all references to that datum, which is slow af. except all datums keep a refcount which is decreased every time a reference is removed and increased whenever a reference is added (duh). if the refcount is 0, the datum is "efficiently" garbage-collected. so we wrote our own garbage collector and suddenly all servers ran much faster.

(also that one time that we found a memory leak that persisted through server restarts)
Logged

Quote from: NW_Kohaku
they wouldn't be able to tell the difference between the raving confessions of a mass murdering cannibal from a recipe to bake a pie.
Knowing Belgium, everyone will vote for themselves out of mistrust for anyone else, and some kind of weird direct democracy coalition will need to be formed from 11 million or so individuals.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9024 on: February 15, 2016, 04:18:56 pm »

Most languages don't require you to care how the hardware works, though. Your standard C++ compiler or PyPy or whatever will do most of the optimisations for you anyway, and that's assuming your program needs optimal performance in the first place.
So I don't think "Lisp doesn't require intimate knowledge of machine processes" makes much sense as an argument. Programming in Lisp is a different way of thinking, but it's not that different.

Go watch Mike Acton's optimization videos. The compiler does jack shit that people think it does ... it can only do very superficial "optimization" and even a small amount of obfuscation of identical source code causes an epileptic fit in even "advanced" optimizing compilers. The magic sauce of machine-powered optimization is highly overrated, and there's probably somebodies agenda in that belief, because even simple test cases prove that it isn't true. Probably coming from both ends of the people selling compilers to companies, and companies not wanting to pay for coder time to do it right: this myth that you can write whatever you want and the compiler will magically make it the most efficient code ever just perfect for all target platforms is just not true.
« Last Edit: February 15, 2016, 04:23:03 pm by Reelya »
Logged

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9025 on: February 15, 2016, 04:29:56 pm »

That's trimming at the edges. The compiler won't actually change your algorithm at a higher level that that, and the sheer bulk of possible speed savings are not found by merely replacing postincrement with preincrement operators. For example, the compiler won't always unroll loops, and it won't make any logical assessment "this loop isn't really needed is it?"

Some of mike's examples e.g. are doing some calculation in a statically-size loop (e.g. 10 times). If the calculation is simple enough, then some compilers (clang mainly, but not VC++ or GCC usually) can optimize the whole loop out of existence and just put the calculated value in. But if you put part of the calculation inside a function, then even clang starts going spastic and making worse code that a human would.
« Last Edit: February 15, 2016, 04:34:33 pm by Reelya »
Logged

Antsan

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9026 on: February 15, 2016, 04:33:45 pm »

snip
Yes, you're kind of right, but practically speaking a lot of "optimizations" you learn are specific to a certain architecture that may be out of data and may even mak code run more slowly on modern hardware. I don't remember which language this was about and where I read it, but there was a demonstration of some "optimized" code running much slower than the unoptimized version, because the compiler could actually optimize the unoptimized one better.

The kind of language-dependent optimization you are talking about isn't portable.

That's trimming at the edges. The compiler won't actually change your algorithm at a higher level that that, and the sheer bulk of possible speed savings are not found by merely replacing postincrement with preincrement operators. For example, the compiler won't always unroll loops, and it won't make any logical assessment "this loop isn't really needed is it?"
Doesn't LLVM do this kind of stuff?
Logged
Taste my Paci-Fist

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9027 on: February 15, 2016, 04:36:04 pm »

Yeah, I edited in a reference to clang, which uses LLVM. But Mike shows in the videos that while clang/LLVM are better than the common compilers, there are still trivial-to-a-human examples that cause it to majorly brain fart. Basically if your code is pure old-school procedural code and it's all there in one function LLVM does really good. But as soon as you start nesting functions it suddenly can't conceptualize what is going on. LLVM seems to be able to handle roughly 1 level deeper nesting or so than GCC or VC++ however, but anything more complex than that and they all start spitting out pretty weird and inelegant machine code.

Some examples:

for(loop)
   if (bool_var) do thing.

we can see that moving the if check outside the for loop with speed things up. But the compiler can't make the assumption that the bool won't magically change somehow. clang does better in this situation than VS/GCC. But if you put the bool inside a function, none of the optimizers can cope with that fact and optimize the check away.

function check()
   return bool_var

for(loop)
   if(check()) do thing.

^ this version is exactly the same computationally, but can't be compiler-optimized any more. There are many of these types of examples where a human can see at a glance that two pieces of code should have the same output, but the optimizing compilers cannot. Sure, this could be improved, but the kinds of examples show that we're at a "not there yet" stage.
« Last Edit: February 15, 2016, 04:53:28 pm by Reelya »
Logged

Antsan

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9028 on: February 15, 2016, 05:01:03 pm »

Ah, okay, that makes sense.
Logged
Taste my Paci-Fist

i2amroy

  • Bay Watcher
  • Cats, ruling the world one dwarf at a time
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9029 on: February 15, 2016, 06:06:39 pm »

Just some quick little responses to Antsan's wall there.
Parenthesis highlighting - I'll definitely look into that.
College bad language choice - I'll agree with you on that point. We don't even get to see a fraction of what LISP/related languages can do. (Though as you noted earlier, what it "can do" and what it "can do without me having to write it from scratch myself" are two very different things due to library maintenance :P).
Logged
Quote from: PTTG
It would be brutally difficult and probably won't work. In other words, it's absolutely dwarven!
Cataclysm: Dark Days Ahead - A fun zombie survival rougelike that I'm dev-ing for.
Pages: 1 ... 600 601 [602] 603 604 ... 796