/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Old thread:

Other urls found in this thread:

comicvine.gamespot.com/metahuman/4015-55705/characters/
twitter.com/SFWRedditGifs

Haskell Wikibook is pretty good senpai.

Integer is an integer

Int is an Int (think C)

Int# is an unboxed Int, # is typically used for unboxed types

Haskell also has Word8, Word16, etc.
(Those are boxed though)

Integer is arbitrary precision.

Int is, as you said, think C.

Don't forget Int64 and friends.

So Int is recommended for dealing with natural numbers?

For some reason Haskell doesn't have a Natural type. Never understood why.

GHC has one, but it's not in base
It's proposed for haskell prime

You can always do it yourself

data Nat = Nat Integer
-- don't expose this constructor

-- todo: operations --

instance Num Nat where
fromInteger i | i < 0 = throwError ("Can't make nat out of " ++ show i)
| otherwise = Nat i

For instance: reading a natural number from a file or parsing an argument as a natural number.
Racket gives me this for free (at the cost of performance I guess).

Prelude doesn't have a Natural type, so use Integer
If you really want to make sure to use Natural, use GHC.Natural

Any of you into Computer Graphics ? What are you up to these days ? What are your projects. Pictures,github links,blogs and general thoughts would be appreciated.

do you like haskell?

I'm improving my GET tool with an integrated post form that uses a Sup Forums pass.
(I could add a captcha solver like in DelayClose, but that's just too unreliable for GETs since captchas expire really quickly and sometimes get rejected for no reason.)

This will allow me to drastically improve accuracy when posting large images with a GET, because I'll be able to start sending 99% of the data for a post to the server, and only have to confirm the post at the exact moment of the GET, instead of starting the upload at the moment of the GET and then having to wait.

The performance of my tool is currently of ~1500ms between the time a previous post is made and when it is detected, and for a small text-only post an additional 400ms between detecting and the GET post hitting the server, (but much longer for posts with large images).

So this currently works fine on slow boards, but almost 2s of delay it's too slow for big GETs.
This improvement should bring the total delay to around ~1600ms no matter the size of the post, and then I still need to work on improving detection times.

I have three different methods to detect new posts, two of which should be very fast and bypass all caching, but although very rarely they give detection delays as low as 250ms, the majority of the time it's closer to 1500ms, and I have no idea why.
If my ping is 20ms and a request comes back in

any ideas?

Wear a bra?

I'm interested, I made my own script using legacy captchas. Works pretty good and I've got a lot of quads & quints on Sup Forums & Sup Forums. What method are you using to detecting posts?

I'm no Haskell veteran, but it looks like a solid language. I also read a book on Racket, but I'm not sold. Haskell looks better in many aspects.

So there's 3 methods, the first is just checking the Page 1 using the Sup Forums API, and taking the last post in it, but that's very slow and unreliable, so it's only used on first start to get a rough idea of the current post ID.

Then I have two different methods using undocumented APIs to check if a particular post ID exists, so I keep track of the last post ID and keep checking until the next pots appears.

One of these is using the good old sys.Sup Forums.org//imgboard.php?res= API which is pretty well known, and the other one I haven't seen anyone else use, it's designed to bypass all caches and should be pretty fast, although in practice it performs roughly the same as the ?res API.

Why do some people think dynamic typing is a good thing?

Can you implement in haskel a fast calculation of a PDE with a CUDA acceleration?

It's easier to program with a duck typing.

What's haskel?

Haskell

Haskell who?

False economy.

Frankly speaking, I don't clearly understand what it is. Pajeets like to use this word in conjuction with the word Arch Linux or Apple MacBook. It seems very important in modern software engineering.

It depends on a context. Silicon chips are usually cheaper than engineers' time.

Curry!

Static typing catches errors faster, and requires less time to be spent debugging and writing tests.

[citation needed]

May be type errors are not frequent.

Static typing catches at compile time, dynamic typing at run time.

So what?

You also save time from the compiler being able to instantiate and pass things around automatically using information gleaned from types.

Anything that can explode at run time, should be covered by tests.

With the cost of neutering interactivity with your environment, along with limiting your metaprogramming.

Types aren't going to catch logic errors.

[citation needed]

>Template Haskell
>GHCi
Enough said. If you allow the full power of metaprogramming, you give up type-safety.

If you had to choose, I'd say yes.
No shit.

There're pros and cons and trade-offs in every technology. Some tools are better for some particular tasks. I don't see the point to argue about a family of languages for a some vague general case. People chose a technology to use according to many factors including a labour market.

>implying those two are the only possibilities

Metaprogramming delays type checking until after code generation at worst.

dynamic typing only became a thing because the type system of so called popular strongly typed languages were dog shit at that time

Feel free to name any other. There's a couple of Lisps I can think of.

C++ templates don't have this problem.

They literally do, and they aren't metaprogramming

Yes they do.

Nah, C++ templates definitely are metaprogramming.

>Nah, C++ templates definitely are metaprogramming.
How?

>Template metaprogramming (TMP) is a metaprogramming technique in which templates are used by a compiler to generate temporary source code, which is merged by the compiler with the rest of the source code and then compiled.

They're not simply generics that get monomorphised, they're much closer to macros since they basically just do code substitution. They do a modicum of type checking up front (i.e. you can't use an int as a typename/class parameter) but most of the type checking is delayed so you can do things like SFINAE.

C++ people might CALL it metaprogramming but that doesn't mean it is

They literally are monomorphized generics, parametric and ad hoc polymorphism is allowing you to do that stuff

What about metahumans?

+ overloading that is

but in sane languages you just call it programming

Yeah, I agree with that. Metaprogramming is a poor man's programming for the most part.

>sys.Sup Forums.org//imgboard.php?res=
Yeah that's the one I use. Is there any big advantage of using the method you mentioned over this one?

Imagine an abbo who's smarter than every other abbo

He's meta-abbo but is he meta-human?

and basically that's my opinion of C++ "metaprogramming"

comicvine.gamespot.com/metahuman/4015-55705/characters/

Implementing a twisty puzzle (à la Rubik's Cube) in console.

The other method seems to be ~5ms faster, but overall that's pretty negligible. I'm also sure that the other method is completely uncacheable, but in practice that's not very important since I'm still getting the weird 1500ms delay either way.

copyright it

I can't. The original idea is not from me. ANd I give it to the world. Cubes shoudl be free for cubers.

Is it for you to give away someone else's idea?

did you commit it to the systemd mailing list? pretty sure they would include it in the next release

>Is it for you to give away someone else's idea?
The idea is already published.

It merely shows that you have troubles with C++. Software engineers from Nvidia or id Software for example don't have this problem. It seems that they aren't going to move to a "proper metaprogramming" in your opinion.

No. I will try to integrate it to the bsd-games.

No, I'm saying that "metaprogramming" in a decent language is just programming.

Also, I noticed you said you were using GET to check if the post exists. You should use HEAD so you don't load the unnecessary body content.

C++ is a multiparadigm language you can call it whatever you want. Template metaprogramming is not a C++ term.

Yeah right now I use GET and fire a callback as soon as I see the headers, but that's pretty wasteful

>C++ is a multiparadigm language

Do you have anything to contribute?
According to your picture you should probably get some education, so I guess not.

fucking demolished
never show your face here again

fucking anime poster im gonna find you and dick you down for hours

What's wrong with this?

#include
#include

typedef struct rule {
const int factor;
const char *string;
} rule_t;

static const rule_t rules[] = {
{ 3, "Fizz" },
{ 5, "Buzz" },
};

int main(int argc, char **argv)
{
for (int i = 1; i

Works on my machine (tm).

Really good, +1 from me.

>using size_t for an index instead of ptrdiff_t

>it's another episode of user is too depressed to code episode
>reruns showing for 4 days straight

Why would you want a signed type for array indexing?

Ask him, he used an int index already.

Not for array indexing but for iterating over the integers he wanted to.

*lazy

>C++ is a multiparadigm language
but if you don't follow the official style of C++ OOP with templates you'll be laughed at

there are books you should know and follow those practices to be taken seriously

C++ sucks like that

We doing FizzBuzz again? Fuck yo modulos!
#include
int main() {
size_t f = 0, b = 0, to = 20;
for (size_t i = 1; i 2 ? 0 : f) == 2;
int bt = (b = b > 4 ? 0 : b) == 4;
int pnum = ft || bt;
printf("%s", ft ? "Fizz" : "");
printf("%s", bt ? "Buzz" : "");
printf(ft || bt ? "\n" : "%zu\n", i);
}
}

Thankfully, what people feel to be good code/programming practice has absolutely no influence on whether a language is multiparadigm or not.

Shit, I forgot to "optimize" the "pnum" variable away.

you are like a little baby
watch this

Oh, the password can be your pass cookie apparently.

How do I make the commented code work?
import Text.Read

areaTriangle base height = 0.5 * base * height

getLineDouble = do
line return x
Nothing -> error "invalid number"

main = do
putStrLn "The base?"
base

rate me
int StartTime;

async void Main()
{
StartTime = Environment.TickCount;

for (int i = 0; i < 100; i++)
{
await PrintFizzBuzzAsync();
}
}

async Task PrintFizzBuzzAsync()
{
await Task.Delay(1000);
int delta = Environment.TickCount - StartTime;
if (delta % 15 == 0)
Console.WriteLine("FizzBuzz");
else if (delta % 3 == 0)
Console.WriteLine("Fizz");
else if (delta % 5 == 0)
Console.WriteLine("Buzz");
else Console.WriteLine(delta / 1000);
}

++ (show $ areaTriangle base height)

>2015 + 2
>Not programming in almighty Java

What is your excuse?

Is there no way to remove the '(' and ')'?

I put n numbers which are presented as lengths of segments, how many triangles is it possible to make?
I am legitimately retarded person and wish to have some sort of critique. Are there better variants possible?

inb4 don't use c++

#include
#include
#include
#include

using namespace std;

int
main() {

vector v;
unsigned int count(0), length, temp, n;

for (size_t i = 0; i < n; i++) {
cin >> length;
v.push_back(length);
}


sort(v.begin(), v.end());

for (int i = 0; i < v.size(); i++) {
for (int j = 0; j < v.size() - 1; j++) {
if ((i < j) and (v[i] + v[j] > v[j + 1])) {
cout

To intelligent

Like the line above it. $ isn't a magic replacement for parens. $ has super low precedence, so haskell parses it like this:
putStrLn $ ("The area of that triangle is " ++ show) $ (areaTriangle base height)

And "The area of that triangle is " ++ show obviously doesnt make sense, so you get an error.

>$ isn't a magic replacement for parens
oh... I thought '$' simply inserted parens after the symbol.