/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Old thread:

Other urls found in this thread:

upwork.com/
steve-yegge.blogspot.com/2006/03/execution-in-kingdom-of-nouns.html
cantrip.org/rust-vs-c .html
twitter.com/NSFWRedditImage

First for C.

D fags help pls

...

Free as in freedom CPU!

Replied

I am tired of working and at the same time I am too much of a pussy to open my own shop. Just want to write programs sitting in my panties at home and get a little bit of money in return. What are my options? Is freelance a meme?

upwork.com/

Mobile app development

haskell!

*trashkell

Sorry for the typo

Thanks anons, will try.

haskell is CUTE

Hi guys, I'm learning Haskell and I have no idea why my fizzbuzz implementation doesn't work?

1)
the input should be integral and showable, i.e.
(Integral a, Show a)
so that you can use mod on it (Integral a) and show(tostring) on it (Show a)
alternatively you could just use Int

2) in the final case, you want "otherwise = show x"
otherwise is simply an alias for "True", what's called the guard (i.e. the clause after |) is simply a boolean

Not as cute as you.

what if i am haskell?

>the input should be integral and showable, i.e.
Why?

(Integral a) indicates at the type level that you can perform "modulo" on a, and that a is a Num (which allows you to, among other things, use literals like 23 as type a)

Show allows you to convert it to a string

Not ALL types can be "mod"-ed, and not all types can be "show"-ed.
(Show , Integral ) =>
indicates that these things can be done with
They are constraints, like an interface.

Then you proved that \existsx[C(x) > C(x)] and thus that predicate calculus sucks.

fb :: (String a) => a -> String
this type signature is wrong. As is, it reads "take any type a that is an instance of String, and return a String." However, String is not a typeclass. You want
fb :: (Integral a) => a -> String
which reads "take in any type a which is an integral and return a string
otherwise x = x
This will not compile because your function returns a String and an arbitrary integral type is not guaranteed to be of type String. You want
otherwise x = show x
and now your type a also needs to be a show, so change your type signature to
fb :: (Integral a, Show a) => a -> String
which reads "take any any type a which is both an Integral and a Show and return a String.

Thanks.

thanks user I'll try that out!

Haskell is a very interesting language from what I've seen

It's more complicated than Go or Python with regards to the curve

in fact, if you use GHCI (or an editor plugin that shows you the type), you can look at the type of show and the type of mod
(see pic)

The simplest way of reading these, is:
(Integral a) =>
"Where a satisfies the interface Integral"
If it's a straight forward class like Integral or Show, you might just say
"Where a is showable"

- if you don't know that a is showable, how can you show it?


These constraints have to be satisfied, and traditionally that means they "float up to the top" - i.e., if you call a function that has a (Show a) constraint, then the function calling it normally also has that constraint.

You can make an exception for something like (Show Int), because Haskell trivially knows that there's an instance Show Int. Similarly (Show Double), (Integral Integer), etc.
But when you're writing a generic, you don't necessarily know that, so you must constrain it.

You can also have a 'superclass' of a constraint, i.e.
class Eq a => Ord a

(Ord a) only exists as (Eq a) does
This means if you know (Ord a), then you also know (Eq a)

Alternatively, you could do
fb :: Integer -> String
and not need to muck around with type classes at all

Is there any point in doing something like
#define MAX [some big number]

char *string;
string = malloc(MAX*sizeof(char));

When I could just
#define MAX [some big number]

char string[MAX];

in the example here Since you're using show and mod, you still need Show and Integral, but since it's

(Show Integer, Integral Integer)
Haskell already knows that they exist, so you needn't put that in something calling fb, for instance.

>sizeof(char)
Why would you size of a char?

I bet you don't even cast malloc

Yes, if you want to check for failures, if you want to resize it later or if you want to return it from the function that you created it.

Neither does

Can any of you tell me why syslog-ng refuses to compile on CygWin. When I run

./configure GLIB_LIBS=“-L/usr/lib -lglib-2.0 -lgthread-2.0 -lgmodule-2.0” —enable-sql —with-mongoc=no
make

it complains that there are undefined references to things like g_strdup, g_snprintf, etc even though these symbols should be present in /usr/lib/libglib-2.0.dll.a

Rate muh literal first program

cute

>windows
>C++
>using namespace std
>int fn = {}
>weird indention
>multiple couts when you could have used 1
>system("pause")
1/10

It works. That's pretty good for your first time.

>multiple couts when you could have used 1
No he couldn't. You can't put cins in the middle of a cout without some truly cringeworthy sepplesfag hackery.

Threadly reminder that dlang-chan is not dead; she's going to have her GC tumor removed (eventually); and she's super duper cute and easy to prototype in! Say something nice about her, /dpt/!

I get most of the gripes but why not use namespace std?

steve-yegge.blogspot.com/2006/03/execution-in-kingdom-of-nouns.html

Consistency user
it's always
malloc(number * sizeof([whatever])

>#include trash
>also using memespace STD
C++, LOL

>why not use namespace std?
its a bad habit to clutter your namespace but most importantly, youll quickly learn with C++, you want to be as explicit as possible. And that starts with std::cout,std::cin

No. You're stupid.

defeats the entire purpose of namespaces

Thanks user

cout

iostreams and C++ in general was a fucking mistake.

I'll take "What is size of char[/char]" for 300 points.

good good, in times you will start shilling visual studio and C++ like 50,000 other code monkeys with shitty programming style around the globe

String isn't a typeclass, dumbass.
fizzbuzz :: Integer -> String

What the fuck? That's not even close to valid syntax.

>you cant malloc exactly 1 bit in C
lmao

Show me any programming language that can do that.

this isn't bait enough

I thought C is "different"

Oh, I see what they did: they wrote char instead of code.
That's really fucking stupid.

I want a sideproject but I want it to unironically be useful to someone

Just write something the you personally would find useful.

What can you do with C++ metaprogramming?

The day for mild improvements is here!

Good ones

No, it's int *x = malloc(number * sizeof *x);

You still haven't listed one. Also, don't give me any of that "It's a booleans so it's 'one bit', even though the allocation is bigger' shit. I want to see a true 1 bit allocation.

literally EVERYTHIN
like fizzbuzz

>You still haven't listed one.
Do I have to?

>Show me any programming language that can do that
I was asking for a specific example.

I don't want to.

so why cant any """"""""""systems""""""""""""" language actually go down to 1 true bit?

Because basically every computer is byte addressed.

because you sorta can't address bits

Blame the jews

Byte by definition is the smallest addressable unit, so of course every computer will be byte addressed (Even if the byte is not 8 bits long)

What makes Rust better than C++?

I've encountered that in embedded systems class (writing 8051 code in C), but I am not sure it actually adressed 1 bit directly. There was probably some masking involved, since you cannot physically adress anything less than 8 bits (usually).

Sure you can, if Byte = 1 bit

Modules

Nothing, because its not.
Its verbosity is already approaching early sepples levels this soon, which is impressive.

cantrip.org/rust-vs-c .html

How is it possible for robust low level language to be safe? Seems like a fundamental compromise. Are Rust dudes deluding themselves or did they come up with some new revolutionary shit?

Rust people deluding themselves.

Anything remotely interesting in rust requires unsafe

Rust and C are not low level languages

Give me example

Whats lower than C thats not ASM?

There is no such scale of "low - lower - lowest - medium - medium-high - high" etc

MIR

>Python and C are virtually the same type of language

And?

template struct Factorial
{
enum { val = Factorial::val * N };
};

template
struct Factorial
{
enum { val = 1 };
};

int main()
{
std::cout

why the heck would someone make a language so over-complicated that you can't make a straight looking fizz-buzz

thats wrong and youd argue it if someone actually made the claim.

Both C and Python are "high level" languages

how do I make my own programming language

How is C as high level as python?
This is some next level contrarian shit.

Because there is no "scale" of "language level".
It's either abstraction or machine code

C is high level compared to assembly. Python is high level compared to C.

>theres no measurable degree of abstraction
alright

What is this?

>there is no scale

pls

Just because you're ignorant of the features programming languages provide doesn't mean everyone is.

Machine code != Assembly
Assembly itself is abstraction over machine code

>Just because you're ignorant of the features programming languages provide doesn't mean everyone is.
In what scenario would you argue that C is not an abstraction?