Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 433 434 [435] 436 437 ... 796

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

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6510 on: November 04, 2014, 07:51:59 pm »

Ah, that is much nicer.  Based on my reading I was pretty sure I'd have to fill my __init__.py files with the needed exports, but I'll definitely have to try that.
Logged
Through pain, I find wisdom.

Orange Wizard

  • Bay Watcher
  • mou ii yo
    • View Profile
    • S M U G
Re: if self.isCoder(): post() #Programming Thread
« Reply #6511 on: November 04, 2014, 09:47:10 pm »

Code: (?) [Select]
from astronomy import *

...

Anyway, yeah. Python's import system does seem strange but it's not really an issue, to me, at least.
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.

Mephisto

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6512 on: November 04, 2014, 10:20:03 pm »

Code: (?) [Select]
from astronomy import *

...

Anyway, yeah. Python's import system does seem strange but it's not really an issue, to me, at least.

Want to know how I know you haven't had to maintain code written by people who didn't really know Python and didn't care about best import practices? I'm only being slightly facetious.

We no longer do wildcard imports at work. I honestly can't find a good place for wildcards. I would much prefer tens of lines of importing exactly what you need or one module-level import and then prefacing all calls with said module. Code we found in innumerable locations looks a little something like this:

A contains "from B import foo"
B contains "from C import *"
foo is defined in C

And that's not the worst of it. I believe one instance spanned four or five files.

The process to fix it was basically "fix this stupidity, run tests, and then hope all functionality was adequately tested to catch any breakages." Hint: the tests were not adequate.
« Last Edit: November 04, 2014, 10:26:18 pm by Mephisto »
Logged

Gentlefish

  • Bay Watcher
  • [PREFSTRING: balloon-like qualities]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6513 on: November 04, 2014, 10:27:09 pm »

Hint: the tests are never adequate.

FTFY.

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6514 on: November 04, 2014, 10:28:13 pm »

Wildcard imports are dumb. I see them in tutorials and I cry a little. I want to know where the damn class comes from, dammit.

Gentlefish

  • Bay Watcher
  • [PREFSTRING: balloon-like qualities]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6515 on: November 05, 2014, 01:21:36 am »

Good god I caught myself a weird bug.

So, working in flex. I get the .l file compiled right? Going to compile the lex.yy.c file and...

Code: [Select]
cc -c -g lex.yy.c
avl.l: In function ‘yylex’:
lex.yy.c:704:18: error: expected ‘;’ before ‘break’
 #define YY_BREAK break;
                  ^
avl.l:10:2: note: in expansion of macro ‘YY_BREAK’
 
  ^
lex.yy.c:704:18: error: expected ‘;’ before ‘break’
 #define YY_BREAK break;
                  ^
avl.l:62:2: note: in expansion of macro ‘YY_BREAK’
 %%
  ^
make: *** [lex.yy.o] Error 1

Spoiler: source (click to show/hide)

Wouldn't be coming to you guys if I couldn't figure out how to quash this bug myself. Not even google was able to help me.

The bug in question seems to be trying to point me to a completely blank line in the file avl.l

Not-actually-edit: I removed the newline separators from the file and yet it's still pointing at the same "problem" lines in the avl.l file.

E: HAHA GOT IT YOU ACTUALLY NEED TO INCLUDE A SEMICOLON AFTER LITERALLY EVERY LINE oops. Thought it broke on whitespace.
« Last Edit: November 05, 2014, 02:41:09 am by Pufferfish »
Logged

Orange Wizard

  • Bay Watcher
  • mou ii yo
    • View Profile
    • S M U G
Re: if self.isCoder(): post() #Programming Thread
« Reply #6516 on: November 05, 2014, 02:46:51 am »

Quote
Want to know how I know you haven't had to maintain code written by people who didn't really know Python and didn't care about best import practices? I'm only being slightly facetious.
To be fair, I finished highschool last year. I've never studied programming (well, except a course in school, but the teacher didn't no jack so most of the actual teaching was done by Prof. Google, and that amounted to bugger all), nor have I have ever worked in any software-related industry.
Everything I know on the subject is cobbled together from experimentation (by which I mean endless hours of ineptitude) and whatever poorly-written crap I could yank out of the interwebs. So, derp, of course I don't know the best practices.
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.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #6517 on: November 05, 2014, 03:07:53 am »

Wildcard imports are dumb. I see them in tutorials and I cry a little. I want to know where the damn class comes from, dammit.
I never knew you could wildcard import...
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6518 on: November 05, 2014, 04:02:27 am »

Then I am very sorry that you have learned of their existence. I should probably have put a memetic hazard warning on that.

Mephisto

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6519 on: November 05, 2014, 08:42:50 am »

Quote
Want to know how I know you haven't had to maintain code written by people who didn't really know Python and didn't care about best import practices? I'm only being slightly facetious.
To be fair, I finished highschool last year. I've never studied programming (well, except a course in school, but the teacher didn't no jack so most of the actual teaching was done by Prof. Google, and that amounted to bugger all), nor have I have ever worked in any software-related industry.
Everything I know on the subject is cobbled together from experimentation (by which I mean endless hours of ineptitude) and whatever poorly-written crap I could yank out of the interwebs. So, derp, of course I don't know the best practices.

No offense meant. You learn by making mistakes - that's how we learned. That's probably how best practices came around as well, enough people made the same mistakes enough times that we began teaching what not to do.
Logged

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6520 on: November 05, 2014, 09:08:24 am »

I've also really been annoyed at the fact that Windows is treated as a second class citizen for some Python packages, and Python 3 is also treated as a second class citizen.  It took me a few hours last night to find and install a library to output BMP files from Python code, during which time I could have probably coded it the hard way.  Some packages didn't install on Windows at all, and some either didn't work with Python 3 or misbehaved in poorly documented ways with it.  I'm still absolutely stunned that the NLP library installed on Windows with Python 3, but I did have to locate some files and move them around to get Python 3 to work with all of its features, none of which was documented.  Some kind of serialized object... a pickled egg I think Python calls it?
so much this, especially on the Python 3 part. You basically have to have 2 versions of Python installed to run all Python programs, which is maybe possible on Linux but almost impossible on Windows.
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.

karhell

  • Bay Watcher
  • [IS_A_MOLPY]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6521 on: November 05, 2014, 11:13:22 am »

I've also really been annoyed at the fact that Windows is treated as a second class citizen for some Python packages, and Python 3 is also treated as a second class citizen.  It took me a few hours last night to find and install a library to output BMP files from Python code, during which time I could have probably coded it the hard way.  Some packages didn't install on Windows at all, and some either didn't work with Python 3 or misbehaved in poorly documented ways with it.  I'm still absolutely stunned that the NLP library installed on Windows with Python 3, but I did have to locate some files and move them around to get Python 3 to work with all of its features, none of which was documented.  Some kind of serialized object... a pickled egg I think Python calls it?
so much this, especially on the Python 3 part. You basically have to have 2 versions of Python installed to run all Python programs, which is maybe possible on Linux but almost impossible on Windows.
Consider adding a third if you happened to think the 64 bit version was a good idea when you first installed python...
Logged

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6522 on: November 05, 2014, 01:18:22 pm »

Ah, yes, I noticed that too.  I really wanted to use a 64-bit version of Python since I'd rather not be limited by a 32-bit memory ceiling.  64-bit has been around long enough and Python is popular enough that I figured everything would support it by now, but a quick glance proved that to not be the case.
Logged
Through pain, I find wisdom.

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6523 on: November 05, 2014, 02:53:31 pm »

I've also really been annoyed at the fact that Windows is treated as a second class citizen for some Python packages, and Python 3 is also treated as a second class citizen.  It took me a few hours last night to find and install a library to output BMP files from Python code, during which time I could have probably coded it the hard way.  Some packages didn't install on Windows at all, and some either didn't work with Python 3 or misbehaved in poorly documented ways with it.  I'm still absolutely stunned that the NLP library installed on Windows with Python 3, but I did have to locate some files and move them around to get Python 3 to work with all of its features, none of which was documented.  Some kind of serialized object... a pickled egg I think Python calls it?
so much this, especially on the Python 3 part. You basically have to have 2 versions of Python installed to run all Python programs, which is maybe possible on Linux but almost impossible on Windows.

I'm doing fine on Windows. Hell, I've written something in both just in the last couple days. (Python 3 seems to be the de facto standard for DF-related GUIs these days...)

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6524 on: November 05, 2014, 11:39:42 pm »

I've managed to get plenty accomplished on Windows and Python 3 (32-bit), but I do worry every time I want to install a package that I'll have problems.  Case in point: the PIL package apparently has a complete fork to get it to work with Python 3, which took me a while to figure out.  That was only after looking at some unrelated library called Construct, which was way more complicated than what I needed.

I did get this made at least:


Maybe the rest of this post should go in the science thread.  :)

That's a cylindrical projection of the solar energy received by a planet's surface over the course of a single day for the planet.  Full white means that that section of the planet's surface is receiving approximately as much power as Earth would from the sun at its peak (1 Solar Luminosity).  Full black means no power.  The solar system in question consists of two medium-small binary stars in a close orbit, plus that planet and its single ring.  You can see at the start of the animation that the planet's surface is darker because one star is hidden behind the other, but it rapidly becomes visible as its orbit progresses.  The top of the image is brighter than the bottom because the ring is reflecting some of the stars' light back to the planet, and the dark line through the center is a shadow cast by the planet's ring.  I'm considering adding support for the planet's minor satellites, but they're tiny and it's already getting pretty slow if I turn up the resolution very much.  I think maybe the ring is reflecting too much light back, but I set its albedo to be the same as the moon.

By the way, this could probably be considered a terrible, terrible example of needless complexity, since I'm doing this for a text based game that I'm developing.  This is a debug image generated for my purposes.  I want to have realistic day and night cycles for the unusual solar configuration and ring, so a simulator was the easiest way to get that.  It will also let me theoretically add in some weather simulation later, although at that point I might have to move the astronomical calculations to another process (I gather that Python doesn't support concurrent threads so you must use multiple processes?).  If I do that I can probably ramp up the resolution a bit and decrease the update interval since it's not like second-by-second updates matter much.

Oh well, at least I was able to verify that my hand calculations on the system were reasonably valid and that a planet at that orbit should be habitable and have a pretty stable climate.  The simulator already showed me something unexpected: the planet has only about a 5 degree tilt so I figured seasons would be very mild.  The ring makes an enormous difference though, maybe making the seasons more pronounced than on Earth.  More experimenting is needed.

All told it works out to about 1,000 lines of Python code I think, consisting of tons and tons and tons of trigonometry and linear algebra.  I shudder to think how much C++ code this would have taken.
Logged
Through pain, I find wisdom.
Pages: 1 ... 433 434 [435] 436 437 ... 796