/dpt/ - Daily Programming Thread

Knuth edition

What are you working on, Sup Forums?

Old thread:

Other urls found in this thread:

duma.sourceforge.net/
stackoverflow.com/questions/419163/what-does-if-name-main-do
jeffknupp.com/blog/2016/03/07/python-with-context-managers/
book.pythontips.com/en/latest/context_managers.html
en.wikibooks.org/wiki/Python_Programming/Context_Managers
stackoverflow.com/questions/3693771/trying-to-understand-python-with-statement-and-context-managers
twitter.com/NSFWRedditVideo

>set 4th and 5th spockets to value 9
>carry doesn't propagate even with 10 cycles of drive shaft
Can babbage cucks explain themselves?

immutability by default is as retarded as laziness by default

while(1) {
printf("Thanks for not using an anime image!\n");
}

>while(1)

>having problem understanding that 0 is false and everything else is true
retards like you shouldn't program

>What are you working on, Sup Forums?
shitposting in third /dailypetardthread/ thread

No, you just think so because your logic is dictated by largely mutable habits because that's the norm. Thinking in immutability and purity actually make so much more sense it's crazy. The most important up-front advantage is your code is already much less bug-prone. And most of them will just be you making logic mistakes.

I wrote a json parser that looks at all mentions of the top 250 coins on biz.

To be honest, I have not had any formal training in coding, and I think that my code will show that. I realize there is likely a HUGE amount of inefficiencies, but this is what I just completed today. Eventually I will have it do 100% of the work of buying/selling but baby steps, right?

import requests
from collections import Counter

def symbols():
main_api = "api.coinmarketcap.com/v1/ticker/?limit=250"
json_data = requests.get(main_api).json()
symbols =[]
for x in range(0, len(json_data)):
symbols.append(json_data[x]['symbol'])
return symbols

def comgetter(thread,symbols):
main_api = " 0:
return coms

def threadnumbers():
main_api = "

const was mistake

And how long have you been, "programming", sir?

>having problem understanding the negative long-term project effects of conflating booleans and integers
hope they don't let you anywhere near code that matters

repost
I suppose your point is that users abuse scripting language for building large scale applications. I agree on that. You should use the right tool for the job. If your script is more than a single file, you should really consider a more robust language with static types. However, I don't see the problem for users to write a script in Python that scrapers a Tumblr page.

#define true 1
#defin false 0

Was it that hard, you big fucking crybaby?

>Thinking in immutability and purity actually make so much more sense it's crazy.
>jumping through hoops to define cyclical DSs actually makes so much more sense it's crazy
something's crazy here allright
captcha: ooh, got a fancy one. Sig, I'll miss calle when the less-shitty captcha is over in March :\

constants in while conditions is a mistake
Use for (;;)

*industry voice*
does the job, ship it(tm)

>However, I don't see the problem for users to write a script in Python that scrapers a Tumblr page.

That's purely a convenience issue. If a better and type-safe language can be just as fast to write and safer, than why not?
>Just never look inside...
That's why we are stuck in the hell we are user. That's a very poisonous mentality.

>;;
dumb sepples fag

>does PHP-level type casting fuckery
>that bug was one in a million, doc, nobody's perfect
ah, kids
that's why we need mentorship before review-less commit access

But I'm worried that it doesn't do the job well or fast enough. Realistically, I am only going to run this code once every 10-15mins to check up on /biz/ because it doesn't move but so fast.

And, I want to know, do you find the code terrible personally even though 'industry voice' says ship it?

>for (;;)
>that's the better alternative
c-family fags will actually defend this

Why is /dpt/ so easy to troll?

oh, don't take that post too seriously, was just semi-shitposting
lemme take a look
have you measured time/bandwidth/etc metrics you're worried about and detected that you do indeed need to improve them?

The better question is why don't you just stay on Sup Forums or /s4s/ or /bant/ or the other shitposting boards?

people feel incredibly insecure about their language/technology choices because it's a big part of their lives.

>That's purely a convenience issue. If a better and type-safe language can be just as fast to write and safer, than why not?
Some people aren't very bright and will never comprehend a type-safe language. For those people we have Python.

That's K&R style you dumb faggot.

You're wrong. Functional programming is different, but it won't guarantee fewer bugs. Better design and testing > new tools.

I love how you post a while loop that has no way to terminate, and with a value that has no stated purpose or meaning, yet everyone else is the "retard" and "crybaby"

Please kys

I'm mostly new to Sup Forums but my guess is that there are a large amount of nuances in programming, and this is the only outlet where pro/g/rammers can bitch at each other for whatever nuance they believe is 'truth'

I have many things to duckduck, as I didn't even think about using a timer to measure how long it takes each part of my code to run. That being said though, I would have to hit the duckduck even harder even if I did want to speed it up hahaha.

Those people shouldn't even be in programming in the first place. I don't understand why people think non-programmers belong in programming.Why are we one of the few stem professions that think so backwards? This is unheard of in pretty much every other profession.

cuz it's full of autists with the emotional and debate maturity of an 8 year old
those autists can't emotionally attach to people that well, so they point their borderline religious attachment to objects, e.g. computer languages, approaches, hardware, vendors
the attachment+maturity means they're hilariously easy to trigger, and one would be feeling sorry for them, if it weren't for their own good if at least someone would challenge their immaturity. Cuz god knows nobody normal got time for dat at home/school/work

pssh I won't, while(true) is while(true)

>no mutability outside of functions
>strict purity and no uncontrolled side-effects

>not guaranteeing less bugs

alright m8

>all that self-righteousness butthurt
Is anyone expected to believe you're not one of the people you're complaining about?

no worries mate, just a word of caution since it looks like you're new to chan-tardation: there's posters that are trying to help, and there's others that are just here to shitpost (and those that do double duty, such as yours truly) - so if somebody's being a dick here - don't take it seriously, helps grow a thick skin for when it matters too.

Is there any syntax in C to get a certain part of a string? For example, I have the following string defined:
const char values[5] = "0a0f"

and want to compare just the first two chars, 0a, against another string. What's the best way to do this?

Not as a profession, but as hobby, for convenience sake or out of curiosity.
There are a lot of hobby car mechanics out there who can do basic chores like ricing their car or fixing broken parts. Do you consider that to be a bad thing?

is anyone making the claim that I'm not?
I'm not tho, ur mum is :^)

Because fucking money.
I went to IBM last month, and they were so fucking desperate to recruit people, they didn't even talk me about programming : only about muh afterwork parties, muh funniest company. One of the biggest pajeets I know of got his intership there, and 2 others from my class, which are probably worth less than out-sourced pajeets got a job there.
Funniest is that IBM knows very well they're pajeets, and trains them.

>compare first characters
>compare second characters
>done

strcmp

>I'm not tho, ur mum is :^)
>ur
>tho
>cuz
>ur mum
>;^)
>autists with the emotional and debate maturity of an 8 year old
>other people, not me

Worry not I've worked enough cuckstomer service to know that I don't take anything personally. Thank you though, and while the chan-tardation seems rather rampant on all boards, I am overjoyed by the free expression of those people -- shitposting and helping alike.

I've got other working project code, would anyone care to see it, or would they prefer to complain at one another?

Also, I have yet to functionally understand why I would want to use classes over just listing a bunch of defined functions as I please.

>What's the best way to do this?
as is the case with most things C, the usual answer applies
>get bent, shuffle your own bytes
>oh, but we've made this convenience function that's terribly insecure and trivial to shoot yourself in the foot with so we're totally not portable assembly anymore

>Do you consider that to be a bad thing?
Completely two different things as I don't use what they work on, and they ultimately don't influence what is being used industry-wise.

I know what strcmp is, that's what I'm using.

That's probably what I'll have to end up using, was hoping there was a nicer way to do it.

That's very helpful, thanks.

performance art is enjoyable, what can I say?

In Python, you should use the keyword "and" instead of "&". Also, if you want to check if there's elements on a list on an if, instead of "len(x)" do "len(x) > 0".

In the software i'm developing you will have to pay to minimize the window.

deal with it.

Your GUI is shit

isn't & bitwise too?

*pirates a cracked version*

>while the chan-tardation seems rather rampant on all boards, I am overjoyed by the free expression of those people -- shitposting and helping alike.
absolutely, it's a mixed treasure that should not be allowed to go extinct
>I've got other working project code, would anyone care to see it, or would they prefer to complain at one another?
chuck it in, there's a >0% chance someone will take a look at it and at the very least pretend-give you the "dickiest coworker ever" code review experience
>Also, I have yet to functionally understand why I would want to use classes over just listing a bunch of defined functions as I please.
now this sounds interesting, can you throw an example where others use classes and you think it's useless? Cuz they're not necessary in plenty of cases, but in plenty others they do make sense, as data organization at the very least

> the absolute state of proprietary software

>That's very helpful, thanks.
we aim to please

Yes, if you're doing bitwise arithmetic you should use &. But for boolean expressions like those in the ifs "and" should be used instead.

What's the name of that one weird looking loop unroll that was named after the guy at Industrial Light & Magic who came up with it?

glorious

Duff's device.

>print(my_dick)
this one gets my updoot

Device of Duff

I just discovered Dlang and i think im in love.
Is it as good as it seems or will it stab me in the back and feed me to the sharks when i look away?

There's literally nothing wrong with shitposting.

DD

go back to rabbit

Companies want to maximize their profit, so those hobby programmers get hired. As a result of a large quantity of substandard programmers, tooling is made to cater those programmers into making their life as easy as possible. This is why progression is so slow.
Don't blame the hobby programmers, blame the companies.

Actually I just noticed bitwise & is correct, he's doing between two sets to get the intersection.

>Google a Python module or function name
>it always returns the link to the Python 2 documentation
>Python 3 docs nowhere to be found on the first page

Yeah, that was it. Thanks.

oh shit you're right. Forget what I said then.

Just change the 2 in the URL to a 3

>[[[0] for x in range(15)] for x in range(10)]
>instead of Array.ofDim(15,10)
pythonfags will defend this

>le ebin go bak to plebbit meem
good job protecting us against those filthy plebs, comrade

based user, thanks. Still one extra step because of retarded Google. I thought having their botnet means they tailor the search results to me.

>There's literally nothing wrong with shitposting.
ironically this

do you have a better way to do it?

share

[[0]*15]*10
6/10 got me to respond

I've been spoiled by the PostgreSQL documentation, but Google will still return a random version's result.

>[[0]*15]*10

it's not the same retard

Ok i'll post my take on looking at exchange json data, organizing it into a file as an array to run some fancy math on it later with matplotlib and various numpy functions.


All of my programs deal with data, yet I don't understand how I could further organize anything with a class. It's not that I think it's useless, I just don't think I have the need to use classes in my functions yet. Granted, chances are there are better ways to do the functions I want, and i'll bet it's with classes.

thank you for your input, and verifying that I was doing it right.

is Array.ofDim(15,10) python? Or are you remarking on how python is not C?

using python stdlib? no clue
less retarded language? Literally Array.ofDim(15,10)

It wasn't letting me post it with the url in the program for some reason, so I put in some ='s to beat the auto pruner.

import requests
import numpy as np
def getMarketSummary(coin):
main_api = 'h=tt=ps=://bitt=rex.c=om/api/v1.=1/public/getmarketsum=mary?market=btc-'+coin
json_data = requests.get(main_api).json()
string = json_data['result'][0]['TimeStamp']
things= re.findall('\d+',string)
delimiter = ''
timestamp = delimiter.join(things)
outfo = np.array([[(json_data['result'][0]['Bid'])],
[(json_data['result'][0]['Ask'])],
[(json_data['result'][0]['Volume'])],
[(json_data['result'][0]['OpenBuyOrders'])],
[(json_data['result'][0]['OpenSellOrders'])],
[(json_data['result'][0]['Last'])],
[timestamp[:14]]], float)
file = open(coin+".txt","a")
file.write("[")
for i in range(1,8):
file.write("["+str(outfo[i-1][0])+"]")
file.write("] ")
#names = ["Bid", "Ask", "Volume", "OpenBuyOrders", "OpenSellOrders", "Last". "TimeStamp]

getMarketSummaries()

>is Array.ofDim(15,10) python? Or are you remarking on how python is not ?
2nd, standard low-effort shitpost to try and catch some easily offended flies or (less likely) friendly bantz

People rag on it for its GC, but I think it's fine. If I had to choose a high-level language I'd pick it over Java or C#

>doesn't check if the file exists
>repeating json_data['result'][0] 6 times
>doesn't import re
into le trash

Please, enlighten me then! I only did it that way because it's all my tiny brainlet self could must to actually function. How else could I not repeat that section of json_data but still access the key elements I want?

I'll presume it's the friendly bantz, as I will take any critique with a smile.

I remember once trying to understand how to implement re but it takes me multiple read throughs to really grasp how to use it.

As for the checking if the file exists, my understanding is that if the file does not exist, using the 'a' mode on it will create it.

i would re write other parts of the code but ca't be arsed

How do I find any unused pointers? I'm on Windows, so I can't use Valgrind.

Thank you, In my program I have the import re, just forgot to put in the post. As for the with open() as file: is this just to handle the case in which there is not the text file already made? Why do you end it with the __name__ section stuff? I don't have any programs that use __main__ yet, as I believe that is part of the 'classes' concept I haven't yet felt the need to have? Does making /something/ a class inherently make it better, or is it just common convention among institutional learning for programming?

duma.sourceforge.net/

stackoverflow.com/questions/419163/what-does-if-name-main-do

great example, I think
well, in `outfo`, you're using np.array as a record type (implemented in various languages as plain-ass struct, class, dict, bag, etc)
and if I'm mind-interpreting this correctly (highly unlikely), you're dumping the stuff into a CSV-like text format.
in python there is more overhead than I find necessary for that simple record type, and there's no static typing with its advantages to entice us into creating the type.
So yeah, I wouldn't bother for that short piece of code.
However, if you're going to be doing more operations on these records (and even more so if you had static typing to sweeten the deal), it might start making sense to organize stuff a bit more, e.g. named tuples, a class or something.

Just for comparison's sake, in Scala I might do
case class Coin(bid: Double, ask: Double, volume: Double, openBuyOrders: Int, openSellOrders: Int)

which would allow me to write more readable code for e.g.
val openBuyOrdersSum = coins.map{_.openBuyOrders}.sum

but it depends on whether you have enough need to outweigh the overhead of creating the type.

Then again, given that you'll be running numpy stuff on it, it's probably more convenient to keep it in the np.array.
Right tool for the job, and all that.
>great example, I think
on second thought, yeah probably not - I'm too clueless w/ mathplotlib and numpy to offer any useful advice on whether you'd benefit from a class here. But my gut feeling is 'nah' - specifically for the code that you've shown.

>If I had to choose a high-level language I'd pick it over Java or C#
oh, those are totally different use cases, IMHO. Plenty of cases where (given greenfield dev, equal capability in both langs, etc) Python makes more sense, and vice versa.
Horses for courses

I approve of this post

If I implement hashtable, should it store just pointers or should internal buffer have room for the fixed size object?
struct slot {
void *data;
}
// or
#define slot(type) struct { type data; }

Storing the data to hashtable takes more memory if it never gets fully filled.
But the data is likely close so it would be more cache friendly if you need to loop over every element of the table?

use templates :^)

Fuck off Stroutrup, nobody likes you.

typedef struct {
char name[64];
type_t type;
flag_t flag;
value_t value;
} element_t;

typedef struct {
char name[64];
char func[64];
element_t *elements;
element_t **next, **last;
int size;
} hashtable_t;

>As for the with open() as file: is this just to handle the case in which there is not the text file already made?
spoon-feeding you:
handles any exception that might happen, makes sure to close the file properly
random crap:
jeffknupp.com/blog/2016/03/07/python-with-context-managers/
book.pythontips.com/en/latest/context_managers.html (no need to read 25.1 and onward for now)
en.wikibooks.org/wiki/Python_Programming/Context_Managers
stackoverflow.com/questions/3693771/trying-to-understand-python-with-statement-and-context-managers
>Why do you end it with the __name__ section stuff?
see other poster
>I don't have any programs that use __main__ yet, as I believe that is part of the 'classes' concept I haven't yet felt the need to have?

not really, more to do with modules
each shit.py file is also a module. Thus you can import it. Everything that's outside a function gets run when the module is imported. To prevent somebody from firing the missiles when they only wanted to import your module for later use, you put your "main" code in a function, and throw in that __name__ check. When you do `python shit.py`, python sets __name__ to '__main__', thus your code runs. When the unlucky fuck imports your module, __name__ is not main, thus your request-making (information-leaking, missile-firing, etc) code doesn't run until they choose to.
>Does making /something/ a class inherently make it better
nope, depends on the situation
>or is it just common convention among institutional learning for programming?
eh, kind of a mixed bag
Software Engineering's giving kids OOP to give them a fighting chance if thrown in an OOP codebase (most line-of-business software, which is 90% of SE jobs out there)
Plenty of Unis don't only give you OOP though - they might give you FP, logic programming and others to give you a better awareness of the landscape.