Coding: Fleeting Thoughts

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

User avatar
Flumble
Yes Man
Posts: 1944
Joined: Sun Aug 05, 2012 9:35 pm UTC

Re: Coding: Fleeting Thoughts

Postby Flumble » Fri Oct 14, 2016 2:30 pm UTC

Say you have random sample points in a cartesian system (specific case: 2D) with random values and you want to interpolate between them to get a meaningful value anywhere. What's a good system to use?
I've tried inverse distance weighting (with p=2 to get a smooth curve), but as you can see in the graph it has the downside that points "behind" other points have a non-zero weight. Now the modified method uses an additional linear fall-off for the weights with a certain radius, but that only hides the problem for more evenly distributed points.

How hard is natural neighbour interpolation to implement? It seems I need delaunay triangulation and an understanding of convex combinations for that.
What if the sample points aren't points but concave hulls?

User avatar
Xenomortis
Not actually a special flower.
Posts: 1396
Joined: Thu Oct 11, 2012 8:47 am UTC

Re: Coding: Fleeting Thoughts

Postby Xenomortis » Fri Oct 14, 2016 3:11 pm UTC

Without thinking much about the problem:
Pick a value based on the k-nearest neighbours, weighted by distance, culling those that are "shadowed" by other points (you'll need to decide on the angle to cull at).
I imagine k should be quite small, the culling step is unlikely to be necessary then (assuming "uniform" noise).
Lookup for the nearest neighbours is fast, given a suitable structure (kd-tree, or a generalised BSP-tree).

What's the purpose?
Image

korona
Posts: 495
Joined: Sun Jul 04, 2010 8:40 pm UTC

Re: Coding: Fleeting Thoughts

Postby korona » Fri Oct 14, 2016 4:20 pm UTC

FT: In pre-C++17, is it possible to use standard library allocators on types that have const-members without invoking undefined behavior?

Code: Select all

struct Foo {
    Foo() : bar(0) { }
   
    const int bar;
};

Foo *make_foo() {
    using A = std::allocator<Foo>;
    A allocator;
    auto p = std::allocator_traits<A>::allocate(allocator, 1);
    std::allocator_traits<A>::construct(allocator, p);
    return p; // ouch, I think this is UB (as soon as p is actually accessed)! p does not meet the requirements for lifecycle reuse here!
}

commodorejohn
Posts: 957
Joined: Thu Dec 10, 2009 6:21 pm UTC
Location: Placerville, CA
Contact:

Re: Coding: Fleeting Thoughts

Postby commodorejohn » Sat Oct 15, 2016 12:29 am UTC

You know what you should never, ever see in the official online documentation for an official part of the standard library for a major programming language?
"For all the actual information you came here for, read the man pages and some guy's book."
This should be a firing-squad offense.
"'Legacy code' often differs from its suggested alternative by actually working and scaling."
- Bjarne Stroustrup
www.commodorejohn.com - in case you were wondering, which you probably weren't.

speising
Posts: 2066
Joined: Mon Sep 03, 2012 4:54 pm UTC
Location: wien

Re: Coding: Fleeting Thoughts

Postby speising » Sat Oct 15, 2016 1:15 am UTC

commodorejohn wrote:You know what you should never, ever see in the official online documentation for an official part of the standard library for a major programming language?
"For all the actual information you came here for, read the man pages and some guy's book."
This should be a firing-squad offense.

You know, space on web pages is a limited resource. You can't just put any obscure option there or you run out of characters for the more important things.

User avatar
Yakk
Poster with most posts but no title.
Posts: 11045
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: Coding: Fleeting Thoughts

Postby Yakk » Sat Oct 15, 2016 1:21 am UTC

I can't believe you wasted characters telling them that. We may never be able to describe the cure for cancer on a facebook post because of that.
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

User avatar
ucim
Posts: 5564
Joined: Fri Sep 28, 2012 3:23 pm UTC
Location: The One True Thread

Re: Coding: Fleeting Thoughts

Postby ucim » Sat Oct 15, 2016 4:17 am UTC

speising wrote:You know, space on web pages is a limited resource. You can't just put any obscure option there or you run out of characters for the more important things.
Yanno, there's something to that, but it's not what it seems.

How often have you googled something, found a sea of results, and found most of them to be copypasta, and some of those are slightly modified copypasta. All of them undated and unsourced, so you can't find the original. Now, if one of those results tells you what you want, great. Unless one of the other ones is slightly modified and tells you something subtly different.

And if the copypasta does not answer your query, trying to find the links that are not copies of that particular copypasta is not so easy, especially if the answer you want is on a page that has the copypasta plus the further info you're looking for. It's a form of data pollution.

That said, the original question raises the secondary question: Should the official documentation of a {this} include all information about the {this}? I don't think that's possible. Consider:

{this} works this way.
{this} can be used for these things
{this} can be used for those things too, but you need to {that}.
{this} has a really obscure but quite clever application {here}
{this} can be used with {that} but only on {condition}
etc... Clearly some of this belongs in the official docs. But some of this perhaps doesn't, even if it's explained really well {here}.

How to decide how far to go? I leave that to... well... internet discussion I guess. :)

Jose
Order of the Sillies, Honoris Causam - bestowed by charlie_grumbles on NP 859 * OTTscar winner: Wordsmith - bestowed by yappobiscuts and the OTT on NP 1832 * Ecclesiastical Calendar of the Order of the Holy Contradiction * Please help addams if you can. She needs all of us.

commodorejohn
Posts: 957
Joined: Thu Dec 10, 2009 6:21 pm UTC
Location: Placerville, CA
Contact:

Re: Coding: Fleeting Thoughts

Postby commodorejohn » Sat Oct 15, 2016 4:37 am UTC

Yeah, I get that, but when the official documentation on the official site is passing the buck...!
"'Legacy code' often differs from its suggested alternative by actually working and scaling."
- Bjarne Stroustrup
www.commodorejohn.com - in case you were wondering, which you probably weren't.

User avatar
ucim
Posts: 5564
Joined: Fri Sep 28, 2012 3:23 pm UTC
Location: The One True Thread

Re: Coding: Fleeting Thoughts

Postby ucim » Sat Oct 15, 2016 4:47 am UTC

Yeah, I get that too. There's everything, and there's everything. At some point you have to stop.

The point isn't that it's official documentation. The point is... where do you stop, and why? I don't know the answer, (and I don't know hardly any python) so I can't tell whether this particular case is horrifying or reasonable.

Jose
Order of the Sillies, Honoris Causam - bestowed by charlie_grumbles on NP 859 * OTTscar winner: Wordsmith - bestowed by yappobiscuts and the OTT on NP 1832 * Ecclesiastical Calendar of the Order of the Holy Contradiction * Please help addams if you can. She needs all of us.

korona
Posts: 495
Joined: Sun Jul 04, 2010 8:40 pm UTC

Re: Coding: Fleeting Thoughts

Postby korona » Sat Oct 15, 2016 12:13 pm UTC

ucim wrote:Yeah, I get that too. There's everything, and there's everything. At some point you have to stop.

The point isn't that it's official documentation. The point is... where do you stop, and why? I don't know the answer, (and I don't know hardly any python) so I can't tell whether this particular case is horrifying or reasonable.

Jose

That official documentation is not a tutorial or guide. It is okay if they don't mention all use cases however in this case they don't even provide a reference of all options. Which clearly defeats the entire purpose of the document.

User avatar
Flumble
Yes Man
Posts: 1944
Joined: Sun Aug 05, 2012 9:35 pm UTC

Re: Coding: Fleeting Thoughts

Postby Flumble » Sat Oct 15, 2016 12:59 pm UTC

commodorejohn wrote:You know what you should never, ever see in the official online documentation for an official part of the standard library for a major programming language?
"For all the actual information you came here for, read the man pages and some guy's book."
This should be a firing-squad offense.

IMO the only thing the only thing they've done really wrong, is not include a link to the Tk documentation. (it's glorified man pages, but at least it's a clickable URL and doesn't require you to understand and use manbearpig)

[edit]
Xenomortis wrote:What's the purpose?

In this case it's for interpolating view sizes/locations (oh shit, I totally forgot about locking the y-coordinate in my answer) in a platformer, see here in dutch. As long as there are only preferred views in one direction, a simple bicubic interpolation (or even linear) does the trick, but if the platformer becomes more than a one-dimensional walking simulator, you may need some clever weighting algorithm.
And I'm simply interested in the general case.

commodorejohn
Posts: 957
Joined: Thu Dec 10, 2009 6:21 pm UTC
Location: Placerville, CA
Contact:

Re: Coding: Fleeting Thoughts

Postby commodorejohn » Sat Oct 15, 2016 6:10 pm UTC

Flumble wrote:IMO the only thing the only thing they've done really wrong, is not include a link to the Tk documentation. (it's glorified man pages, but at least it's a clickable URL and doesn't require you to understand and use manbearpig)

Or have man in the first place, if you're running it on Windows...

And a link to the Tk documentation would probably help, but only so much, considering that Tkinter is its own distinct thing (a Python interface to a C library.)
"'Legacy code' often differs from its suggested alternative by actually working and scaling."
- Bjarne Stroustrup
www.commodorejohn.com - in case you were wondering, which you probably weren't.

User avatar
Xenomortis
Not actually a special flower.
Posts: 1396
Joined: Thu Oct 11, 2012 8:47 am UTC

Re: Coding: Fleeting Thoughts

Postby Xenomortis » Mon Oct 17, 2016 2:29 pm UTC

Making arrays in python.

Code: Select all

size = int(4e6)
s = time()
l = list( (x - 0.5) * 0.5 for x in xrange(size) )
print time() - s

0.6 seconds (and a lot of memory)

Code: Select all

l = numpy.fromiter( ((x - 0.5) * 0.5 for x in xrange(size)), dtype=np.float64, count=size)

0.72 seconds
Didn't expect that... at least it's less memory.

Code: Select all

l = numpy.fromfunction( lambda x: (x-0.5) * 0.5, (size,) )

0.04 seconds
What kind of magic is this!?
Last edited by Xenomortis on Mon Oct 17, 2016 2:40 pm UTC, edited 1 time in total.
Image

User avatar
Yakk
Poster with most posts but no title.
Posts: 11045
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: Coding: Fleeting Thoughts

Postby Yakk » Mon Oct 17, 2016 2:37 pm UTC

Well, it knows the size. It knowns the incoming type. It can compile the lambda, and prove that it produces a uniform type; what more, it could prove that you could compile it down to non-python, no?

Ie, I can imagine a lambda having the "Is there an assembly version that takes an integer or double and returns an integer or double?" version of itself, or being able to generate it via pythonic sorcery.

numpy could look at the lambda, determine there is a raw-assembly version, know how big the buffer is, generate the buffer in one fell blow and populate it using non-interpreted code?

Seems plausible.
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

Tub
Posts: 310
Joined: Wed Jul 27, 2011 3:13 pm UTC

Re: Coding: Fleeting Thoughts

Postby Tub » Mon Oct 17, 2016 2:52 pm UTC

Code: Select all

#include <stdio.h>
#include <time.h>

int main() {
   clock_t t1 = clock();
   const size_t size = 4e6;
   double *arr = new double[size];
   for (size_t i=0;i<size;i++) {
      arr[i] = (i - 0.5) * 0.5;
   }
   clock_t t2 = clock();
   double elapsed = (t2-t1) / (double) CLOCKS_PER_SEC;
   // we want to output at least one element of the array so that the compiler doesn't optimize the loop away
   double random_result = arr[time(NULL) % size];
   printf("took %f seconds, here's a random element: %f\n", elapsed, random_result);
   delete [] arr;
}

For comparison, this takes ~0.047 seconds on my slow notebook (gcc -O2). Your CPU is probably faster than mine. Still, it appears as if the third version is close to optimal.

User avatar
Xenomortis
Not actually a special flower.
Posts: 1396
Joined: Thu Oct 11, 2012 8:47 am UTC

Re: Coding: Fleeting Thoughts

Postby Xenomortis » Mon Oct 17, 2016 3:10 pm UTC

Stackoverflow suggests that numpy.fromfunction has very deceptive docstrings and in fact, does not execute the function per coordinate point.
What actually happens is the function is called once with arrays of the coordinates and operates directly on those.
It so happens that numpy's array syntax works well when combining scalars and arrays (so the lambda still does in the "intuitive" thing, but is actually returning a full array when called).
It will consume more memory during its execution, but it's only a few dozen MBs.

Tub wrote:For comparison, this takes ~0.047 seconds on my slow notebook (gcc -O2). Your CPU is probably faster than mine. Still, it appears as if the third version is close to optimal.

0.01 seconds on my work desktop, so we're not far off the "naive C baseline".

Edit:
Of course, armed with this knowledge we come to the "obvious":

Code: Select all

l = (numpy.arange(size) - 0.5) * 0.5

0.02 seconds

It remains to be seen how well this scales to "harder" initialisation functions.
Image

User avatar
The Great Hippo
Swans ARE SHARP
Posts: 6834
Joined: Fri Dec 14, 2007 4:43 am UTC
Location: behind you

Re: Coding: Fleeting Thoughts

Postby The Great Hippo » Tue Oct 25, 2016 5:43 pm UTC

I was talking to somebody about programming earlier yesterday, and they asked me if I'd ever actually coded anything. I was about to say 'no, not at all', but then I realized that a few months ago I actually happened on a weird, somewhat pervasive glitch in networkx, and even wrote a pull request to fix it (which was accepted and is now part of the build).

(if anyone's curious, here's the bug)
Spoiler:

Code: Select all

>>> import networkx
>>> g = networkx.Graph()
>>> my_dict = {"x": 0, "y": 0}
>>> g.add_node("node", my_dict, y=1)
>>> print(my_dict)
{'y': 1, 'x': 0}
>>> my_dict["x"] = 1
>>> print(g.node["node"])
{'y': 1, 'x': 1}
>>> my_other_dict = {"x": 5}
>>> g.add_node("node", my_other_dict)
>>> print(my_dict)
{'y': 1, 'x': 5}
>>> g.add_node("other node", my_dict)
>>> my_dict["x"] = 10
>>> print(g.node["node"])
{'y': 1, 'x': 10}
>>> print(g.node["other node"])
{'y': 1, 'x': 10}
Basically, when adding nodes, you could assign attributes to them by one of two ways: Pass a dictionary to the call or assign those attributes as keywords. The expected behavior was that each node would have its own internal attribute dictionary -- but the actual behavior was that nodes would share attribute dictionaries, causing all sorts of unexpected mutations.
It feels really weird to suddenly realize that yes, I've actually written code that's going to be used by someone other than me.

Tub
Posts: 310
Joined: Wed Jul 27, 2011 3:13 pm UTC

Re: Coding: Fleeting Thoughts

Postby Tub » Tue Oct 25, 2016 7:09 pm UTC

Wait until you realize that you're now also responsible for someone else's computer problems.

User avatar
The Great Hippo
Swans ARE SHARP
Posts: 6834
Joined: Fri Dec 14, 2007 4:43 am UTC
Location: behind you

Re: Coding: Fleeting Thoughts

Postby The Great Hippo » Tue Oct 25, 2016 7:55 pm UTC

Yeah, I'm waiting for my feelings to go from "oh wow someone is using my code" to "oh GOD someone is using my code"

EvanED
Posts: 4324
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: Coding: Fleeting Thoughts

Postby EvanED » Wed Oct 26, 2016 5:02 am UTC

Brains have some weird failure modes. Makes me wonder if perhaps complex software can never possibly be bug free.

I just did this:

Code: Select all

$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> (define x '(1 2 3))
  File "<stdin>", line 1
    (define x '(1 2 3))
            ^
SyntaxError: invalid syntax
>>>

and then stared at it for about 30 seconds trying to figure out what I did wrong.

commodorejohn
Posts: 957
Joined: Thu Dec 10, 2009 6:21 pm UTC
Location: Placerville, CA
Contact:

Re: Coding: Fleeting Thoughts

Postby commodorejohn » Wed Oct 26, 2016 6:28 am UTC

Hah, that's all kinds of great.
"'Legacy code' often differs from its suggested alternative by actually working and scaling."
- Bjarne Stroustrup
www.commodorejohn.com - in case you were wondering, which you probably weren't.

ThemePark
Posts: 450
Joined: Fri Jun 27, 2008 5:42 pm UTC
Location: Århus, Denmark

Re: Coding: Fleeting Thoughts

Postby ThemePark » Wed Oct 26, 2016 6:39 am UTC

30 seconds is nothing. Let me know when you've tried spending hours on obvious-in-hindsight mistakes like that.
I have traveled from 1979 to be a member of the unofficial board Council of Elders. Phear M3

Tub
Posts: 310
Joined: Wed Jul 27, 2011 3:13 pm UTC

Re: Coding: Fleeting Thoughts

Postby Tub » Wed Oct 26, 2016 9:29 am UTC

EvanED wrote:Makes me wonder if perhaps complex software can never possibly be bug free.

You don't need to wonder. Just as we cannot prove if a program halts, we cannot prove if it produces the right answers, or if it produces the right answers by any sensible means. We do have several verification systems (unit tests, manually writing down preconditions, postconditions and invariants, proofs by transforming with the denotational semantics, ...), but all of these are written by hand, and we cannot prove if the verification is correct, either.

If a program happens to be bug free, we'll never know. And the probability for that to happen diminishes with rising complexity.

User avatar
Yakk
Poster with most posts but no title.
Posts: 11045
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: Coding: Fleeting Thoughts

Postby Yakk » Wed Oct 26, 2016 11:10 am UTC

There is a law. Any complex system will not only be operating in a failure/error state, but will rely upon it to work.

So tgere will be some logic where the programmer was like "this should never happen". It will be happening. Other parts are now relying on it happening in order to work properly.

Complex prigrams work *by accident*. The worst bugs or errors are fixed because they get noticed. Humans cannot design systems as complex as modern software using current techniques and get it right.

There are many ways to mitigate that; TDD, unit tests, formal proofs, coverage anaylsis, manual testing, fuzz testing, netflix's chaos monkey.
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

User avatar
The Great Hippo
Swans ARE SHARP
Posts: 6834
Joined: Fri Dec 14, 2007 4:43 am UTC
Location: behind you

Re: Coding: Fleeting Thoughts

Postby The Great Hippo » Wed Oct 26, 2016 2:11 pm UTC

Features are just bugs we haven't found yet?

ThemePark
Posts: 450
Joined: Fri Jun 27, 2008 5:42 pm UTC
Location: Århus, Denmark

Re: Coding: Fleeting Thoughts

Postby ThemePark » Wed Oct 26, 2016 2:25 pm UTC

It's the other way around. Bugs are just undiscovered/undocumented features.
I have traveled from 1979 to be a member of the unofficial board Council of Elders. Phear M3

EvanED
Posts: 4324
Joined: Mon Aug 07, 2006 6:28 am UTC
Location: Madison, WI
Contact:

Re: Coding: Fleeting Thoughts

Postby EvanED » Wed Oct 26, 2016 3:02 pm UTC

ThemePark wrote:30 seconds is nothing. Let me know when you've tried spending hours on obvious-in-hindsight mistakes like that.

Oh, I definitely have, but it's usually like some = in an if somewhere, where yeah it's a dumb mistake but the location of the mistake isn't easy to find. (That hasn't happened to me in a long time, but it's kind of the classic example, and maybe my first long-but-stupid debugging session.)

This one was notable because there was nowhere to look outside of those few lines. And still not the first time it's happened. :-)

User avatar
ahammel
My Little Cabbage
Posts: 2135
Joined: Mon Jan 30, 2012 12:46 am UTC
Location: Vancouver BC
Contact:

Re: Coding: Fleeting Thoughts

Postby ahammel » Wed Oct 26, 2016 3:21 pm UTC

EvanED wrote:
ThemePark wrote:30 seconds is nothing. Let me know when you've tried spending hours on obvious-in-hindsight mistakes like that.

Oh, I definitely have, but it's usually like some = in an if somewhere, where yeah it's a dumb mistake but the location of the mistake isn't easy to find. (That hasn't happened to me in a long time, but it's kind of the classic example, and maybe my first long-but-stupid debugging session.)

This one was notable because there was nowhere to look outside of those few lines. And still not the first time it's happened. :-)

Your brain just wants you to be writing Lisp.
He/Him/His/Alex
God damn these electric sex pants!

User avatar
Yakk
Poster with most posts but no title.
Posts: 11045
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: Coding: Fleeting Thoughts

Postby Yakk » Wed Oct 26, 2016 3:30 pm UTC

Complex systems have bugs. Complex systems coupled to systems with bugs rely on those bugs to operate.
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

User avatar
Xenomortis
Not actually a special flower.
Posts: 1396
Joined: Thu Oct 11, 2012 8:47 am UTC

Re: Coding: Fleeting Thoughts

Postby Xenomortis » Wed Oct 26, 2016 4:31 pm UTC

EvanED wrote:
ThemePark wrote:30 seconds is nothing. Let me know when you've tried spending hours on obvious-in-hindsight mistakes like that.

Oh, I definitely have, but it's usually like some = in an if somewhere, where yeah it's a dumb mistake but the location of the mistake isn't easy to find. (That hasn't happened to me in a long time, but it's kind of the classic example, and maybe my first long-but-stupid debugging session.)

My favourite is when my test scripts keep failing in impossible ways after I've just fixed some python code. I keep running the scripts and getting nonsense error traces, no matter what code I type.
Turns out I frequently switch vim splits to run the test script *before* hitting ":w".
Image

User avatar
Yakk
Poster with most posts but no title.
Posts: 11045
Joined: Sat Jan 27, 2007 7:27 pm UTC
Location: E pur si muove

Re: Coding: Fleeting Thoughts

Postby Yakk » Wed Oct 26, 2016 6:08 pm UTC

Ah yes, the "is it plugged in" test. Are you editing the code you are compiling? Are you compiling the code you are running? Are you loading the DLL you built? Are you running the subprocedure you thought you where running? Is the header file being excluded due to header guards, or an identically named header file somewhere else?

Those are actual "why doesn't this work" case I have personally experienced. Most of them I've fixed other people's "bugs" by wakling through the checks.
One of the painful things about our time is that those who feel certainty are stupid, and those with any imagination and understanding are filled with doubt and indecision - BR

Last edited by JHVH on Fri Oct 23, 4004 BCE 6:17 pm, edited 6 times in total.

User avatar
Xeio
Friends, Faidites, Countrymen
Posts: 5086
Joined: Wed Jul 25, 2007 11:12 am UTC
Location: C:\Users\Xeio\
Contact:

Re: Coding: Fleeting Thoughts

Postby Xeio » Wed Oct 26, 2016 6:35 pm UTC

I just spent like a day and a half working around an issue where sometimes the data didn't pass through a service boundary correctly.

Turns out I forgot to add [DataMember] attributes to all my [DataContract] class fields.

The only weird thing is... it only failed the first time after an app restart. The 2nd/3rd/ect tries all were fine.

Yakk wrote:
Ah yes, the "is it plugged in" test. Are you editing the code you are compiling? Are you compiling the code you are running? Are you loading the DLL you built? Are you running the subprocedure you thought you where running? Is the header file being excluded due to header guards, or an identically named header file somewhere else?

Those are actual "why doesn't this work" case I have personally experienced. Most of them I've fixed other people's "bugs" by wakling through the checks.
I can only thank the gods that Visual Studio detects the "debugging the wrong version" types of things automatically.

User avatar
Xanthir
My HERO!!!
Posts: 5213
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex
Contact:

Re: Coding: Fleeting Thoughts

Postby Xanthir » Thu Oct 27, 2016 12:00 am UTC

This is also why, the *moment* I start getting confused, I print something to verify that execution is actually running thru the code I'm writing. This instinct has saved me hours of debugging time. I often do it even before I start getting confused, just to make sure I'm looking at the right code in the first place.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))

commodorejohn
Posts: 957
Joined: Thu Dec 10, 2009 6:21 pm UTC
Location: Placerville, CA
Contact:

Re: Coding: Fleeting Thoughts

Postby commodorejohn » Thu Oct 27, 2016 12:51 am UTC

Xanthir wrote:This is also why, the *moment* I start getting confused, I print something to verify that execution is actually running thru the code I'm writing. This instinct has saved me hours of debugging time. I often do it even before I start getting confused, just to make sure I'm looking at the right code in the first place.

Yup. printf() is seriously underrated as a debugging tool.
"'Legacy code' often differs from its suggested alternative by actually working and scaling."
- Bjarne Stroustrup
www.commodorejohn.com - in case you were wondering, which you probably weren't.

User avatar
The Great Hippo
Swans ARE SHARP
Posts: 6834
Joined: Fri Dec 14, 2007 4:43 am UTC
Location: behind you

Re: Coding: Fleeting Thoughts

Postby The Great Hippo » Thu Oct 27, 2016 6:03 pm UTC

I've been debating trying to write a data-driven rogue-like again, if only cuz I've played a couple of cool rogue-lives recently. I should probably focus more on learning the basics of coding, though. I still struggle with really simple terminology, like "framework" or "service".

(To be fair, though, I'm getting the sense that programmers in general struggle over these things)

ThemePark
Posts: 450
Joined: Fri Jun 27, 2008 5:42 pm UTC
Location: Århus, Denmark

Re: Coding: Fleeting Thoughts

Postby ThemePark » Thu Oct 27, 2016 8:22 pm UTC

Those are really just buzzwords. There is no right way to use those terms, so no worries.
I have traveled from 1979 to be a member of the unofficial board Council of Elders. Phear M3

User avatar
Flumble
Yes Man
Posts: 1944
Joined: Sun Aug 05, 2012 9:35 pm UTC

Re: Coding: Fleeting Thoughts

Postby Flumble » Thu Oct 27, 2016 8:49 pm UTC

You should use a javascript-based Roguelike-as-a-Service framework.

Some unsollicited advice:
Depending on how 'playful' you want to learn those basics of coding while making/preparing for your roguelike, I'd suggest using anywhere from RPGMaker©™ to GameMaker® to PyGame. To be honest have no experience with rpgmaker nor pygame, but others seem to be enthusiastic about it. Unreal is also really nice, but I have no idea how easy/hard it is to start with dataflow programming (it does have the benefit of not having to learn textual syntax).
In any case they all (except for RPGMaker probably) include an imperative programming language too, so you can code whatever you want to make it "data-driven".

commodorejohn
Posts: 957
Joined: Thu Dec 10, 2009 6:21 pm UTC
Location: Placerville, CA
Contact:

Re: Coding: Fleeting Thoughts

Postby commodorejohn » Thu Oct 27, 2016 9:36 pm UTC

PyGame is a bit misleadingly named, it's pretty much just an SDL wrapper for Python and not an actual game-development toolkit. Still, if you're looking to do something from scratch anyway, you could do worse.

I'd stay away from GameMaker, it was clunky and unfun ten years ago and doesn't appear to have significantly improved in that time.

RPGMaker is a bit restricted in what you can do with it (it's right there in the title, after all,) but it's probably not too far off what you're shooting for, and newer versions (VX and onwards, I think XP as well) allow you to use Ruby scripts in addition to the simple state-machine logic of the previous versions, so it's a lot more flexible than it used to be.
"'Legacy code' often differs from its suggested alternative by actually working and scaling."
- Bjarne Stroustrup
www.commodorejohn.com - in case you were wondering, which you probably weren't.

User avatar
The Great Hippo
Swans ARE SHARP
Posts: 6834
Joined: Fri Dec 14, 2007 4:43 am UTC
Location: behind you

Re: Coding: Fleeting Thoughts

Postby The Great Hippo » Fri Oct 28, 2016 2:07 am UTC

I've worked with pygame pretty extensively, and toyed with RPG Maker (the one that relied on Ruby); I always end up getting lost in the details. For example, last time I tried with pygame, I ended up sinking several days of work into a way to dynamically recognize gamepads (as soon as they were plugged in) and handle their inputs.

I messed around with Game Maker recently, since it automates a lot of the things I end up struggling over... But I've found it's hard to maintain my interest when a lot of the problems are solved for me.

When it comes to programming a game, I seem to be obsessed with defeating myself.

User avatar
The Great Hippo
Swans ARE SHARP
Posts: 6834
Joined: Fri Dec 14, 2007 4:43 am UTC
Location: behind you

Re: Coding: Fleeting Thoughts

Postby The Great Hippo » Tue Nov 01, 2016 3:00 am UTC

I'm trying to create a function that takes strings with nested parenthesis and operators (ex: "4 + ((10 - 1) / 2)") and breaks the string down into a list of strings that can be interpreted as the correct order of operations (ex: ["10", "- 1", " / 2", " + 4"]).

This is turning out to be way trickier than I thought (but at least I'm learning about the shunting yard algorithm, plus prefix vs postfix vs infix notation).


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 12 guests