Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 469 470 [471] 472 473 ... 796

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

Willfor

  • Bay Watcher
  • The great magmaman adventurer. I do it for hugs.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7050 on: March 09, 2015, 05:48:16 pm »

Hm. Is there a profiler type thing for Python?
cProfile.

The way I get it to work on my programs is to write a separate python file with this in it:

Code: [Select]
import cProfile
cProfile.run('import [entry file name]')
Logged
In the wells of livestock vans with shells and garden sands /
Iron mixed with oxygen as per the laws of chemistry and chance /
A shape was roughly human, it was only roughly human /
Apparition eyes / Apparition eyes / Knock, apparition, knock / Eyes, apparition eyes /

Orange Wizard

  • Bay Watcher
  • mou ii yo
    • View Profile
    • S M U G
Re: if self.isCoder(): post() #Programming Thread
« Reply #7051 on: March 09, 2015, 05:57:09 pm »

Beautiful. 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.

Squeegy

  • Bay Watcher
  • I don't really have any answers for you.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7052 on: March 10, 2015, 01:10:46 am »

What's your guys' favorite programming term? The one word that's the coolest piece of programmer jargon.
Logged
I think I'm an alright guy. I just wanna live until I gotta die. I know I'm not perfect, but God knows I try.
Kobold Name Generator
⚔Dueling Blades⚔
Fertile Lands
The Emerald Isles

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7053 on: March 10, 2015, 01:50:28 am »

Deep Magic/Heavy Wizardry.

Related, but not the same.

Thief^

  • Bay Watcher
  • Official crazy person
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7054 on: March 10, 2015, 01:58:19 am »

Swizzle, meaning to rearrange (typically color/vector components in graphics programming). It's just a fun word :)
Logged
Dwarven blood types are not A, B, AB, O but Ale, Wine, Beer, Rum, Whisky and so forth.
It's not an embark so much as seven dwarves having a simultaneous strange mood and going off to build an artifact fortress that menaces with spikes of awesome and hanging rings of death.

Gatleos

  • Bay Watcher
  • Mournhold... City of Light... City of MAGIC!
    • View Profile
    • Someone Sig This
Re: if self.isCoder(): post() #Programming Thread
« Reply #7055 on: March 15, 2015, 01:04:14 am »

AUGH

Is there a less time and space consuming way to use multiple aggregate functions together in SQL? Something like MAX(COUNT(*)) won't work, so you have to write a subquery returning the list of grouped COUNT values, then wrap a query around it that returns MAX. But wait, I don't want the MAX value itself, I want the value in another column whose COUNT is equal to that MAX value. So now, I have to copy/paste the exact same query I already wrote to get the same table, and compare the MAX value to each row in a HAVING clause to find the highest value and display the associated value I want. And THEN I have to use that value in another nested query layer, so I copy/paste it again.

This problem only contained a couple steps, and the query is 22 lines long. Is SQL code actually this bloated, or am I missing some extremely useful feature of the language?
Logged
Think of it like Sim City, except with rival mayors that seek to destroy your citizens by arming legions of homeless people and sending them to attack you.
Quote from: Moonshadow101
it would be funny to see babies spontaneously combust
Gat HQ (Sigtext)
++U+U++ // ,.,.@UUUUUUUU

karhell

  • Bay Watcher
  • [IS_A_MOLPY]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7056 on: March 16, 2015, 07:33:30 am »

Yeah, SQL tends to get very verbose when it comes to that kind of problem. There might be something shorter than what you did, but without knowing the specifics of the problem, it's pretty much impossible to tell.

Also, is this tied to a specific DBMS ? I'm unsure about others, but oracle has some pretty nifty analytical functions that might be able to help (such as row_number() over(partition by ... order by ...) ).
Logged

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7057 on: March 16, 2015, 07:37:50 am »

Well, 22 lines to do that. I'm sure Java or C++ would be many more than 22.  Though if there are repeated patterns as you suggest I'm fairly sure there would be ways to cull it down though.

Tylui

  • Bay Watcher
  • O_o
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7058 on: March 16, 2015, 04:53:51 pm »

ptw! can't believe I didn't know about this thread.

I had a similar SQL issue the other day. A client wanted some stats on their orders, related to retailers and sales rep, but the stats they wanted were extremely complex and I spent a couple hours building this huge SQL query. I went back to make sure I solved their problem when I realized what he wanted and what he was asking for were two different things... I went back had just a nice select distinct from where order by statement. SQL is easily one of the most frustrating parts of web development sometimes, but it beats a flat file "db" by miles and miles.
Logged

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #7059 on: March 16, 2015, 05:52:53 pm »

I think these are usually the points where I break out LINQPad to figure out the SQL, but I'm one of those people who find it easier to turn (functional) LINQ into SQL than writing SQL straight.
Logged

Levi

  • Bay Watcher
  • Is a fish.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7060 on: March 16, 2015, 05:55:10 pm »

I wish I could post some of the ridiculous sql I've had to write at work, but I don't think I'm allowed.   :P

Edit:  Although, I can probably post this non-ridiculous and actually quite handy function I wrote for oracle.

Code: [Select]
CREATE OR REPLACE FUNCTION concatenate_list (p_cursor IN  SYS_REFCURSOR,delimiter IN VARCHAR2)
  RETURN  VARCHAR2
IS
  l_return  VARCHAR2(32767);
  l_temp    VARCHAR2(32767);
BEGIN
  LOOP
    FETCH p_cursor
    INTO  l_temp;
    EXIT WHEN p_cursor%NOTFOUND;
    l_return := l_return || delimiter || l_temp;
  END LOOP;
  close p_cursor;
  RETURN LTRIM(l_return, delimiter);
END;

Which lets me turn a bunch of rows into a single delimited text field(which comes in handy sometimes).

Code: [Select]
select concatenate_list(cursor (select name from example_database where velociraptors>5), ', ') from dual

bob, frank, julie, boris

« Last Edit: March 16, 2015, 06:05:23 pm by Levi »
Logged
Avid Gamer | Goldfish Enthusiast | Canadian | Professional Layabout

Tylui

  • Bay Watcher
  • O_o
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7061 on: March 16, 2015, 06:37:11 pm »

wow bob, frank, julie, and boris have quite a few velociraptors! I hope their electrified cages are working properly... Clever girls...
Logged

Gatleos

  • Bay Watcher
  • Mournhold... City of Light... City of MAGIC!
    • View Profile
    • Someone Sig This
Re: if self.isCoder(): post() #Programming Thread
« Reply #7062 on: March 16, 2015, 09:58:39 pm »

I don't mind the verbosity, I just hear this screaming in the back of my head every time I fetch a table with a specific set of conditions... then SQL's syntax forces me to discard the entire thing and set it up again to do what I want. I only have a problem with that fact that the language seems to want to cram every possible problem solution into the format of a SQL statement.

One annoying thing about it to me is the arbitrary ordering for clauses. Like, in every other imperative programming language ever, the only thing you have to remember is "statements at the top execute before statements at the bottom". But in the name of making SQL "user friendly", the clauses in SQL queries are laid out in a way that resembles English grammar. Which means they aren't written in the order they execute. So now I have to remember what the actual order is when I'm creating and referring to aliases, and it's no longer as simple as a single rule.

The most annoying side effect is what I already referred to: in another language I would load a table using a set of WHERE conditions, then perform all the operations I wanted on this one table instance I created. But contorting my solution into the shape of a SQL query means I inevitably have to write redundant and inefficient queries that load it again and again. It seems like SQL syntax only works well with smaller problems, and as soon as you get even a little complex (about the time you start using joins and subqueries) it all breaks down.

But I am doing this in a classroom, where the requirements may not accurately reflect those in a real scenario. So ignore everything I just said I guess. :P
Logged
Think of it like Sim City, except with rival mayors that seek to destroy your citizens by arming legions of homeless people and sending them to attack you.
Quote from: Moonshadow101
it would be funny to see babies spontaneously combust
Gat HQ (Sigtext)
++U+U++ // ,.,.@UUUUUUUU

Spehss _

  • Bay Watcher
  • full of stars
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7063 on: March 20, 2015, 08:59:27 pm »

ptw
Logged
Steam ID: Spehss Cat
Turns out you can seriously not notice how deep into this shit you went until you get out.

gigaraptor487

  • Bay Watcher
  • Escaped Lunatic now civilised
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7064 on: March 29, 2015, 05:13:12 pm »

ptw
Logged
Hehe, you thought there would be an interesting sig here

I now run a program which brings old multiplayer games back to life : click
Pages: 1 ... 469 470 [471] 472 473 ... 796