Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 658 659 [660] 661 662 ... 796

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

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #9885 on: August 09, 2016, 02:55:58 am »

Oh wait, I read your post wrong.
« Last Edit: August 09, 2016, 02:59:17 am by Skyrunner »
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

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9886 on: August 09, 2016, 05:04:10 am »

Speaking of web, how does one get started learning to program web applications? I don't want to rent server space for experiments and learning, so what do I need to download to reasonably simulate a website operating on a server (besides an IDE)?
Honestly, for my first website thing which was really just a shitty flappy bird clone, i wrote some basic javascript and then connected it to a bottle python backend with an sqlite database in there somewhere.

I usually use lighttpd as my webserver. (I was doing something dumb where lighttpd served the webpage but backend data handling was done on another port by bottle. don't do that, it's a pain in the arse). Lighttpd is exactly what it says on the tin: light. And simple. Sudo apt-get install lighttpd and you're halfway there.

Also if you're doing webdev keep the Mozilla Developer Network close by at all times. It's great.
« Last Edit: August 09, 2016, 05:06:17 am by miauw62 »
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.

Antsan

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9887 on: August 09, 2016, 05:59:34 am »

I would use any of those languages (well, maybe not php), but I'm not quite sure I could write a Makefile with those.
The idea would be that you'd have the script invoke the compiler for each source file to build the object files, then invoke the linker afterward.  Same thing that makefiles do, but admittedly it's something they handle relatively seamlessly and invisibly.  It would really only be helpful if you had some pretty complicated conditionals on which files got built and when.
Doing that would be superfluous. The Makefile is only a convenience for users who aren't used to Lisp, especially since Poslin needs somewhere between 4 and 8 GB of RAM to compile now, which requires starting up SBCL with some command line arguments so it doesn't crash.

With SBCL, "compilation" happens like this:
1. Start a Lisp process.
2. Load all the required files in the right order – this is quicklisp's/ASDF's job, which are just regular libraries. Compilation happens separately for everything on load – the compiled result gets dumped into the already running Lisp process.
3. Dump the running process into a core file or an executable. I only do the latter, but probably should fix my Makefile to do both, since it is slightly smaller than the executable.
Logged
Taste my Paci-Fist

Mephisto

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9888 on: August 09, 2016, 07:13:14 am »

But there's NOTHING in your Python example which shows how to filter page requests in this sort of custom manner. Show me the working code for that and I'll bet it's very similar in complexity.

You're comparing apples and oranges.

That was my whole point. Your comparison was also comparing apples to oranges.

If you're going to compare PHP to a Python web framework, make sure the two things you're comparing have similar feature sets. Of course the Python will look more complex if the thing you're comparing it to doesn't do url routing.
Logged

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9889 on: August 09, 2016, 07:19:04 am »

No, I gleaned that from looking at tutorials for getting a bare-bones web page up and running with Python. This is the hello world example from Python apparently:

Code: [Select]
import web

urls = (
  '/', 'Index'
)

app = web.application(urls, globals())

render = web.template.render('templates/')

class Index(object):
    def GET(self):
        greeting = "Hello World"
        return render.index(greeting = greeting)

if __name__ == "__main__":
    app.run()

And then you also need to also have the actual web page to render. How exactly is this easier than the equivalent version in PHP? It seems to require another whole layer of crap.
« Last Edit: August 09, 2016, 07:24:45 am by Reelya »
Logged

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9890 on: August 09, 2016, 12:12:26 pm »

TBH you should generally be using a more elaborate module for that, like bottle.

Code: [Select]
from bottle import route, run, template

@route('/hello/<name>')
def index(name):
    return template('<b>Hello {{name}}</b>!', name=name)

run(host='localhost', port=8080)
« Last Edit: August 09, 2016, 12:20:45 pm by miauw62 »
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.

breadman

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9891 on: August 09, 2016, 01:34:46 pm »

Don't you even dare think that Python is even close to the level of raw scripting convenience Perl has. >:(

There are certain things I still use Perl for, but every time I do, I have to look up how to use one or more of its basic container types.  Python's just so much easier to use.

But you're right, dedicated syntax for regular expressions makes a difference at times.  I just don't reach for it nearly as often with Python, preferring string methods where possible or real parsers where necessary.

Granted, Python's regex support is still far superior to PHP's, which for some insane reason requires explicit delimiters inside a quoted string.  (Yes, I know it lets you specify flags.  That should have been a separate parameter.)

What about any of the Apache branches? It's probably simple enough to compile vanilla Apache for myself, but I'm feeling lazy and many of the branches just have plain installers.

That should be fine to start with.  For the real server experience, you'll eventually want a Linux machine, where you can install Apache through the package manager.

Is it worth even learning PHP, or should I just start with Perl or Python? I've already used Python before but Django looks scary.

It's generally worthwhile to learn as many languages as you can, so you know which one's right for the job at hand.  Fortunately, most of the concepts are shared, so each one tends to be easier than the last.  For web in particular, Django can be complex, but not nearly as complex as creating a site by hand.  Flask and Bottle are simpler alternatives, though they don't give you quite as much power out of the box.  PHP is easier to start with, but all the little gotchas get annoying after a while, and starting without a framework leads to a fragile site.  Perl is better for simple regex-based text processing, but Python's almost as good at that anyway, so you can live without it.

beside everyone is missing the main strength of php: hosting costs 12$/year. find a hosting with same feature and allowing for running a python/java server, I dare you.

Heroku does a decent job with their free tier, for low-traffic sites.  But yes, it's much simpler to host multiple unrelated PHP sites together than Python webservers.

No, I gleaned that from looking at tutorials for getting a bare-bones web page up and running with Python. This is the hello world example from Python apparently:
No, that would be the hello world example for a particular framework.  The equivalent of using CakePHP or some such; much messier to start up, but designed to make your life easier a few thousand lines of code down the road.

Granted, the pure Python code isn't that much simpler, though it's flexible enough to handle your routing example:

Code: [Select]
from SimpleHTTPServer import SimpleHTTPRequestHandler, test

class RequestHandler(SimpleHTTPRequestHandler):
    def do_GET(self):
        extensions = [
            '.png',
            '.jpg',
            '.jpeg',
            '.gif',
        ]
       
        path = self.translate_path(self.path)
        if any(path.endswith(ext) for ext in extensions):
            SimpleHTTPRequestHandler.do_GET(self)
        else:
            self.send_html("<p>Welcome to Python</p>")
   
    def send_html(self, text):
        self.send_response(200)
        self.send_header("Content-type", "text/html")
        self.send_header("Content-Length", len(text))
        self.end_headers()
        self.wfile.write(text)

if __name__ == "__main__":
    test(HandlerClass=RequestHandler)

And then you also need to also have the actual web page to render. How exactly is this easier than the equivalent version in PHP? It seems to require another whole layer of crap.

In both cases, the whole layer of crap is the web server itself, replacing Apache or php -S.  Basically, PHP was designed to make the web part invisible, where Python is a more general-purpose language.  Of course it's not quite as convenient as a more specialized language for certain tasks; the amazing part is that it's almost as good at everything, from text processing to web serving to data mining to desktop games.
Logged
Quote from: Kevin Wayne, in r.g.r.n
Is a "diety" the being pictured by one of those extremely skinny aboriginal statues?

Meurlorg

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9892 on: August 14, 2016, 05:41:30 pm »

I know I'm a bit off topic, thread wise but I dint feel like creating a post just to get some attention, lolz, anyway the reason I posted here is that I'm hook with tweaking Dwarf Forest despite the fact I only play legendz and adventure thus far anyway here is a little bit about me.

God I was so ready for this game, I actually found out about it a few years back but
could never get into it cough WASTED YOUTH, until now that is, and what really did it for me was legends mode, you see I found modding a frankenstien like creature to be utterly exhilerating especially if
you couple that with the above mention legends mode, as you watch your creation live the
next thousand years in anonymity.....so the reason I posted this is that I just want to say,
thank you for giving me this experience, graphics be damn, the experiences itself is worth
a mountain of triple A game! Anyway thank you for having me, I hope to further my ability to
mod or should I say tweak a little here and their and watch the chaos unfold, muhahaha, cough,cough.

ps, I've been up all night since I sighned up for the forum, playing Dwarf Fortress, and I'm
still going strong.....snore...
Logged

Meurlorg

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9893 on: August 14, 2016, 05:55:49 pm »

OOps I had a bit more to say, too bad I cant edit anyway I don't its just me being new but I generated a world last night, fully with land and everything but when I took my eyes away for a moment when it was generating when I looked back their was a god freaking massive hole in the middle of the map...... boy was I excited, you guys have any idea what could have caused it, it seem so instantaneous at the time but when I think back, maybe a few hundred years past in that world.lolz food for thought
Logged

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9894 on: August 14, 2016, 05:58:51 pm »

You should probably take the questions up to the boards with DF on the start. e.g. DF General Discussion. The lower boards are for non-DF related topics, this thread is to help people with their personal programming projects and the like, not discussion of existing games.

Meurlorg

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9895 on: August 14, 2016, 08:12:03 pm »

Alright then but I was wondering offhand, is their any interest ways to mod/tweak the game?
Logged

Orange Wizard

  • Bay Watcher
  • mou ii yo
    • View Profile
    • S M U G
Re: if self.isCoder(): post() #Programming Thread
« Reply #9896 on: August 14, 2016, 08:20:02 pm »

Alright then but I was wondering offhand, is their any interest ways to mod/tweak the game?
You can do some pretty complicated scripting with DFHack, but again, more appropriate to ask in the DF Utilities board rather than here.
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 #9897 on: August 14, 2016, 08:39:04 pm »

Alright then but I was wondering offhand, is their any interest ways to mod/tweak the game?

For modding DF, there's a whole board DF Modding. I recommend reading through a pile of the sub-topics there before posting, and try and implement / adapt some of the ideas in there for your own game.
« Last Edit: August 14, 2016, 08:44:04 pm by Reelya »
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9898 on: August 14, 2016, 09:31:45 pm »

lmao i wish i had any ideas for dwarf fortress mods that are actually implementable in anything else

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #9899 on: August 17, 2016, 10:34:54 am »

past sky why did you write this piece of code

Code: [Select]
// sort all.
for (var i = 0; i < results.length; i++) {
results[i].sort(function(d1, d2){ return - d1[1] + d2[1]; });
}

What are you sorting? WHY are you sorting? And why is the index of sorting -d1[1]+d2[1]?!

I fear I will never get any answers. Refactoring, ugh.


It's made worse because it's javascript, so there's no type hints to go off of. Good thing I'm rewriting as typescript and catching all these weird things.
« Last Edit: August 17, 2016, 10:37:30 am by Skyrunner »
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
Pages: 1 ... 658 659 [660] 661 662 ... 796