/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Previous thread:

Other urls found in this thread:

coursera.org/learn/machine-learning
ghostbin.com/paste/6hp6z
asciitable.com/
en.cppreference.com/w/cpp/string/basic_string/getline
c-faq.com/stdio/stdinflush2.html
pastebin.com/ZVb3vXCT
en.wikipedia.org/wiki/Two's_complement
twitter.com/NSFWRedditGif

First for D

congrats OP for shitposting and ruining the thread

>bounded refinement types

>thread already off to a shit start
once again, OP does not fail to disappoint.

i think it depends. for applications it’s almost an experimental science. i would say step through something like the standard

coursera.org/learn/machine-learning

and see if that makes sense. he runs through linear algebra and how to use matlab/octave, but he also tries to give some heuristics for when things don’t work

Just released v0.8 of my C++ webserver library. I think all I have left is some code cleanup and a helper iterator for chunked transfer encoding, then it'll be ready for a final v1.0 release.

>exceptions
It takes one word!

>3 level deep try/catch blocks
Jesus

Hey man it was either exceptions or nullable pointers. The overhead of parsing, marshalling, and waiting on network overshadow performance concerns of C++ exceptions.

That's just for improved messages in the example code ("client timed out" vs. "timed out waiting for connection" for example)

>muh Palestinian m-mythological character
>r-reeeeeeee
Fuck off.

Judean you illiterate retard

In C,
Let there be an array count[5],
and in the program, some function does ++count[7]
It is safe, right? I didn't want to count that anyway. Will this cause any issues? count[7] doesn't exist so that will just be ignored?

That is undefined behaviour. It could be ignored, it could crash your program, it could do something even more sinister.

user I...

That's not how it works. count[7] could refer to a memory location that you don't have read or write access to. And what if count is an array on the stack? count[7] could potentially modify other variables.
Basically, this:

Wow

>Let there be an array
Are you god or something?

You're accessing something you shouldn't be. There's a chance nothing will happen and your program will proceed normally and your instruction will be *apparently* ignored (though whatever is in &count+7 will be incremented), but that's highly, highly dangerous.

Just for curiosity, what's the context here?

I'm going to start reading through "Programming -
Principles and Practice Using C++". What IDE should I be using?

notepad

C++ is garbage. Why the fuck do you WONDERFUL PEOPLE keep using it?

reeee

You realize Newton was deeply religious right?

thanks!


In the program i posted in last thread ( ghostbin.com/paste/6hp6z )
I wondered what would happen if user inputs some char like ~. It would cause c - 'a' to be above 26.
So should I have an if condition to check if it is within bounds?

asciitable.com/
You should probably check, yes.

I've read through the first 8 chapters of that book and I didn't like it desu.

Mostly for performance reasons

...

Surprise surprise, you should try multiple out and see what you like, and don't like, about each. I personally have a free subscription for CLion and have never felt the need to switch to anything else, but I know most people won't have access to it. CodeBlocks is popular, as are the extensions for Eclipse and NetBeans. I personally hate eclipse from Java use and would recommend the other two over it, but you should just simply try all 3 and see what you like.

Or you could simply pick the best one: vs

I'm going to try to ask this one more time since last time I didn't get any help

I'm trying to prevent overflow when I enter names longer than the string can hold, but when I press enter it skips the next input and goes into the next point of the program. How do I stop that from happening?

actually forget what I said I forgot I did it with char arrays, but the issue's still the same either way I'm sure

>C++
>IDE
Sublime 3 (or your favorite TE) + CMake

Use std::string instead?

the characters are buffered in stdin, it is a terminal thing if i recall correctly. you want to clear that buffer once your array is full. how?
i have no idea, sorry.

en.cppreference.com/w/cpp/string/basic_string/getline

btw, about the ide, use the command line + notepad to learn how it works, then move to visual studio or clion

relevant c-faq.com/stdio/stdinflush2.html

I'm trying not to use anything that isn't covered by that point in the book and honesty I can't remember if I tried strings or not, but I'm going to get it a crack at some point later on.

I have another quick question. Can someone explain to me why this is causing an infinite loop? If I use T < 127 it does exactly what I want it to use, which is display the ASCII starting from 1. But for some reason if I do T

try defining T as unsigned char

Overflow. Char is only 4 bits, once you hit 127 it'll increment once more, but then wrap around back to 0, causing it to be

> Char is only 4 bits
/dpt/ - Daily Programming Thread

Source? Every genius intellectual comes to the conclusion that religion is a tool for oppression and mass control required to keep the lower classes down; that's the reason why I go preaching house to house on weekends even though I know that gods are silly as fuck. If you really believe that X believed in gods because he proselytized, you're the lowest common denominator of sheep.

I confused myself with an int being 4 bytes.
It's still probably wrapping around in some obtuse fashion, maybe as a signed char?

There's no way to do it safely using only what you're using there. There's a couple of safe ways, including using the std::getline function from or setting the max extraction width, but really formatted IO on streams is part of the worst of the standard library.

kek

>int being 4 bytes.
/dpt/ - Daily Programming Thread

Closer to the mark. char is actually a signed char. a char has 8 bits => an integral range of [-128, 127]. Thus, a signed char is always

>T = 0
>check condition
>do stuff
>increment
...
>T = 127 (01111111)
>check condition
>do stuff
>increment
>T = -128 (10000000)
>check condition

It is overflow. char can hold values between -128 and 127. With the condition T

what editor is that

plain char being signed or unsigned is implementation defined.

Yeah sorry it's for intelligent students.

So it's implementation defined behaviour, not undefined behaviour. Big whoop.

>char is actually a signed char
That's implementation defined, if you want a signed char you need the signed keyword.

If anyone liked day 23 of Advent of Code, here's a bonus puzzle with some more assembly code.

pastebin.com/ZVb3vXCT

If I didn't fuck up somewhere, the correct answer is 67155.

public static int UppingTheAnte(bool p2)
{
int b = 86, c = b, f = 17;
int h = (int)Math.Pow(2, f) - 1;
if (p2) {
int a = 10;
for (int i = 0; i < a; i++) {
b += c;
c += b;
}
}
f = 0;
for (int d = 1; d

nice try, bjarne. I won't give you money

Sublime Text 3 with a custom color scheme and some custom (ie not broken) language definitions.

Is the runtime complexity of traversing a nxn matrix Θ(n^2) or Θ(n)

>char is 8 bit
/dpt/

Θ(n^2)

Θ(n^2) = Ω(n^2) = O(n^2) in this case

I just started working at mid-size gaming studio to work on their engine.

The lead dev forbids most usage of preprocessor directives because according to him it "slows compilation times" and thus workflow. Day one and I want to leave.

Θ(f(n)) ⇒ Ω(f(n)) Λ O(f(n))

>slows compilation times
wtf

who cares about compilation times

I'm looking to get into basic GUI development in python. Any recommendations on what library to use? I've been looking at Tkinter, PyQT or wxPython. I have zero prior experience in GUI dev.

>math.pow(2, f)
This is your average java programmer /dpt/

Jesus

I meant for his program. And on most machines, it's a signed char. Of course, you correct since signedness of the char type is not fixed by the standard. Should have clarified.

people writing sepples because the compilation times escalate quickly

eh I just graduated, I don't need to remember this shit any more
¯\_(ツ)_/¯

why would you want defines when you have constexpr and enums?

Θ basically means it grows at the same rate beyond a certain point, or is only different by a constant factor
i think

basically Θ is Ω and O

Not him
Why is -128 represented like that?

What if I said the dimensions were mxm

Is it still Θ(n^2)?

> count[7] doesn't exist so that will just be ignored?
No. C will do just about any old fucking thing if you tell it to, particularly with arrays. You'll basically be incrementing some other chunk of memory.

"Let there be" is pretty standard talk for mathematicians and proofs

how do you do conditional compilation?
he is right kinda, but didn't explain it to you. if you include the same file many times, the compiler still needs to check it for pragma once or guard, so it opens it every time, which is really slow, so technically you are better off putting a class Whatever; at the top of the file, and yeah that's really stupid

I'm not sure I'm getting what you mean
Okay that makes sense. I guess I didn't realized it overflowed because the ASCII goes up to 255. Didn't even realize char was signed or unsigned
This works

en.wikipedia.org/wiki/Two's_complement

it's Θ(m^2)

Thanks

>Didn't even realize char was signed or unsigned
Note that I was partially wrong - whether char is signed or unsigned is an implementation detail. Usually it will be signed, like in this case.

zero is a number also, and it is within the positive range. a signed char reserves the first bit to tell if a number is negative or positive.

Really its O(k) where k is the numbr of elements in the matrix. In general k = m*n, and in your case m=n so O(k) = O(m*n) = O(n^2).

It is actually O(1) since you only work on a single matrix

I agree with both of these, but it just seems a little over the top. I guess I'm also just sour because he's a holier-than-thou prick. He's smart, but goes out of his way to act extra smart. Idk, fun job but that guys a douche.

Can somebody please fucking explain theta(n) to me? I understand O(n) is "it's not gunna run much slower than this", and Omega(n) is "It's not gunna run any faster than this", but I don't...theta?
My korean professor in my last algo class had terrible english and basically just scrawled a shitload of pseudocode down so I never got the concept

kys

it's going to run as fast as this

The logic is just as stupid as .
>ackshiually it's *this* if you redefine things

Big theta also ignores lower order terms (and so does big o and big omega).

ah

Nah, he is objectivelt wrong. Never heard of macros becoming cause of slow compilations. It is always templates or unnecessary includes

I looked it up as a refresher. O() = upper bound, Ω() = lower bound, Θ() is exact bound (when O() ≡ Θ()). Then there's o(), which I never learned or if I did it's not important :^)

>I'm not sure I'm getting what you mean
You can tell the stream (std::cin) to only extract up to n characters even if it hasn't found a newline yet. Or, you can use the function I linked, which takes the stream and the string as arguments. But it doesn't look like whatever resource you're using has introduced either, and if I know my C++ teaching material they probably won't and leave it up to you to check the standard library documentation.

f(n) = Θ(g(n)) iff f(n) = O(g(n)) and f(n) = Omega(g(n))

Basically it gives you the tightest bound

I didn't redefine anything, I only gave him a (slightly) broader view of what is actually going on and demonstrated that you can do simple algebraic manipulations.

Some algorithms can give better or worse asymptotic complexity depending on the structure of the inputs (e.g. certain sorts become O(n) if the list is already sorted). Big-O is used for upper bound, big-Omega for lower bound, and big-Theta when the bounds are "tight", meaning that lower and upper bounds are the same.

>tfw mixed up ≡ and =
model CS student here

Why not make the first bit mean - or + and leave the rest the same?
128 is 01111111 so why not make -128
11111111? If you want to change sign just flip the first bit, none of the two complement shenanigans

Because now you have two non-equal definitions of 0. No one wants to deal with that.

>Why not make the first bit mean - or + and leave the rest the same?
Because then you have two zeroes, 00000000 and 10000000. Operations need to be specialized to handle it. Two's complement has only one zero and, as a consequence, operations are simpler.

Because it requires much simpler hardware/software to support twos complement