/dpt/ - Daily Programming Thread

What are you working on, Sup Forums?

Old thread:

Other urls found in this thread:

open-std.org/jtc1/sc22/WG14/www/docs/n1570.pdf
en.wikipedia.org/wiki/Shunting-yard_algorithm
twitter.com/AnonBabble

First for C.

Would there be any disadvantages for building GC support directly into the hardware?

I'm working on this trying to make the last button switch to next line every time clicked. Days text file contains days from Monday to Sunday but when I click the first time it says Sundays and second click does nothing. Any ideas?
from Tkinter import *

def Last(ReadLines):
Read = open('Days.txt', 'r')
for line in Read:
LastButton = Read
ReadLines.config(text=line)

def main():
root = Tk()
root.title("NKD")
root.geometry('500x230')
w1 = Label(root, text="Line")
w1.pack()
ReadLines = Label(root, text='', width=50)
ReadLines.pack()
LastButton = Button(root,text="Last", width=9, command=lambda:Last(ReadLines))
LastButton.pack(side=LEFT, padx=5, pady=5, anchor=SE)
root.mainloop()

if __name__ == '__main__':
main()

C with Classes > C++

c with templates > c with classes > c++

Best way to multiply two 64-bit integers into a 128-bit integer? Can I do the same trick as with imull?

Trying to learn data science / machine learning. I'm tired of being web dev drone. I want to move to something more challenging, rather than being stuck in a field which is full of substandard programmers.

Look at your for loop. Here, ReadLines.config(text=line), line will always be the last line of the textfile, in this case "Sunday".

You could probably leverage inline assembly in the mul instruction to do it

>Trying to learn data science / machine learning
you got a CS degree? or you just a pajeet trying to "level up"

Sure, but how? Does imulq %edx store EAX*EDX in EDX:EAX?

Sorry, I mean RAX and RDX of course.

The assignment to LastButton in Last looks fishy. You're assigning to a variable that you never read from.

I do have a CS degree. I studied a few AI modules in the university. Now I'm trying to remember what I learnt and catching up on what's new.

Back in university (3 years ago) I though cloud would be a much bigger thing.

>data science
It's just doing statistics by programming computers. Dull unless you understand and like the area that the input data is coming from.

Need some help guys. I'm doing this template clusterfuck:
template
struct matrix_range
{
using T = typename M::value_type;
constexpr matrix_range(M& matrix, const vector2i& position, const vector2i& dimensions) noexcept
: m(matrix), pos(position), dim(dimensions) { }

/* snip */

template
struct matrix : public matrix_range
{
using value_type = T;
constexpr matrix(std::size_t w, std::size_t h, T* data) noexcept
: matrix_range(*this, { 0, 0 }, { w, h }), p(data) { }

but the compiler says:
matrix.h(13,41): error : no type named 'value_type' in 'struct matrix'
using T = typename M::value_type;
^

I don't see the error here. There's obviously a value_type defined. Am I doing something wrong or what?

does your company sponsor masters programs? check it out bc they may

>Back in university (3 years ago) I though cloud would be a much bigger thing.
Cloud's pretty big, but was hyped a lot more. ALWAYS ignore the hype.

Someone explain hash collisions to me:
>>> set(range(3, 14, 2))
{3, 5, 7, 9, 11, 13}
>>> set(range(3, 13, 2))
{11, 9, 3, 5, 7}

Pure statistics might be dull, but they have very interesting applications (image processing, classification, text analysis, analytics etc.).

I don't really enjoy university live. I prefer to study things on my own or learning at work.

C stands for circlejerk

Last I checked, "data science" was being used to squeeze more profits out of vulnerable insurance elderly patients by calculating likelihood of death and simply cutting them off if the data trends say they're not worth spending more money on.

It's truly vile what they're doing.

that's not has collision mate. that just generates a list of number starting at 3 with increments of two which are less than 13 / 14. In second case, 11 is the last number in the list, so 13 is not in the result.

Simply run range(3, 14, 2) and range(3, 13, 2) to see it.

C stand for Circumference, e.g. circumference of your brain and cock. The better you are with C, the bigger your brain and thicker your package.

Data science is a tool and like all tools, it all depends on how it's used. IBM's Watson supposedly saves lives.

When hashing, you convert an arbitrary value to an integer. You can do that uniquely for any finite value, but that's really not very useful as the values get very large; everyone instead maps to small integers (32 bits often). That's going to end up with things mapping to the same thing, but getting Perfect Hashing (which doesn't do that) right is much harder than handling collisions. Since collisions are handled anyway, there's no shame in reducing the size of the hash value after computing it; the mod operator is a favorite way of doing that.

Practical code handles collisions by hanging other data structures (usually lists or trees) off the hash table entries; those use normal comparison. Things are kept efficient by occasionally growing the hash table when the number of values grows.

>very interesting applications
Yes, that was the point of what I said. The interesting bits are exactly the applications. Some people really like that. (Me, not so much.)

>so 13 is not in the result
I'm talking about the order of the set. The first is ordered, the second is second isn't. This has broken a function I made, as I relied on the order of integers in the set for set.pop().

sets are not ordered in python. use lists, if you want a defined order.

IBM also sold computers to the third reich so they they could extrapolate public records and target all the undesireables and ship them off to death camps.

I'm having a fucking brain fuck right now.

In C, say
int i=5,x=10,n;
n = i + i + x*++i;


n is coming out to be 70. I cannot wrap my head around it at fucking all.

First, ++i should become 6. Then 6*10 = 60, then 60 + 6 + 6 = 72.

But for some reason, i+i is happening before ++i. Why the fuck would addition happen first? I thought maybe it was a "left to right" error, but if I do
n = i + x*++i
Then ++i IS executed first, and I get a result of 66. What the actual fug?

don't think you can pull that off desu

that's undefined behaviour

How is order of operations undefined behavior?

That is undefined behaviour.
You can't have an operator with side effects (++) mixed with another use of of it.
If you compiled with -Wall (which you always should), you should have received a warning.

>Data science is a tool and like all tools, it all depends on how it's used
It's the same retarded argument gun owners make about knives. If it's a tool which is commonly misused, and those misuses wouldn't be an issue without it, then the fault is clearly in the tool itself.

>n = i + i + x*++i
altering a variables value and reusing it in the same expression is undefined behaviour

It's not the order of operations, it's the use of side effects on a callee without statement point.

Because you're changing the value of a variable mid equation.

Now that you say that, I do have that warning

thanks. I never really had that problem before.

C doesn't permit this kind of cheap hack, and rightfully so.

It's unspecified behaviour retards.

It's unspecified whether the other instances of i are from before or after the increment.

Order of evaluation is unspecified, but those sorts of uses are explicitly labelled as undefined.

int i = 1;
printf("%d %d %d %s\n", i++, i++, i++, "GO!!");

I'm trying without having T defined now but it doesn't make things any easier
constexpr auto& operator()(vector2i p) noexcept { return const_cast((*this)(p)); }

(that doesn't compile either btw)

Representing a float point number as a string in C. I'm afraid I'm doing Pajeet-tier code though.

you sure love to obfuscate your code

Can someone explain this?
Why does it print 3 2 1 ??

>float point number as a string
Then it's not a floating point number anymore.
Did you by any chance wanted to achieve something like fixed point arithmetic?

It's undefined behaviour.
Any result is completely meaningless.

scroll up

Apparently this compiler processes parameters right to left

Should they be? There are just multiple reasonable answers you could get, unlike undefined behaviour where there is no reasonable answer at all.

it don't

No, I want to do it to write a JSON file.

If I start trying to access an uninitialized pointer and incrementing it by a random value, the program might segfault, or it might not.

I can't predict my program will run as intended every time.
That's undefined behavior.

Yes. Those sorts of statements are dubious at best, and I have no issue with them being explicitly forbidden.
>There are just multiple reasonable answers you could get
Considering how wildly different they may be, there is just no reasonable way to write a portable program that takes these into account.
It's just like signed integer overflow. INT_MAX+1 could be INT_MIN or -0. These are REALLY different answers.

I'm not saying it's okay to rely on any one possibility just because that's what your compiler is doing, but what does the specification really say? Is the compiler free to make demons fly out of your nose in this scenario?

the c compiler is free to make any assumptions that aren't explicitly covered in the standard

I looked it up before:
open-std.org/jtc1/sc22/WG14/www/docs/n1570.pdf
Page 76
6.5 Expressions
>If a side effect on a scalar object is unsequenced relative to either a different side effect
>on the same scalar object or a value computation using the value of the same scalar
>object, the behavior is undefined. If there are multiple allowable orderings of the
>subexpressions of an expression, the behavior is undefined if such an unsequenced side
>effect occurs in any of the orderings. 84)
Footnote 84
>This paragraph renders undefined statement expressions such as
i = ++i + 1;
a[i++] = i;
>while allowing
i = i + 1;
a[i] = i;

That's an irrelevant tautology.

Okay, I'm just mixing it up with argument evaluation order which is unspecified.

Here, Sup Forums. I found this and thought of you. Had to kill the quality to get the file size down, though.

Here's a challenge: write a program that takes an image input, and has a boolean output. The output will signal whether the input was a Twitter post screencap. Maybe you can cleanse the cancer off this website.

>AT&T syntax
Disgusting
Anyway, look at volume 2 of the Intel Developers Manual, it describes all of the x86 instructions in full detail. Once you run imul, you can probably move the contents of RDX:RAX into two different variables and print the contents of them from there to see if it worked correctly. Can probably even create a struct to hold and work with the 128-bit variable afterwords.

>That's an irrelevant tautology.

Incorrect.

>That's an irrelevant tautology.
it's always people who are uninformed who think they know shit. printf("%d", i++); is undefined

>printf("%d", i++);
I'm sure you meant to put another i++ in there.
That's just a normal printf.

>printf("%d", i++); is undefined

I want that poster on my wall

Does ++ and -- even need to exist if its going to be such a cluster fuck?

How do I convert any given infix expression to an s-expression?

Eg: (1 + 2 * 3) -> (+ 1 (* 2 3))

Visual Studio Two Thousand Seventeen Er Ce Enterprise Edition.

Operator precedence

Many languages don't have them cause they're shit.

They seem useful enough, but I understand why people might not want them.
But the undefined behaviour actually extends beyond that, as it also includes the assignment operators, and you certainly wouldn't get rid of those.

It's only a clusterfuck because of baboons not knowing how to properly use them.

Please elaborate?

* has higher precedence than + so you know that it's (+ 1 (* 2 3)) and not (* (+ 1 2) 3).

Look up the shit to write a simple recursive decent parser for arithmetic expressions.
Then just spit out the polish notation when you're done.

en.wikipedia.org/wiki/Shunting-yard_algorithm

that one is easy to modify to prefix notation

>mz-700
ik heb nog zo'n ding ergens
nooit geweten dat die basic had.

Is it possible to use multiple threads in an event based program?

So I create an object, call a connect() function that hooks up my events, then call object.run(). Can I set it up in a way where objects in my events aren't considered to be part of the thread that calls object.run()? idk if this is a stupid question or not

make the event dispatcher spawn more threads.

Sounds like a recipe for disaster.

make the event dispatcher spawn more threads.
Sounds like a recipe for disaster.

Souds like a recipe to spawn more threads

make the recipe spawn more disaster threads.

Today, I finally learned how to draw a concave polygon in OpenGL. I feel fulfilled.

mkea the ntvee dspcaierth apswn (more | oemr) erhtdsa.
suodns eilk a (pireec | eripce) rfo dstaiesr.

dont ever le change Sup Forums xD

my leles are in orbit

upvoted xD

What objectively sounds like a recipe for gitting really gud?

git gud

git clone gud.git

Started learning Visual Basic a few days ago. Its a program that calculates the price of a pizza including a discount if you buy a lot of pizzas. Am a computer engineer yet Sup Forums?

Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
Dim numPizza As Integer
Dim totalCost As Double

numPizza = CInt(txtPizza.Text)

If (numPizza >= 3) Then
totalCost = (10.5 * numPizza)
ElseIf (numPizza = 2) Then
totalCost = 23.5
ElseIf (numPizza = 1) Then
totalCost = 10.5
End If

If (totalCost > 40) And (totalCost < 59) Then
totalCost = (totalCost * 0.95)
ElseIf (totalCost > 60) Then
totalCost = (totalCost * 0.9)
End If

txtCost.Text = "Your total cost is " & "$" & (totalCost)

learn all the shit your language can do.
Start making programs until you get to know how to solve almost every problem.
Probably won't work but my tiny brain can't think of anything better.

Was going to try to make a GUI text editor with FLTK, but I realized that they literally have a #include file with a text-editor implementation

I'm going to try to move to ncurses to focus more on the text-parts... Quick question: I downloaded ncurses 6.0 and I can't seem to run the test programs

When I run them (after
./configure
make
I get the folowing error:
Error opening terminal: xterm.

wtf?

i wish i could be this good

How can I generate an image pixel-by-pixel then display it using Swing + AWT?
I can't find anything clear in the documention for creating the image, I assume displaying is easy though.