/dpt/ - Daily Programming Thread

old thread: What are you working on, Sup Forums?

Other urls found in this thread:

youtu.be/WdpBnGpRuL0?t=2m6s
youtu.be/Hxo1dS2KssE?t=30s
interactivepython.org/runestone/static/thinkcspy/index.html
twitter.com/NSFWRedditVideo

Type inference is only needed in langlets who lack dependent types.

Lisp is the most powerful programming language.

LiquidHaskell is part way to what you propose. I actually think it is on Rust's roadmap to integrate a Prolog-like logic, at least for generics (code generation would be a future possibility).

Repeating the question from the other thread:

I was trying to imitate the Bubble Sort algorithm after understanding the concept (to study for a test). The picture related shows my result, but I don't think I'm actually doing the Bubble Sort like it's really suposed to be.

So my question is: Is the sorting algorithm that I programed more similar to another sorting algorithm than Bubble Sort?

Here's the code:
int arr[10];

void RandomArray();
void BubbleSortImitation(int ArraySize);

void main()
{
RandomArray();
}

void RandomArray()
{
system("cls");
int i, n = sizeof(arr)/sizeof(arr[0]);
srand(time(NULL));

for(i=0;i

Not at all relevant, as we're talking about value inference here, not type inference.

Ever heard of a bidirectional type system? You retain most of what unification based type inference gives you in a dependent type system while remaining decidable. In practice, you only need to annotate at the top level, which is already considered good practice in languages with full type inference.

Just wanted to come in and tell you all that programming, regardless of language, makes me want to gouge my eyes out in boredom. I would literally rather shovel shit than program. I say this as a network Admin with security certs. Shit's boring.

And I applaud anyone who makes something of themselves with programming. Don't know how you guys do it.

>value inference
absolutely disgusting

>absolutely beautiful
ftfy

MYSTERIOUS NUMBER!!! OOOOoooOoOooo ooga booga

Spooky code desu

the way you use functions is awful

Doing super-early python stuff because i'm bored, first assignment was just to see what someones age was in seconds and make it interact-able with inputs, super early on but it still pretty fun.

It's just the way I like to order them.

youtu.be/WdpBnGpRuL0?t=2m6s

Do you think automated theorem proving is disgusting? It's the same thing.

the way you organize your code is a garbled mess, either make functions perform specific roles or put all your code in main, don't use functions as some arbitrary grouping system that call themselves one after the other

oh yeah well
youtu.be/Hxo1dS2KssE?t=30s

It's the way I present the code. I like to have all the functions under the main but I'm also leaving the functions up there to know which functions I'm using.
Usuallly I make really large codes and that's just the way I organize myself.
If that's not the way you make your codes it doesn't mean my way is bad.

He's saying it should look like this.
void main() {
int[] arr = GetRandomArray(10);
BubbleSortImitation( arr);
}

int[] GetRandomArray( int size) {
// etc
}

void BubbleSortImitation(int[] arr) {
// etc
}

You see how each function does what its name implies, takes what it needs as parameters, and could be modularly used in many circumstances? Your mix of nested functions with a randomly-global array is, for lack of a better term, completely fucking retarded.

>It's the way I present the code. I like to have all the functions under the main but I'm also leaving the functions up there to know which functions I'm using.
>Usuallly I make really large codes and that's just the way I organize myself.
This isn't what we're talking about.
We're talking about why does RandomArray call your sorting function.
And also, why does your sorting function always sort the same array.
Contrary to its name, RandomArray doesn't even return a random array, it just builds one, and it's not even truly random because it's always sorted.
And your sorting function is also misleading, seeing as how it doesn't sort any given array, just the global one.
Global variables are a bad idea by the way.

How long should it take or how extensive should my knowledge be of programming before I start pursuing a career. I still have a looooong way to go but need to get out of this shitty motorcycle dealership I work at.

My only experience is some training in HTML5 and CSS (enough to build a small website for a class project) and just started learning python. I just want to get an easy to grasp of what programming is before I start something like C++ or Javascript.

What's Sup Forums's experience in this field without a degree?

>And also, why does your sorting function always sort the same array.
Did you even run the code?
It's not always the same array. It sorts any random array built by RandomArray.

>it doesn't mean my way is bad
It isn't a difference of opinion. There are a few right ways, and many wrong ways to structure code. Yours is one of the wrong ways. It makes the code objectively less readable, and completely unusable in a modular fashion.

>int[] GetRandomArray( int size)
This doesn't look like a valid function though.
Where's the void.
Also things don't belong in the parentheses.
Your code just looks like gibberish to me.

...

wow there's actually an anime which mentions Sup Forums?!

>It's not always the same array. It sorts any random array built by RandomArray.
It is indeed always the same array, as in always the same array object in memory, regardless of that array's contents. You can't make it sort an array declared elsewhere, for example.

Which makes it completely useless. It is a function that creates an array and sorts it, without even returning it. As a side effect it prints some shit to stdout. It performs no useful work.

what's the best way to learn C++17?

inb4 no one uses it

but I want to start learning it anyway

>unreasonably difficult, slow, and unusable
Well that's just not true.

C++ is fucking trash.
Why would you want to use it?

Learn Javascript now, it's good with your HTML and CSS combo.
There's literally no reason for you to learn C++ if you're going to be a webdev which is what you should shoot for without a degree. You also already know the front-end other than Javascript.

and Kim Jong Un is a tall and slim stud

Do you realize even if you fall for the "rustlets = sjws" meme and call C++ trump for contrast, that's still an insult to trump because both languages are trash?

Bernskell should have won, then we could have had a pure functional America with an expressive algebraic type system and no mutable state

I want /the_donald/ Sup Forumsdditors to leave.

that's all I really know up to version C++14

I'm too old to learn something else

>no mutable state
This is a limitation of Haskell, not a good thing. Linear types, baby. They're the libertarians and linearity is the NAP.

>mfw still using c++98 and never learned anything else

>This is a limitation of Haskell, not a good thing.
objectively wrong
>Linear types, baby. They're the libertarians and linearity is the NAP.
so in other words libertarians are socialists??
that's news to me

Are you baiting or do you actually not know how to program?

Do you think it's impossible to have mutation in a pure language?

The guy I was pretending to be actually doesn't know how to program.
I, however, was baiting.

At the semantic level, yes, because if there's mutation it's impure
I don't care what happens under the hood though, I don't have to because pure languages are safe

that's a mistake since C++11 revolutionized the whole language and made it really comfy and modern

calm down, it's a parody twitter ridiculing Trump's craziness

Do you think it'd be possible to fuck with audio in such a way as to render them useless to speech recognition AIs? Ideas? C#

but is it as comfy as haskell tho
imean why would i want to learn it when ive since migrated to the magnum opus of languages

I would really love to see more type-directed code generation in the future. DeriveFunctor is an extremely simple example, yet it is very powerful.

>linear types
Meh.

Not him, but actually-mutable state monads have been a thing for a long time.

Bernie isn't Haskell, Haskell has typeclasses and Bernie seeks the dissolution of the class system.

Are there even really that many changes in C++17? It's got some helpful little shorthand features, but what's the biggest thing in there? Fold expressions? It's not like C++11, not a whole lot you gotta relearn. Just read a feature list.

haskell is not comfy for writing multi-threaded low level apps

>"""comfy"""

>(ReturnTypeReturnType*)
what

Definition of purity:
>In computer science, purely functional programming usually designates a programming paradigm—a style of building the structure and elements of computer programs—that treats all computation as the evaluation of mathematical functions.
Fancy way of saying that f(x) = f(x), i.e. when you call a function with the same input you get the same output. Forbidding mutation is one way to get purity, but it is not necessary. Linearity looks at the "call a function with the same input" part and allows you to restrict that. If writing to a pointer takes as a parameter a value representing the entire world and outputs a value representing the entire world after the write, now you have purity. Linearity enforces that you cannot copy or delete the entire world. You can do this with monads but you lose expressivity or at least trade it off big time with added verbosity.

Prove to me right now that there's any reason to learn anything other than C++ and various assembly languages.
Pro-tip: you literally can't.

no one writes shit like that except library developers that spend tons of time validating their code and coming up with clever optimizations and then have it reviewed by other experts so after like a year or two it can be tested in boost or something

C++ is the krokodil of programming languages.
It will literally rot your brain.

I don't accept linearity as pure. It may be computer science pure but it's not pure of heart.
Linearity without mutable state is okay and interesting though but defeats the purpose.
Also Haskell does this under the hood anyway.

I tend to agree but there's nothing better

actually with web assembly gaining support across browsers, there's a really good reason to learn c++

Asslel confirmed for most brainlet language, can't even do inheritance

POO

Until it actually becomes industry standard, nah.

>It may be computer science pure but it's not pure of heart.
What?

>Linearity without mutable state is okay and interesting though but defeats the purpose.
What the fuck are you even talking about

>Linearity without mutable state
No, linearity is a bitch to program in.

>defeats the purpose
Do you realize that
let (x,y) = some_linear_pair in
(f x, y)


and

let p = some_linear_pair in
modify_first p f; (* destructive mutation *)
p

are semantically equivalent? The former is typechecked to prevent reuse of destructively modified data, while the latter is more efficient. Thus a compiler can safely transform one to the other.

C

don't be ridiculous you need classes

>it's good with your HTML and CSS combo
If someone told me that they knew HTML and CSS and didn't know Javascript I would laugh them out the door.

>you need classes
>I don't know how to program other than to POO
Go home, fag.

Ahh nice. I can see how that would work well together. I suppose once I have down enough to be comfortable with the 3 I can always opt to learn something not web development oriented. To be well rounded that is.

Like I said, it's good with their HTML and CSS combo :^)

some things are naturally objects, so why create a mess and not let your IDE give you good suggestions and let you code ten times faster?

here, read this:
interactivepython.org/runestone/static/thinkcspy/index.html

I thought you were learning JavaScript first, had me going there.
That's a bad path to walk.

Imagine being the kid who was taught arithmetic in something stupid like Reverse Polish notation. That's what learning JavaScript first is like.

Yea of course. I honestly really recommend getting good at web development. My mom's friend's kid completed one of those 3 month web development bootcamps a few months ago, and just landed a job making 92k a year doing full stack. There's a shit load of good work in that market right now and it's only gonna grow in the coming years.

>you can't store noncopyable data in Rust unions
>there's no unsafe copyable wrapper, either

Why would you want to put noncopyable data in a union?

To write a pool allocator that uses empty segments to store the linked list of empty segments. You can't just cast the pointer because of size and alignment concerns that a union takes care of, and an enum would be wasteful.

That's a great resource. Thank you sir. I'm currently working my way through zedd shaw's learn python the hard way book so It's nice to have more material to go through once I finish that.

Sounds like you're gonna have to handle alignment yourself.
Or could you make the link list copyable? (e.g. contains just an unsafe ptr)

>don't use rust
Problem solved lad

>Or could you make the link list copyable? (e.g. contains just an unsafe ptr)
That wouldn't be reusing the otherwise unused memory.

The only other suitable languages are C and C++ and I despise them.

try nim
it's GC is actually optional.

>nim
case insensitive piece of shit

I have some uni work to build a JVM in C.
So, here's my problem:
At certain point in the code, this line is called
memcpy(&pointClassFile->nameClasse, &(pointClassFile->constant_pool_table[index - 1].info.Utf8.bytes), length+1*/);

None of that matters besides what the second argument (bytes) and the last one (length+1) are.
bytes is a pointer, and it points to an address where a sequence of length (+1 for a null terminator) bytes are. it's definition is made through this:
constantPool[i].info.Utf8.length = LE_read16bytes(filePointer);
constantPool[i].info.Utf8.bytes = malloc(sizeof(uint8_t) * (constantPool[i].info.Utf8.length+1));
fread(constantPool[i].info.Utf8.bytes, 1, constantPool[i].info.Utf8.length, filePointer);
constantPool[i].info.Utf8.bytes[constantPool[i].info.Utf8.length] = '\0';

As far as I can see, everything is perfect. However, when I run the code with Address Sanitizer, I get a heap-buffer-overflow error
I checked it out, and the error happens when length+1 is larger than 24.

After the error, ASan provides a visual representation of the memory (pic related). The value between brackets is what byte is pointing to
It seems that only 8 addresses for 8 bytes were allocated, even though 27 were requested. Because of that, it reads into some other allocated value, and gives me the heap-buffer-overflow. Such is this that, when I replace length+1 on my code to a constant value of 8, it goes through all the files (up to the point of another bug, but that's something else)
So I was wondering, what the fuck is wrong with this? Why are 27 values not being allocated? It isn't because the memory is full, since if I replace length+1 to anything above 24 it returns the error on the very first time it is called, and by then almost nothing has been allocated

gee user you sure are picky

on jump-to-directory-or-file tool.

I said goes through all the files because that part is pretty much only for reading files by the way

you can force yourself to like C++

why doesn't this work

class A{
private:
std::vector foo(A::count, 0);
public:
enum{A,B,count};
}

This is old C++.
That entire trailing return can be omitted.

also, can i make this work somehow?
class A{
public:
"???" someNum = A::a;
enum {a, b, c};
}

Not really. Just don't like eating shit, that's all.

and yet you're using rust

WTF is this shit even supposed to do?

>someNum = A::a;
why?

are you trolling, bro?

nope.

how about a RandomArray function that returns a random array, and how about a BubbleSort that takes an array pointer and a length and returns either nothing (in-place sort) or a pointer to a new sorted array
also no global array usage

random pitch shifting and random time-stretching and randomly placed random length pauses during each word

how do i do this
class A{
A(){}
void foo();
};

//main
A a = A();
std::function f = std::bind(a.foo);