/dpt/ - daily programming thread

Web devs are retards edition

Discuss the failures of MongoDB and whatever shitty JS framework that is the flavour of the month

Old:

Other urls found in this thread:

youtube.com/watch?v=F3ntGDm6hOs
pastebin.com/epvS6mca
gist.github.com/rygorous/c6831e60f5366569d2e9
sarahmei.com/blog/2013/11/11/why-you-should-never-use-mongodb/
robmiles.com/c-yellow-book/
amazon.com/C-Players-Guide-2nd/dp/0985580127/ref=sr_1_1?ie=UTF8&qid=1470232979&sr=8-1&keywords=c players guide
twitter.com/NSFWRedditImage

>tfw want to learn programming
>start with Python
>get bored after learning basics
I guess programming is not for me

> not using C

degenerate

Third for C++

>learning Python as your first programming language
Learn a better language and learn more than just the basics

Now put the average internet speed on the graph.

Why is The Elements of Programming Style out of print when The C Programming Language is still in print? I really want to read it but it doesn't seem as readily accessible as K&R is where I live.

So, the code guidelines of my collab asks me to keep the line length under 80 characters. It's a little strict, but it's alright, when I'm coding in C I do that anyway. However in Python that seems a little difficult as you can't add line breaks everywhere (just between arguments for example) which drives me fucking insane desu. So how the hell do I format python code?

Had similar problem with coworker last week.
We compromised on increasing the limit to 140 (I still think its too little).

But the code guidelines of my collab asks me to keep the line length under 80 characters. It's a little strict, but it's alright, when I'm coding in C I do that anyway. However in Python that seems a little difficult as you can't add line breaks everywhere (just between arguments for example) which drives me fucking insane desu. So how the hell do I format python code?

If web page sizes increase proportionally to the internet speed, you have gained nothing.

Not an excuse

There's people with slower connections, data caps and you are also wasting server resources for no good reason except incompetence and laziness

boring thread
op is retard

Python is shit desu. I tried to learn programming through Python a few times and it never clicked for me. Then I learned C and fell in love.

youtube.com/watch?v=F3ntGDm6hOs is pretty good. The rest of the channel has like 500+ hours of programming a game in C from scratch.

Reminder thag c# is the best beginner language

>Clear syntax
>C-based
>Has All oop principes
>Is type safe
>Excellent IDE (inb4 muh bloat)
>Intellisense
>Has a lot of Resources to learn from
>Welk documented
>Can use in unity, xna, and other engines.

Good. If you don't find programming interesting, you should probably look into a different career path. Maybe civil engineering or graphic design may be more your style.

Trips confirm.

Speaking of which, what's the easiest way to do pic related there?

You add brackets. Like
if (illustration['component_id'] is not None and
illustration['component_id'] not in visited[illustration['type_id']]['components'] and
illustration['component_id'] != 0):

Agreed.

What do you mean? As in setting up the objects or what?

Beginner. Made a base converter in Python.
pastebin.com/epvS6mca
I feel like I've been calling myself a beginner for too long but this thing took me three days to make and it was labelled "easy" on the Pro/g/ramming Challenges.
Definitely not as easy as listing prime numbers.

Try getting a book you can leaf through while lying in bed.
Not a PDF file. A real thing with paper between covers.
That's what I did: Java for Dummies, C++ programming in easy steps, Beginners guide to Python, etc.
Think I overshot my abilities when I bought SICP, though...

>Then I learned C and fell in love.
This so much. Programming in python feels like a chore, nothing makes fucking sense, everything just works either way, it gets super slow and every abstraction comes at ridiculous costs. You never know what actually happens under the hood. With C you get some intuition what the best way of doing things is, with Python you just have no fucking clue whether some object is really what it looks like or really some blown up data structure that triggers twenty CPU operations and ten memory accesses when you are just looking at it. To me that's no fun at all.

I don't think you should use an IDE when you start to learn programming. You understand much more what's actually going on if you do everything yourself.

>just have no fucking clue whether some object is really what it looks like or really some blown up data structure that triggers twenty CPU operations and ten memory accesses when you are just looking at it
Alt+F12 on the object, jesus

Is it true that Haskell can't give you a straight pseudorandom integer like random (1, 10) or whatever?

I googled it really quick and all the answers were talking about monads and I/O and shit

If that's the case, then whew: meme language 100%

I don't think you should use anything higher level than Assembly when you start programming. You understand much more what's actually going on if you do everything yourself.

An IDE can actually give you more information as to what's happening, you mongoloid.

>Just use some function in some unknown IDE I'm using, jesus

No, I want to make a database like pic-related. Two different lists whose members are associated on a 3rd list with additional data, like a quantity number.
I've tried to do this with ordinary lists but it's a pain in the ass to do that like that.

Not true.

>Try getting a book you can leaf through while lying in bed. Not a PDF file. A real thing with paper between covers.
This. Having something you can physically interact with on more than one level is really conductive to learning. You can write, highlight, and tape other notes to pages, make dogears, etc. It's a great catalyst for active learning.

If you just create a new project in Visual Studio and program something you understand the code that you've written but you don't understand how the compiler works, how to create the files for your program etc. because the IDE already does everything for you.

Or whatever the hotkey for GoToDefinition on your text-editor-with-plugins-totally-not-an-IDE is.

Prove me wrong.
If I just want a random Int for internal code use, how do I invoke it without doing weird shit

That's a bad comparison. I wasn't talking about the language, I was talking about how to actually create an application.

You can literally inspect the assembly with memory addresses and everything that is generated by your code in real-time, see exact memory usage of various objects, etc.

Yes, the IDE generates all of the meta files for you. I'm not sure why anyone would bother to do that manually.

That isn't really the problem I was talking about. The problem is that what you type into your text editor with plugins is way to far away from what your CPU does in the end to develop any kind of intuition for what performs well and what doesn't.

Python is a fine glue and meta language.
My employer's software is comprised of C++ and Java, with Python filling the gaps and binding it together.

If you think there's only one best tool for all job, you need to get more experience

Making my lisp to be able to be embedded in html and executed as a server side language.

I give up.

>You can literally inspect the assembly with memory addresses and everything that is generated by your code in real-time, see exact memory usage of various objects, etc.
That's probably too much for beginners
>Yes, the IDE generates all of the meta files for you. I'm not sure why anyone would bother to do that manually.
I'm not saying IDEs are bad, I was just saying that you should first understand what's going on as a beginner.

You want to make a database or you want to store those objects in memory as your program runs?

If you want all that as global state in memory, the simplest design would be to create a class for each table, then store a public, static List of each of those objects, each of 3 Lists representing a table.

Better practice would be to set up interfaces between an actual SQL database where those tables are stored and interact with the data as needed.

Can you give an example?

What did you do that unintuitively performed poorly?

Most issues like this are common knowledge of application design, such as not doing I/O on a loop, and asyncing out web requests.

>Intro to C on Windows
>on Windows
>taskbar on top

>you should first understand what's going on as a beginner
That's true to some extent, but why would I care if any of my employees know how to create a solution's meta files manually?

I don't want them to do that manually. I want them to use the process in place that saves time and reduces human error.

Same goes for personal projects. Why should I ever care? At what point am I creating these files by hand? Let the IDE worry about library versioning and references.

>That's true to some extent, but why would I care if any of my employees know how to create a solution's meta files manually?
Because you want to learn how to program

Like I said, I didn't say IDEs are bad, I just think you should understand how they work. Once you do, you can work with an IDE.

>You want to make a database or you want to store those objects in memory as your program runs?
If with the former you mean messing with the data locally on the application then yeah, but just want it to do the numbering and sorting for me while I add/edit/remove objects in all lists without fucking up the data.

gist.github.com/rygorous/c6831e60f5366569d2e9

In Python, you can use \ to continue a line of code onto another line.

For example:
correctResponse = False

while correctResponse != True:
print('Type either 1 or 4.')
ans = input()

if int(ans) == 1 \
or ans == 4:
correctResponse = True
print('Good. \
You can follow a simple instruction.')
else:
print('Try again.')

>talking about Python
>some faggot tries to join the argument with a compiler-specific issue in C++

lol

You should at least be able to read some assembly (you don't need to be able to write it). It helps so much when debugging to be able to break in somewhere, look at the registers, step through a few lines of asm, and immediately realize what the problem is, vs stepping around and setting watches like a retarded monkey. Sometimes syntactic sugar can obscure what's really going on and being able to form a clear picture of what the CPU is actually doing is a very useful skill.

Fuck. Fucked my example up.
correctResponse = False

while correctResponse != True:
print('Type either 1 or 4.')
ans = input()

if int(ans) == 1 \
or int(ans) == 4:
correctResponse = True
print('Good. \
You can follow a simple instruction.')
else:
print('Try again.')

I've kind of got a problem/question like has. I wanted to make a look-up program for work/practice, so I shoved what my novice brain thinks should happen in Python: I've got three dictionaries - one that associates a user-input state with a hardcoded county, another that associates that county with all of the towns in it, and a third that associates each town with a "protection code" from the local fire department.

# get input from user
state = input("Enter the state (abbreviation): ")
county = input("Enter the county: ")

# associate state with counties
countiesInState = { 'NY' : 'Nassau'}

# look up appropriate towns
townsInCounty = {'Nassau' : 'Garden City'}

# protection class
classCode = {'Garden City' : '03'}

# return results
print (townsInCounty[county] + ", class code " + classCode[townsInCounty[county]])


and below should be the somewhat end result:

Enter the state (abbreviation): NY
Enter the county: Nassau
Garden City, class code 03


I can print one town easily enough, but I don't know how to associate multiple towns with one key AND associate all of those towns with protection codes on top of that. Am I in over my head? Would this be better in C#/Java? I only really know the basics of single dimension arrays.

>mongodb
snapchat for databases

"Messing with the data locally on the application" means the data is in memory.

Use the 3-object, 3-list solution, it's the easiest way if this is a quick-and-dirty.
Object = row, List = Table, in this case.

If you're working with a fuckton of data (read: millions and millions of rows), you might have to do local I/O to temporarily store your local modified data.

I feel like I'm far enough along programming wise to start working on shit that's not retarded but for the life of me I can't think of anything to program.

>tfw my website is 1.53KB

The point was that "zero-cost abstractions" in C++ of all languages lead to shitty performance compared to using raw structs. Python is approximately 30x worse because you have no idea what the fuck kind of code is being generated.

I shouldn't have expected you to realize that since you're a retarded Python babby, sorry, my bad.

>MongoDB
Read an interesting article on MongoDB (and NoSQL in general):

sarahmei.com/blog/2013/11/11/why-you-should-never-use-mongodb/

I don't even write in Python, faggot.

I was genuinely interested in the issues you had with it, because I was considering dipping into it as a side language.

Strings? I have no idea how Python handles strings or what it's doing to my strings under the hood. In C I can just set up a char* and know exactly what's going on. Maybe I want a mutable string! To get the same results in Python I'd have to use a bytearray and if I ran into any problems and posted on Stackoverflow or /dpt/ everyone would call me retarded.

see
It's basic relational design.

You have a table of States, a table of Counties, and a table of Towns(Cities?).

Each row/object/item/entry in the State table has information about the state, and only about the state.

Each row/object/item/entry in the County table has information about the county, and only about the county, as well as a state ID reference.

Each row/object/item/entry in the City table has information about the city, and only about the city, as well as a county ID reference.

How you represent this in code depends on the language. I'm assuming you'd do much the same in Python as C#; define an object representing a State, and create an object to store a collection of States. Ditto for counties and cities.

For me it's the level of abstraction. I simply didn't understand what programming was until I opened up the memory window in Visual Studio and saw bytes flipping through values as my code executed. Writing C feels like I'm working alongside my computer and building something together with it. Writing Python feels like I'm sucking some mathematician's dick.

You are really talking to two people. Anyway, it's not so much a specific problem, but just the general observation that abstractions have insane costs, which is mainly because stuff that should be static is all dynamic and handled at run time, i.e. classes. The class is not just a static struct and a bunch of associated methods, it's something way more ugly than this. Usually when I try to make my python code more orderly by adding some more abstractions, it slows down noticeably. You kind of always expect this, but not as dramatically.

Gang of four or head first for design patterns ? Just want to learn new shit yo

>Writing Python feels like I'm sucking some mathematician's dick.
lol just wait til you go functional

python is fine for casuals and datafagging

Programming is literally creating, using, and manipulating data.

The fuck do you mean by "datafagging"?

found the compsci cuck

>You can always delete the entire activity stream record out of your cache and regenerate it from your consistent backing store. It may be slow, but at least it’s possible.
>What if there is no backing store? What if you skip step 1? What if the cache is all you have?
>When MongoDB is all you have, it’s a cache with no backing store behind it. It will become inconsistent. Not eventually consistent — just plain, flat-out inconsistent, for all time. At that point, you have no options. Not even a nuclear one. You have no way to regenerate the data in a consistent state.
>When Diaspora decided to store social data in MongoDB, we were conflating a database with a cache.

Very nice. That article looks really, really damaging to mongodb. Was there a response from devs?

Guyz, while commiting with git, can I in anyway comment various files differently or the only way is to commit a few times?

So I assume at some point, I'd end up having a big list/array of counties with each county having a state ID reference, and then an even larger list/array for the county/town relationship? For example, the list for Nassau has 198 town entries alone, although I think this number can easily be trimmed of duplicates and entries that are just [town] FD (fire department).

Side note: we skip the cities in a state and go straight to the state's counties because of how geographically "local" fire departments are in relation to a county rather than n fire departments in a single city.

You shouldn't be committing multiple files at once. Your commits are probably way too monolithic. Git is best with very, VERY small, atomic commits.

I generally agree, but I'm not sure I'd ever prefer C++ to Java in a team environment. It's just so much easier to figure out what someone's shitty (legacy) code is supposed to be doing and untangle it in Java than in C++.

# get input from user
state = input("Enter the state (abbreviation): ")
county = input("Enter the county: ")

# associate state with counties
countiesInState = {
'NY' : ['Nassau']
}

# look up appropriate towns
townsInCounty = {
'Nassau' : ['Garden City','Paris']
}

# protection class
classCode = {
'Garden City' : '03',
'Paris' : '99',
}

# return results
for town in townsInCounty[county]:
print(town+", class code "+classCode[town])

def user():
global lu
global lua
lu = sword , lua = raw_input('Username:')
if lu == lua:
print('yay')
user()

Why does this cause the error
lu = sword , lua = raw_input('Username:')
ValueError: too many values to unpack

I agree.
They do only use C++ for a small but complex performance critical part. Business logic is Java. Glue logic and maintenance scripts are Python.

>pirate head first c#
>first chapter introduction to ide and creating xaml for windows store app
Is it worth it to learn shit that only use in windows 8 store app?
I think i need recommendation of non-shitty ebook i can pirate.

You can do multiline commit logs. If you can't remember everything you changed, or listing the changes file-by-file is too time-consuming, then you're waiting too long between commits.

That sounds altogether more sane and pleasant than the monolithic heap of shit we have to maintain.

Do u even program bruh?

>learning programming on YouTube
Get the fuck out, Pajeet.

>ebook
Get a physical book, honestly, but if you really want an ebook grab the C# Yellow Book
robmiles.com/c-yellow-book/

I like the yellow book a lot; it's a bit disorienting if you're not from the UK to see Brit-themed examples but it's really well written. See if you can find a pirate copy of amazon.com/C-Players-Guide-2nd/dp/0985580127/ref=sr_1_1?ie=UTF8&qid=1470232979&sr=8-1&keywords=c players guide while you're at it because it's a great compliment to more academic books. I wouldn't recommend it standalone.

What useful program doesn't create, use, or manipulate data?

Actually fuck that, that's a shitty edit that does not answer your problem. Here's how I would have represented the data in python if I were you:

database = {
'NY' : {
'Nassau': {
'Garden City': '03',
'Paris' : '99',
}
},
'XX' : {
'Nassau':{
'Paris' : '97',
}
}
}

def print_codes(state,county):
for town,code in database[state][county].items():
print(town+", class code "+code)

print_codes('NY','Nassau')
print_codes('XX','Nassau')

Not that I know of.

It's basically an explanation as to why relational databases are used pretty much everywhere, and hierarchical databases have their uses, but are not to be used as the sole method of storage.

Even in simple cases like which looks hierarchical in design, you might later realize that some counties belong to multiple states, or some cities belong to multiple counties, etc, which immediately causes duplicate data.

You don't really understand how to use it. Only thing I can agree on is that debugging happens to be much more painful. Especially when you finally find the shit and see something similar would not even compile in C/C++.

0ooh i have both of them. Thanks man. I will start my programming adventure.

Congrats on writing your first fizzbuzz in C.

Dynamic typing (duck typing) kills Python for me.

EXPLAION TO ME why aren't you using extreme programming for 1-3 person teams

So the way you tackled it was to essentially create a megadictionary/JSON-like data structure to store the state, then the associated counties, and then the towns with class codes? I didn't even know I could do that with dictionaries (but is that limited to Python?).

I get the feeling it would be pretty heavy for all 50 states at the end of it all. Would it still be "worth it" to write it in Python for extended use?

I HVAOE NO EXPLAIONAIOIN

Explains a lot. I've been commiting every 4-8h of coding, so yes, the descriptions are *kinda* blurry when I now look at them.

Thank ya!

Well, to me, that seems like the easiest way to represent your data.

Another route you could go is use other user's advice and create a relational database, fill it up and use queries to retrieve whatever you want.

Since you mentioned that it's for work/practice, then it won't see much use (as in, you'll be its only user), and the easiest way is the best. If you're designing that program that will have lots of users, lots of adding and editing and whatever, a relational database would probably be the better choice because of how robustly it handles of that (and because of how easy it is to fuck up your data with a simple approach).

> but is that limited to Python?
Well, no, would work in any language that supports disctionaries/maps/hashmaps.

>it would be pretty heavy for all 50 states at the end of it all
Heavily depends on what you want to achieve. For run once and then forget tasks it's perfect.

import System.Random
> randomRIO (1, 10)
6

nothing weird about this

Have you achieved Satori yet /dpt/

the space program

>Well, to me, that seems like the easiest way to represent your data.
I don't know anything about data structures outside of terms I've heard other people use/things I've read; that's going to hamper me real quick if I don't read Intro to Algorithms soon.

>Another route you could go is use other user's advice and create a relational database, fill it up and use queries to retrieve whatever you want.
This might actually be an option because people at work have been curious about moving from the excel sheet that's currently used for this and it might give our server host reason to give us some free space to work with. There won't be a lot of editing from anyone except myself since I don't recall how often these codes change but it's not exactly rapid, but it would have a handful of users to start, probably 5 or so.

>disctionaries/maps/hashmaps.
Ok, I'm getting a better grasp of terminology. Then this is reasonably transferable to the other parts of the "Big 4".

>For run once and then forget tasks it's perfect.
Yeah, it would be about this. Getting input from the user and putting out that list of codes for the towns in the county, user copies the code they need and closes the program.

Thanks for your help, it's been invaluable.

>Think I overshot my abilities when I bought SICP, though...
You just have to take SICP at your own pace. Don't rush your way through it; take time to read a section over and over until it clicks. But if a particular exercise is really difficult for you, don't be afraid to leave it behind and come back to it later. Maybe something you learn later on will help you understand it better.

That said, don't outright skip exercises. Any of them. They're all valuable learning opportunities -- don't think of them as drills; think of them as like lessons in and of themselves. The assignments themselves are designed to teach. Learn from them.

>extreme programming
ridiculous memeword

what