Daily Programming Thread

Daily Programming Thread
Prev:

Attached: 1459817739512.jpg (500x700, 133K)

Other urls found in this thread:

gitlab.freedesktop.org/polkit/polkit/merge_requests/14
godbolt.org/g/26viuZ
godbolt.org/z/lAY2hu
htdp.org/2018-01-06/Book/
godbolt.org/z/qCLWNa
youtube.com/watch?v=s4wnuiCwTGU
godbolt.org/z/ydw6Rj
b-ok.org/
twitter.com/AnonBabble

First for Scheme

>haskell is better than c

import Foreign.Marshal.Alloc
doubleFree = do a

What's the razor equivalent for java??

Razor?

you know, the c# -> html wrapper

I don't get it, why the fuck is Python used for Machine learning and its so good at it while its such a slow piece of shit, you'd think you need something faster for those things.

Attached: 25325325325.jpg (1200x675, 93K)

>you know
No I don't. Normal people don't want to translate C# to html. Not opposing you asking or anything, just place your expectations realistically.

you're wasting memory pages you retard

Razor is the layout engine used with C#, found in ASP.NET MVC. It lets you mix C# and HTML in a way similar to that of PHP but without being shit.

Python is usually used as a frontend language for that. It's not running the actual NN. That's all C/C++.

As to why python was chosen. I'm thinking it's because big data people have a big interest in AI and big data people have been using python frontends (think anaconda/pandas) for a lot of their work already. It's not that strange.

python is just the front end. tensor flow is not written in python. it's a c++ project and python just provides an easy API so brainlet "data scientists" can use it without having to know when to make your d'tor virtual. it's literally training wheels for people too dumb to learn a proper language
but then again the whole AI/ML shit is a fucking meme

I wouldn't expect the haskell memory allocator to be that terrible.
And do you care about how much virtual address space you take?

>And do you care about how much virtual address space you take?
that's not how sbrk works

Linear types would have prevented this

besides the documentation should I read Think Python 2e or A Byte of Python to learn python? is there a web dev-oriented python book cuz I want to program web apps with python and use it as server-side language (planning to learn Flask then Django as soon as I finish one of those books)

*rustles*

/dpt/ is now a frog thread

Attached: 1536928288782.png (657x527, 184K)

dumb frog poster

Is there a way to rewrite the following python code without the extra indent for try catch?

try:
while True:
print(next(myiter))
except StopIteration:
return

The try is scoped with the while block, so ideally instead it would work something like this:

while True, try:
print(next(myiter))
except StopIteration
return

hey user, thanks, i kind of thought it might be too much of a clusterfuck
there's never any direct comparison because it's a radix sort
the style guide I have requires that arrays with a variable size should be allocated dynamically, so I didn't want to use an incorrect way of dealing with an array that was defined as a pointer by switching syntax to using arr[n] instead of *(arr+n), but maybe I'm just a brainlet

I got into the field with a fucking useless degree (BlA), and I'm wondering if it would be worth it to go back for my BA into MA for comp sci. Is there any financial incentive to prioritize school over experience, and if so, how can I look for companies that will let me work for them while going to school part time?

>his malloc still uses sbrk

BASED

while True:
v = next(myiter,None)
if not v:
return
print(v)

>using exceptions for control flow
Python is truly abhorrent.

How smart are jit compoilers; if you made a virtual machine, would they end up optimizing it into the native instructions of the CPU or keep running through the emulation layer?

lole frogposters.

require "sqlite3"
require 'csv'

db = SQLite3::Database.new ":memory:"

If this creates a new sqlitedb on ruby (on ram), how could you load an existing sqlitedb, to ram?

Attached: 1536461297200.jpg (651x651, 83K)

How does Jow Forums conceptualize its code? Do you write pseudocode or flowcharts? Any good rules to follow to make it legible?

The VM has knowledge of all instruction sets available on the host, so in theory it could convert the input bytecode to the most optimal native instructions. In practice it doesn't. At least not the OpenJDK. For instance, it doesn't automatically use AVX.

>How does Jow Forums conceptualize its code? Do you write pseudocode or flowcharts? Any good rules to follow to make it legible?
Prototype in a simple high-level language like Scheme, Haskell or Python
Then port to C or C++.

Oh jolly, more programming comics.

Attached: W1.png (868x1228, 984K)

>Jow Forums, the "smart" board
>CompSci is math
>can't determine whether an arbitrary finite simplicial complex is homeomorphic to a manifold

Attached: 1421164417027.png (714x738, 324K)

k dork

It seems pretty clear to me that if you fix n and look at finite simply connected n-dimensional simplicial complexes then the (rational) homotopy equivalence problem is decidable

Where is her nose?

You mean her trunk?

Attached: 68db54d252287f8aa53bcc4c074ab587.image.500x381.jpg (500x381, 23K)

>no results
make a new thread.

So you're saying your environment has a malloc that just wraps sbrk?
I'm saying that I don't expect malloc to not reuse memory. What kind of malloc would even allocate a new page for small allocations of the same size? Don't you normally get 4k on Linux?

>AI/ML is a meme
yes, it is

Attached: 1.jpg (550x466, 48K)

JavaScript rocks!

Attached: js-rocks.png (1000x494, 369K)

Not sure what you're point is.
You can double free in C too.
In fact if you can't double free your language is shit.

Reminder that Option could've prevented this
gitlab.freedesktop.org/polkit/polkit/merge_requests/14

For many projects, destructors would be incidental complexity.

Fuck off.

Attached: 1517587106191.jpg (1980x1400, 1.11M)

>how to conceptualize code?
get away from the computer and write some notes in english

>gcc: oi mate look what I've done for you
godbolt.org/g/26viuZ
>user: oh thanks gcc you're such a good friend
>user: I just need to add..
godbolt.org/z/lAY2hu
>gcc: what the fuck is this garbage you wrote. I'm not gonna optimize that, fuck off.
>user: (iДi)I thought we were friends

It's C++, bruh. There are too many spooky hidden control flow paths for programmers to understand, what makes you think a dumbass compiler will do any better?

what are you doing that needs to be ported to C/C++? is haskell not fast enough?

I download the newest eclipse version from their website and its tomcat version only goes up to 7? What is up with that?

Haskell is too safe, C/C++ takes the guard rails off and allows undefined behavior and that makes it fast

how would Rust compare?

The compiler is FAR better at optimizing spooky hidden control flow paths than you are, dumb nigger.

Attached: 1526841580376.jpg (900x1050, 108K)

That's not it. The problem is that the optimizations compilers do are so fragile.
Maybe you didn't read it but this just does some basic arithmetic on a range of values and sum them. The first example becomes a ret with the result.
The second example is a bunch of crap because the compiler couldn't figure out how to add a second time.

So it's an inherent problem with C++, yes. And the problem isn't compilers being dumb. It's that they're both capable and limited yet people treat them like they're not just capable. They ask themselves why can't the compiler optimize this thing when it did it in muh microbenchmark.

What it does is eliminate almost any feature from C++ as viable. And frankly it's the same with C. Except we've culturally learned to accept C as a lower bound.

Why doesn't the universe wants me to program and succeed?

>std::experimental
Submit a bug report? It's not that shocking for experimental features to optimize poorly, now is it?

i need doujins about programming so bad

Attached: dpt programming club.png (1550x1123, 890K)

Low neuronal density.

why so rude?

Give it to me straight are there non meme work from home jobs in programming?
I want to opt out of society and looking for a stable reliable work I can do from home.
Bear in mind that I don't mind about high pay.

Persevere, user.

how do I decompile machine code into C?

trust me you don't want to.

this. OP is such a fucking faggot it's unbelievable

>no copy paste OP with resources like every other general

what the fuck. get your shit together you fucking gay traps. How am i supposed to know where to learn how to program if you faggots don't even have any links in your OP

You don't, just disassemble and analyze the binary. Radare2 is a nice tool for this.

Yes. But you better be good at what you do, or have a rare talent, or connections, or run your own business. A business may not want to hire you to do remotely what ten equally good job candidates are eager to do on-site.

>home economics club
Well that manga definitely isn't about anything like a programming club.

htdp.org/2018-01-06/Book/

You could look for a business without offices.

It's what I do. If you go the freelance contractor route it may be rough at the beginning until you land decent clients.
You could also just get a regular programming job and commute for a month or so, and then transition into working from home. That's very common nowadays too because companies are desperate to keep their good programmers from leaving

I don't have any of those.

Attached: 2018-12-05-22-46-18-1219137057.jpg (229x220, 4K)

Rust is not fast by any measure

Attached: speed graph.png (960x540, 18K)

If you can program computers then you could probably run a business.

Have you done a web search?

I can't do shit for now but I'm trying to figure out how to move forward toward my goal of going off grid and opting out of this gay ass society.
It seems like programming would be the best choice for generating income from home but I have literally zero clue about this field.
What kind of business could you run and how much upfront money would you need to get it started.

>but I have literally zero clue about this field.
forget about it then
there are very few good programmers who started programming after the age of 13

If you're starting from zero knowledge then I would ask a search engine before asking a message board.

Programming is a lot easier today than it was when they were 13 though.

great why is this not in the OP?

also one link only? look at any other general. They have tons of links and advice, what If I want to learn fucking SQL?

basic stuff that should be included in any general

Anyone know how this can be written more cleanly?
swaps :: String -> [String]
swaps xs = map ($xs) $map (\x -> filter (not.flip elem [x, toUpper x])) ['a'..'z']

Attached: 1398899452968.jpg (1280x720, 98K)

there used to be a massive amount of stuff on a website run by some user linked in the OP
but that included textbooks and other such things, so it's no surprise that it is gone now
since that disappeared nobody has replaced it

Why not use a search engine?

>there used to be a massive amount of stuff on a website run by some user linked in the OP
but that included textbooks and other such things

wtf. what are you niggers doing? take your buttplugs out of your asses and get that shit back up and running

I did I found out about web design but I have no idea if it's actually a reliable non meme kind of work.
And most of the other results were meme shit like writing and social media management.

because despite what anyone says, real people are better sources of information than a search engine. being able to hear what others have been through, their advice on what they could have done better, their recommendations etc, is a huge help.

communities are tremendous resources and being a part of one lets you learn more than you might on your own.

It's not that. Even if this were caused by a bug it doesn't adress the more general faults of designing a language to handle this way.
godbolt.org/z/qCLWNa
Consider this code. This is an old example, if you go to clang 6.0 or 5.0 you'll find that it calls pushback here. It really shouldn't call pushback.
youtube.com/watch?v=s4wnuiCwTGU
There's a lightning talk on this code and some thoughts concerning compiler optimizations.
The gist of it is that optimizations are hard to do at this granularity. You have a bunch of work to do stripping away all of these abstractions. The example from before is possibly even more crazy. But here the compiler is struggling with getting rid of memory.

Do some changes for me. Compile this on trunk and look at the length of the asm output. No need for careful measurement, screen-feet are fine.
Comment out the ranged for and insert my old C style for loop (don't forget to replace the sum operation).
Measure again.
You'll find that it's way shorter. You'll find that all over the world C++ programmers argue that their abstractions are cheap if not free. They're not. Examples like are presented in the first step all over the place. People look at this one example and they applaud, I can only imagine they're thinking that the result here is guaranteed for some reasonable set of use cases, but as you see there it is not.
Range based for is a feature from C++11. It doesn't optimize out neatly in this trivial case. That is a humongous problem because not seeing this optimization prohibits the compiler from reaching other optimizations.

I'm opposed features being constructed like this. They've got no guarantee to be good. Anyone who writes C++ code like this should know it comes with the caveat of potentially very big performance costs.
Of course not everything C++ brings is bad
godbolt.org/z/ydw6Rj
Look at that. It does what you expect it to.

>No /dpt/ in the OP
Fucking retarded trap. Your shitty thread is not searchable.

Fuck off reddit-spacer. There is no useless tat in any of the OPs by design.
There is no way that anyone here can agree on anything and you just just search for that shit yourself.

>The gist of it is that optimizations are hard to do at this granularity.
That really could use some better explaining. I should probably have said that abstractions aren't trivial to boil away even when they seem to be. But you can watch the talk and get a better idea probably.

>There is no way that anyone here can agree on anything

other generals seem to be able to do it, and previous threads had resources in the OP. I think you are just being anal.

also

>muh reddit spacing boogeyman

>Fuck off reddit-spacer
The things retards will complain about. Sheesh.

programming is more art than anything else
it would be stupid to have an art general and champion one book or drawing discipline as "Jow Forums approved" over all others

There's a thing called programming boot camp.
It takes perhaps 6 months.
If you attend one, you will learn a lot, including whether you like programming.
This is very important to know because programming takes a lot of effort.
I can't imagine doing it if I didn't enjoy it.

It's possible to learn on your own but for newbies it can be invaluable to have real live humans to consult.

Do you think we all agree that that is a great book?
b-ok.org/
Here you go. There's some good books in there.
Other generals just like to market poor advice. I don't know why. The few attempts at a OP header have been disastrous and often just cause conflict. It's better this way.

Why do you even think it's of value if the people in this general doesn't find the recommendations good? You could go find a quora answer or whatever.

>other generals seem to be able to do it
So? There are many, many different types of programming which are VERY different, and people have very strong opinions about it.
I can not think of a single resource that many people will have significant problems with and just lead to a bunch of pointless shitposting.
>and previous threads had resources in the OP
No they haven't, newfag redditcuck.
>>muh reddit spacing boogeyman
Your posting style is disgusting to look at and juvenile (not just the spacing). Fuck off.

>one book

I don't see any other generals suggesting ONE HEADSET or ONE LINUX DISTRO over all others. The idea is to have many resources from different sources so that people can learn. user here said that the only link had tons of stuff, not just "one book"

>Do you think we all agree that that is a great book?

you don't have to agree on anything, compiling all the books and stating perceived pros and cons if needed is fine. no one said there has to be ONE DEFINITIVE BOOK one programming "X" language.

For error messages, what tense do you use:
"File is not found" or "File was not found"?

I feel like "was" is more correct in most if not all cases since the error values are typically stored before being logged.

Attached: 1471397567615.jpg (343x354, 19K)

afd = {0: {'a': 4, 'b':1},
1: {'a':2, 'b':1},
2: {'a':4, 'b':3},
3: {'a':0, 'b':3},
4: {'a':4, 'b':4}}

def accepts(transitions, initial, acceptions, string):
state = initial

for i in string:
state = transitions[state][i]
return state in acceptions

def main():
in_string = input("Introduce a string to check:" )

if accepts(afd, 0, {1, 3}, in_string):
print("Accepted.")
else:
print("Not accepted")

if __name__ == "__main__":
main()

So I wrote this little Deterministic Formal Automaton/Automata in Python3 like two months ago and almost forgot how it works. I'm using a dictionary to work with the states and specifying the transitions between states.
Now I need to implement a Pushdown Automaton/Automata or Stack Automaton/Automata, whatever you want to call it; Where I am also supposed to store and check for elements of a certain stack before moving through staes.
The thing is I have no idea how to do it. I'm honestly having a hard case of not even knowing what to ask. Yeah I know, I'm a huge brainlet so you might get mad and shit at me.
Still, if you could give any advice, I would really appreciate it.
Thanks a lot.

Attached: 1514846854468.jpg (645x773, 56K)