Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 389 390 [391] 392 393 ... 796

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

Maklak

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5850 on: May 11, 2014, 04:41:04 am »

OK, NVM. I was sure dollar was the convention, but now it starts to look as if I either saw it in some old book or made it up and fooled myself into believing it was common. Ugh, this is embarrassing. :o

I suppose, I should just remove the dollar and put commands in code tags, then. I want them to stand out. End of topic.
Logged
Quote from: Omnicega
Since you seem to criticize most things harsher than concentrated acid, I'll take that as a compliment.
On mining Organics
Military guide for FoE mod.
Research: Crossbow with axe and shield.
Dropbox referral

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5851 on: May 11, 2014, 05:46:15 am »

Eh, I don't blame you. When I use Git Bash for cherrypicking and other things that are annoying to do with TortoiseGit it also has that dollar.
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.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #5852 on: May 11, 2014, 07:12:49 am »

I made a thing. It's supposed to connect points with bezier curves(not actually fit a curve to points as the html says), and it does do that in a way, but not as well as I hoped. The curves are rather exaggerated and all.

My conditions were that the curve looks smooth, and that they were connected by bezier curves.


This is the idea I started with: connect three points at a time and match the slopes between sets of curves. It... didn't turn out well. The JS can be viewed through the page, or by replacing all "html" with "js".

I would appreciate someone's help in making a better bezier curve algorithm :(
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

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5853 on: May 11, 2014, 04:43:07 pm »

"Some sort of prompt symbol" is generally the convention when the example will also be showing output or including explanation. It's to distinguish between what you should put in, at the prompt, and what you will see in response or asides the writer wants to add. I've actually seen it in a lot of tutorials as well, and very very commonly in snippets in private text. Generally, if the command starts with a symbol ($ or > are common), and is meant to be put in as a command, ignore the symbol. The actual symbol used is generally "whatever symbol they copy pasted from their own prompt when they copy pasted this entire line". :3

And regular expressions are awesome. Hell, I use them all the time just for the games I run on the forum or when writing scripts. They are incredibly for any sort of "find/replace" need, since they support backreferences.

So you can, for example, do something like converting this:
* John went to the zoo, and then went home
* Amy went to the zoo, and then went home
* Tony went to the zoo, and then went home

with :%s/* \(\w*\) \(went to the zoo, and then went\) home/-> \1 \2 to \1's house/g
(vim syntax, actually executed in vim rather than rewriting this by hand)

to get:
-> John went to the zoo, and then went to John's house
-> Amy went to the zoo, and then went to Amy's house
-> Tony went to the zoo, and then went to Tony's house
« Last Edit: May 11, 2014, 04:49:50 pm by GlyphGryph »
Logged

Rose

  • Bay Watcher
  • Resident Elf
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5854 on: May 11, 2014, 11:44:07 pm »

I made a thing. It's supposed to connect points with bezier curves(not actually fit a curve to points as the html says), and it does do that in a way, but not as well as I hoped. The curves are rather exaggerated and all.

My conditions were that the curve looks smooth, and that they were connected by bezier curves.


This is the idea I started with: connect three points at a time and match the slopes between sets of curves. It... didn't turn out well. The JS can be viewed through the page, or by replacing all "html" with "js".

I would appreciate someone's help in making a better bezier curve algorithm :(

Can't you just reduce the length of the tangents?
Logged

da_nang

  • Bay Watcher
  • Argonian Overlord
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5855 on: May 12, 2014, 04:27:14 am »

And regular expressions are awesome. Hell, I use them all the time just for the games I run on the forum or when writing scripts. They are incredibly for any sort of "find/replace" need, since they support backreferences.
Deep inside me, a formal language theory student cries.
Logged
"Deliver yesterday, code today, think tomorrow."
Ceterum censeo Unionem Europaeam esse delendam.
Future supplanter of humanity.

Twiggie

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5856 on: May 13, 2014, 09:35:39 am »

Figured I'd ask here -
C# system.transactions.transactionscope seems almost too good to be true. I want to create a transaction around arbitrary sql commands with different connections and from what I can tell this lets me do it with only
 using var scope = new transactionscope()  blahsql() scope.commit()

So am I wrong in thinking that?
Logged

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5857 on: May 13, 2014, 10:52:40 am »

I would appreciate someone's help in making a better bezier curve algorithm :(
Sky, your goal is to use those bezier curves to create rivers for your Minecraft map generator, right? In that case, just pick any slopeX and slopeY you want for each node, based on the directions of the neighboring nodes, and draw the bezier curve between two nodes by using their locations and locations+slopes as control points. If you like, you can even add some noise to the locations and slopes to make the river look more natural.
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #5858 on: May 15, 2014, 09:22:53 am »

So, according to my compiler (Visual Studio 2013), pretty much every single sprintf() is unsafe!

warning: 'sprintf' may be unsafe. Consider using snprintf instead.
warning: 'snprintf' may be unsafe. Consider using _snprintf instead.
warning: '_snprintf' may be unsafe. Consider using _snprintf_s instead.


WHERE WILL IT END D:
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

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5859 on: May 15, 2014, 09:28:02 am »

And regular expressions are awesome. Hell, I use them all the time just for the games I run on the forum or when writing scripts. They are incredibly for any sort of "find/replace" need, since they support backreferences.
Deep inside me, a formal language theory student cries.
Wait, what do formal language theory students have against capture groups? I've... don't think I've seen a regex implementation that *doesn't* support them in quite a while...

Next you'll be saying lookaheads and lookbehinds and recursive patterns make you cringe in pain or something!
« Last Edit: May 15, 2014, 09:32:28 am by GlyphGryph »
Logged

forsaken1111

  • Bay Watcher
    • View Profile
    • TTB Twitch
Re: if self.isCoder(): post() #Programming Thread
« Reply #5860 on: May 15, 2014, 09:31:31 am »

So, according to my compiler (Visual Studio 2013), pretty much every single sprintf() is unsafe!

warning: 'sprintf' may be unsafe. Consider using snprintf instead.
warning: 'snprintf' may be unsafe. Consider using _snprintf instead.
warning: '_snprintf' may be unsafe. Consider using _snprintf_s instead.

Warning: '_snprint_s' may be unsafe. Consider using 'sprintf' instead.   8)
Logged

miauw62

  • Bay Watcher
  • Every time you get ahead / it's just another hit
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5861 on: May 15, 2014, 09:57:54 am »

How much do you know about programming?
It's hard to explain anything when we don't know what you already know.
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.

da_nang

  • Bay Watcher
  • Argonian Overlord
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5862 on: May 15, 2014, 10:31:16 am »

And regular expressions are awesome. Hell, I use them all the time just for the games I run on the forum or when writing scripts. They are incredibly for any sort of "find/replace" need, since they support backreferences.
Deep inside me, a formal language theory student cries.
Wait, what do formal language theory students have against capture groups? I've... don't think I've seen a regex implementation that *doesn't* support them in quite a while...

Next you'll be saying lookaheads and lookbehinds and recursive patterns make you cringe in pain or something!
Simply put, there are two definitions of regular expressions. The first and classic one is based entirely on Kleene algebra and supports union '+' (sometimes '|'), concatenation '·' and Kleene star '*'. This definition is equivalent to a DFA and thus represents regular languages (and in turn finite languages). This is what they teach you in Formal Language Theory.

The second one is based on either POSIX Extended Regular Expressions or Perl Regular Expressions (I forget which) that supports backreferences. Backreferences essentially add "memory" to the parser, something which DFAs do not support. In fact, it can be proven by the pumping lemma that the addition of backreferences leads to the parser being able to parse more than just regular languages (such as palindromes).

Calling them regular expressions to someone who is more familiar with the former definition sounds more like a misnomer, hence the cringe.

Lookaheads and lookbehinds, on the other hand, don't change what languages can be parsed AFAIK.

Logged
"Deliver yesterday, code today, think tomorrow."
Ceterum censeo Unionem Europaeam esse delendam.
Future supplanter of humanity.

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5863 on: May 15, 2014, 10:47:38 am »

I actually think think the might, but I'm not sure. Recursive patterns totally do, though. :D
Logged

Maklak

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5864 on: May 15, 2014, 11:12:39 am »

> Would someone kindly explain to me the idea behind templates and generic programming, and how those apply to a pleb like myself?

I have a simple example, but I'm writing without compiling, so my syntax may be off. Anyway, let's say you want a Max(a, b) function which returns the maximum as long as both arguments are the same type and comparable.
C lets you do something like that with a macro,

#define MAX(A, B) ((A) > (B)) ? (A) : (B)

but it has some drawbacks, such as the possibility that a or b may be an expensive function-call with side effects (say incrementing some global variable).
foo = MAx(bar(), baz());  // Calls one of these functions twice.

Now the same thing with a template:

template<class T>
T Max(T a, T b)
{ return (a > b) ? a : b; 
}

The compiler will translate T to appropriate type when it sees a call, so for example

Max(5, 7)

calls

int Max(int a, int b)
{ return (a > b) > a : b;
}

This has the unfortunate cost of bloating executable code because usually a lot of templates get generated with very similar code.

Now it should be clear the the purpose of templates is making smart substitutions. The example was simplistic. Now consider the task of making doubly-linked lists for a bunch of different things. In C you might re-write it for every one of them by hand. Or you might do something like a doubly-linked list with void * as the content to point at actual things. In C++ you write one template class for a list (already done in stl) and use that over and over for different classes. Well, you might use inheritance, but templates work better in this case.
Logged
Quote from: Omnicega
Since you seem to criticize most things harsher than concentrated acid, I'll take that as a compliment.
On mining Organics
Military guide for FoE mod.
Research: Crossbow with axe and shield.
Dropbox referral
Pages: 1 ... 389 390 [391] 392 393 ... 796