[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
/dpt/ - Daily Programming Thread
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 255
Thread images: 24
File: karlie.jpg (225 KB, 1515x1024) Image search: [Google]
karlie.jpg
225 KB, 1515x1024
Old thread: >>54520933

What are you working on /g/?
>>
A waifubot
>>
>>54528613
Gross.
>>
>>54528613
>unironically posting 3D

get the fuck off my board
>>
Please stop posting anime.
>>
File: Cute!.webm (2 MB, 924x520) Image search: [Google]
Cute!.webm
2 MB, 924x520
>>54528613
Gonna build my own VM, no idea what I'd do with it after though
>>
>>54528666
seek psychiatric help
>>
>>54528613
What's up with her ribs

Why isn't she writing code
>>
>>54528613
She's fucking perfect
>>
>>54528613
thank you for posting a waifu programmer image
>>
>>54527702

Help
>>
File: 1444343055256.png (143 KB, 280x275) Image search: [Google]
1444343055256.png
143 KB, 280x275
>>54528669
>dancer armour
>>
>>54528669
i was fiddling with this idea myself cause it seemed interesting but then dropped it cause i wouldnt have anything to use it for...

i hope you're writing it in C/C++/Rust tho
>>
I want to mess with images. There is openCV, imagemagick etc.
But before I start using those I'd like to know more about what an image file is exactly - is it text, how does text become an image etc.
I'd like to be able to generate such files, change their colors, distort them etc using programs that I made.

But i lack some theoretical knowledge.
I would google this shit, but i'm not sure what exactly I need to google.

Is there some resource that anyone here has used and liked about images.
>>
>>54528714
I was thinking C or D.
>>
>>54528730
not sure how much higher level D is, but as long as it's not too high go for it bro

(even tho its a dead lang)
>>
Question about C: Is using void * frowned upon if you don't have to use it? It seems like void * could be a major source of type safety issues.
>>
A pong clone
>>
>>54528721
>what an image file is exactly - is it text
Wow, you have a bit to learn anon..

an image file is almost always binary. They are usually compressed such as in the case of png and jpeg files.

A bitmap file is uncompressed, and is just a binary stream of all the pixel values. The beginning of the file will have information about how to interpret the pixels, such as how wide and high the image is meant to be, and what colour format the pixels are in.
>>
>>54528757
Yep.
>>
>>54528730
Do it rusty rusting rustless, D is dead, baby.
https://www.youtube.com/watch?v=y7Yp2L6c2KM
>>
>>54528770
Rust has been taken over by SJWs and will go nowhere.
>>
>>54528752
>>54528770
The community is still pretty active and it gets worked on pretty often. It's not dead, just not very popular
>>
>>54528796
Does rust still have horrific compile time problems?
>>
>>54528804
I dunno, I don't use it
>>
>>54528762
thanks for not answering the question, tripfaggot

you might as well have not responded if you didn't want to offer an answer
>>
>>54528828
How did i not answer the question? What is it you would like to know?
>>
1) Find Freelance gig in your area
2) Hire Pajeets to do the project
3) Pay them 80% less than what you charge

Why aren't you doing this?
>>
>>54528804
i'm using it, and this emacs plugin gives me live error checking by compiling the file, it's near instant for ~1500LoC projects.

also i was in the rust beginner irc and even though i agree they are SJW they are very competent programmers, and they dont push their agenda
>>
>>54528836
Because I would kill myself knowing some pajeet copy pasted shit from stackoverflow without reading SICP
>>
>>54528757
void * is good for two (some would say three, but I disagree) things.
1. If you're talking about a chunk of memory
2. As the other component (besides the function pointer) of a closure
The third way to use void * is as a (type-erased) generic, but IMO you should always use macros for generic programming (i.e. parameterizing code over a type).
>>
>>54528765
So suppose I'm writing a function 'func' which always returns a pointer to a certain struct 'container'. Given
struct container* func(...){
...
}

and
void* func(...){
...
}


I should opt for the first option despite being considerably more verbose?
>>
Not really programming but I had to run several scripts in SQL Server earlier (a nightly script I had to run not in the schedule to apply some changes).
>run script
>BIG RED ERROR: can't write to transaction log, please kill yourself
>check server, turns out the drive containing the .ldf file is full to the brim
>getting reports that users are unable to login to our main application
>PANIC
>decide to free up some space for the .ldf file, 1TB now free
>users still can't log in
>severity one(aka you better fix this right now or else we are going to lose money and you lose your job probably) already issued
>MORE PANIC
>restart our main application
>same issue, check all possible causes, application can't connect to DB
>but DB is up, connection is OK, both manually connecting to db through local and remote machines, all accounts used also tested
>everything tells me that the DB is the issue - restarting the DB server and services will take 8 hours
>already hear names of big guns sending emails to our support team
>1 century later(1 hour)
>decide to the app server's cache (not involved in our standard procedure)
>everyone can now login
Thanks for reading my blog. That was the most intense 1 hour of my life.
>>
>>54528881
lmao
all my functions use void pointers and i just cast later
yolo
>>
>>54528757
Insomniac and Naughty Dog uses them instead of templates for generic programming, which I guess qualifies as a place where you don't have to use it.

I'd say that's an exception rather than the rule though, if you walked into like NASA or some shit and started replacing templates with void * they'd probably go apeshit.
>>
>>54528903
Yes, you should. The more type information you can encode in your function signature the better.
>>
>>54528852
How does it feel people who develop Ruby on Rails apps and never even heard of SICP make 10 times more money than you?
>>
>>54528903
Always.
>>
>>54528903
obviously

you have a type system use it
>>
>>54528924
They don't, though.

(Well, maybe some in California do. But then they go home to a tiny apartment that they pay $3k/mo rent for.)
>>
>>54528924
Pretty good because cracking/exploiting their shit is easy like raping a 5 year old kid.
>>
ess queue ell

or

sequel
>>
>>54528971
Squall
>>
>>54528903
This is unrelated to your problem, but if func is allocating the memory for the struct, don't. Pass it in as a pointer argument to be written out. It's frowned-upon in C to take away control over memory from the programmer, because that's pretty much the only thing C has going for it.
>>
>>54528971
squeal
>>
>>54528905
As a fellow DBA, I'd be lying if I said I haven't had a similar experience.
>>
>>54528971
"Sequel", unless you want someone to immediately dismiss you as uneducated.
>>
>>54528971

The latter, but I had a DB professor this past semester that absolutely insisted on the initialism.
>>
File: 05-13 13-02-26.png (4 KB, 168x154) Image search: [Google]
05-13 13-02-26.png
4 KB, 168x154
I worked on a little chrome addon to download every image from an 4chan thread, it was kinda pain to code but it's open source so there's always room for improvement.
>>
>>54528881
So suppose I'm making a computational algebra system (just an example) and I need to implement runtime polymorphism. In this case, void* seems like a good candidate. Is there a better way to do this?
>>
>>54529032
You're still in college, Ozzy?
>>
>>54529047
in this case use a language that supports real runtime polymorphism
>>
>>54528613
Whom is this floor whore?
>>
As the project's complexity grows, I'm finding it harder and harder to write self documenting code. Nobody taught me anything about this, what the fuck? I used to be able to tell what anything did in my code just from reading it but now that's almost impossible.
>>
>>54528987
It was my first and my biggest blunder. it's been 6 hours since and I still can't sleep, I also haven't eaten anything yet, I don't think I can stomach anything right now.
>>
>>54529055

Unfortunately.
>>
>>54529038
that's cool. source source? im wondering what made it such a pain..
>>
>>54529047
You'll (likely) need to use void *, yes, because what you want is easily accomplished with closures (a virtual method paired with its object is essentially a closure).
>>
>>54529076
Where you at comrade
>>
>>54529059
Karlie Kloss. She's a programmer.
>>
>>54529085

Top secret government facility.
>>
>>54529076
Whatcha studying?
>>
>>54529066
>I'm finding it harder and harder to write self documenting code.
Probably because your codebase doesn't have a good hierarchical structure. Learn good code structure. It's essential to writing anything that's not script-kiddie tier shit.
>>
nice programming related picture FAGGOT
>>
>>54529081
The source code is available on my github
Jumono is my username if you're interested, I have tons of fun working on little things like that when I have a free time.
>>
>>54528881
What if I have a function that returns a pointer to a struct based on its input. Since I don't know which pointer to struct the function is going to return, I'm assigning the value to a void* variabile. Then, based upon some other stuff, I cast the pointer to the actual struct type it's pointing.

is this ok?
>>
>>54529113
She's a programmer, you idiot.
>>
>>54528613
>karlie.jpg
overrated as shit
>>
>>54528666
Not your board fucko.
>>
>>54528613
>old hag
>shit op
fuck off
>>
>>54529128
No, much better to use a union for that.
>>
>>54529129
no she's not, you don't become something just because you feel that you are it
>>
File: 1461005231404.jpg (687 KB, 826x1167) Image search: [Google]
1461005231404.jpg
687 KB, 826x1167
>>54529094
Uh-huh
I bet it's a community college, ain't it
>>
>>54528921
>>54528925
>>54528929
Okay, thanks.
>>54528982
What if the output is of unknown size which is impossible to predict for the programmer? Is it still a better idea to just allocate a large chunk of memory outside of the function and set up a limit for the amount of memory used for the function?
>>
>>54529157
If possible, separate the part that calculates the size into another function. Failing that, allow the user to pass in an allocation callback (basically something with the signature of malloc).
>>
>>54529143
Oh, I actually never thought about using unions. Nice.
>>
>>54529056
>>54529082
Okay, thanks.
>>
>>54528903
Why the fuck are you programming in Swedish?
>>
>>54529119
you're using vanilla js. i applaud you sir. so much of your code could've been saved by using jquery but you went all out.
respect man
>>
>>54529188
>func
>container
>swedish
what
>>
>>54529157
>>54529183
I only say to prefer something other than a callback because C doesn't have lambdas, and so it can be a bit of a hassle.
>>
>>54529188
för att jag vill det
>>
>>54529204
>>54529222
What?
>>
>>54529222
Nice trips cuck
>>
>>54529129
yea, and you're also not a faggot
>>
>>54529099

CS

>>54529152

No, actually. I was going to a community college a while ago, but now I'm at a real university.
>>
File: indians6.gif (60 KB, 1024x874) Image search: [Google]
indians6.gif
60 KB, 1024x874
>>54529200
>>
>>54529213
>C doesn't have lambdas

#define lambda(l_ret_type, l_arguments, l_body)         \
({ \
l_ret_type l_anonymous_functions_name l_arguments \
l_body \
&l_anonymous_functions_name; \
})


Enjoy.
>>
>>54529200
I don't like jQuery, never liked the syntax and I'm generally okay with doing pure JS
>>
what's the best language to write the first compiler for? everyone recommends scheme, but I don't know anything about functional programming besides Java streams and lambdas. I intend to write it in C and for it to produce assembly code
>>
>>54529129

I know right. I always get into lingerie and 6 inch stilleto heels, then sit on the floor without any equipment to do koding.
>>
>>54529268
>if you don't use your an idiot
>your
>>
>>54529314
CLite
it's not an actual language but great for learning
http://myslu.stlawu.edu/~ehar/Spring10/364/clite_grammar.html
>>
>>54529323
>xD
>>
File: hs-2012-01-a-xlarge_web.jpg (1 MB, 1280x1024) Image search: [Google]
hs-2012-01-a-xlarge_web.jpg
1 MB, 1280x1024
Downloading images from the NASA archive since I recently learned they are all free to use as long as you don't suggest NASA is endorsing you and they don't have astronauts in them.
>>
>>54528613
Finally going back and reworking my 4chan api wrapper

import Foundation
import FourChanAPI

let a = FCBoard(name: "a")

// Getting a list of all boards
FCBoard.getAllBoards {boards in
print(boards)
}

// Updates the board's thread list
a.updateThreads {threads in
print(threads)
let thread = a.threads[0]

// Fill thread with posts
thread.updatePosts {posts in
// Print last post
print(thread[thread.count - 1]!)
}
}
>>
>>54529323
It's the best way. I sometimes massage myself down there to get my blood flowing, and then meditate on zygohistomorphic prepromorphisms.
>>
>>54529188
How can you tell?
>>
>>54529275
gnu c
>>
>>54529337
looks straightforward as fuck. thanks.
>>
>>54529443
void * is type-fluid.
>>
>>54529468
Voids are also black.
>>
>>54529468
ayyyyyyyyyyyyyyyyyyyyyyyyyy
>>
I'm playing around in IDA. How should I name local variables that are basically duplicates of parameter?
void __fastcall setPlayerPosition(__int16 x, __int16 y)
{
int v2; // esi@1
__int16 v3; // di@1
__int16 i; // bx@1
int v5; // eax@2
void *v6; // eax@5

v2 = dword_40C618;
v3 = y;
...

As seen here, where v3 is parameter y. Would you add an underscore or what?
>>
>>54529455

Admittedly, but it's still neat. A bit like TMP in that its functionality is merely incidental.
>>
nothing tbqh
>>
>>54529275
What the fuck is this shit? Show a usage example.

Does it have closure support?
>>
>>54529507
>Does it have closure support?
no
>>
File: 1461987500521.gif (3 MB, 640x360) Image search: [Google]
1461987500521.gif
3 MB, 640x360
I'm currently making a program that scans a company's schedule and sends out emails and SMS messages to the customers alerting them of their appointment the following day. I'm having a weird issue though. While i'm sending a mass amount of text messages, sometimes (rarely) a couple of them will be missing a character or two from the message. I'm using the service of sinch to send out the messages. Anyone know what the issue might be? I'm starting to think it's on their end.
>>
>>54529489
I never understood what so many underscores are for. I've seen them in many disasm as well as many C/C++ libraries.
>>
>>54529528
Might as well not be an anonymous function then.

So what happens if you attempt closure shit? Does the program print garbage or does it fail to compile?

And apparently since this isn't gnu c, what sort of c is it?
>>
>>54529550
>I'm starting to think it's on their end.
yeah since it only does it sometimes, it's probably an issue on their end
>>
>>54529569
>And apparently since this isn't gnu c, what sort of c is it?

It is GNU C.
>>
>>54529550
You might have a weird kludge somewhere causing it.

Impossible to say unless you show us what's underneath the skirt, so to speak.
>>
>>54529551
in this case it's in defs.h
#define __int16 short
>>
>>54529569
>Might as well not be an anonymous function then.
a lambda procedure is an expression.

>>54529569
>Does the program print garbage or does it fail to compile?
print garbage.

>>54529569
>And apparently since this isn't gnu c
this is gnu c.
>>
I love you, /dpt/.

I learn so much while I'm browsing these threads.

Now, I don't learn much from the actual thread, but I take all of these fragments of incoherent arguments and research them until I get a cross-section of articles on a particular subject.

The catalyst, of course, being the inane rants and insults thrown around here.

So thank you, /dpt/. You've caused me to be able to bullshit my way through basically any conversation about things related to programming.
>>
http://blog.8thlight.com/micah-martin/2013/05/28/performing-code-katas.html

Why aren't you a code artisan, /dpt/?
>>
>>54529799
I'm a software alchemist you flying faggot
>>
>>54529799
i'm a wizard that writes spells in scheme
>>
>>54529799
>>54529799
I didn't think SF webdevs could get any more pretentious, but there you go.
>>
>>54529609
Rather not post the entire code because it hold's company info, but here's the part where it sends a text. Also, yes I know I'm a fag for using c#.

private async Task MainAsync(string description, string when, string over)
{
string Tdate = DateTime.Now.AddDays(1).ToString("MM/dd/yyy");
//Remove all possible (,), and - from the address
String fixPhoneNumber = description.Replace("-", "").Replace("(", "").Replace(")", "");
Console.WriteLine(fixPhoneNumber);
var smsApi = SinchFactory.CreateApiFactory("logindata", "logindata").CreateSmsApi();
var sendSmsResponse = await smsApi.Sms("+1" + fixPhoneNumber, "(The Companies name) would like to remind you that you have an appointment on " + Tdate +" between " + when + " and "+ over + ". If you have any changes, please call us ASAP at (The Company's phone number)").Send();
Console.WriteLine("Text Sent");


Thanks if anyone can help.
>>
>>54529088
*coder
>>
>>54529887
**apper
>>
>>54529859
Where are the characters missing? From the end of the message string?
>>
>>54529911
The weird thing it's usually near the end of the messages.
>>
>>54529799
>clojure
Of course.
>7 minutes to fizzbuzz
Kek
>>
>>54529931
near? or at? Do you have an example?
>>
>>54529859
>Also, yes I know I'm a fag for using c#.
C# is comfy as fuck, nothing wrong with that.

Chaining Replace() is fine, but I like the LINQ hack:
string fixPhoneNumber = new string(description.Except("()-").ToArray());


I'm willing to bet that the API just hacks off the end of a string if there are too many characters.

Are the characters ever dropped in the middle of the message?
>>
>>54529948
Like the word "us" at the end will lose it's 's' character.
>>
>>54529859
>>54529952
It's worth noting that the length of your 'when' and 'over' variables are not apparent from this code.

Are they ever longer or shorter?
>>
>>54529952
>Chaining Replace() is fine, but I like the LINQ hack:

Well, that's a new trick to me.
>>
>>54529845
))))))
>>
>>54529971
That's messed up. Can't be anything you're doing. Either the library you're using is fucked or they're fucking it up server side. Would be interesting if you could see what's being sent to the server. Maybe with fiddler or something.
>>
>>54529972
The info it pulls would be ie) 03:00 PM and 04:00 PM.
>>54529971
Thanks man, I didn't know I could do that. I
Tend to lose a character or two near the "Call us at" part
>>
File: beautiful.png (1015 B, 83x17) Image search: [Google]
beautiful.png
1015 B, 83x17
>>54529991
That's the source of my power. But you have to colorize them.
>>
>>54528760
source for background plz?
>>
>>54530009
lack of sleep, sorry. second part is for
>>54529952
>>
>>54529985
LINQ hacks are basically my tripcode.

I'm /dpt/'s resident C# LINQ abuser.

You can do anything with LINQ.

ANYTHING.

>>54530009
>Tend to lose a character or two near the "Call us at" part
It's definitely the API then, nothing with your code.

Examine the texts that have dropped characters and confirm their EXACT character count.
>>
How much domain specific DOM shit do I have to memorize before I can make a trivial userscript in JS?

I'm finding JS difficult because I have no idea what i'm assigning to my variables.
>>
>>54530050
>I'm /dpt/'s resident C# LINQ abuser.

I love LINQ as much as the next guy, but I try not to do too much with it.
>>
File: Iceweasel_wallpaper.png (2 MB, 1280x800) Image search: [Google]
Iceweasel_wallpaper.png
2 MB, 1280x800
>>54530043
Some anon posted it somewhere sorry i don't have the original image
>>
File: Qqv3LoM.png (12 KB, 858x152) Image search: [Google]
Qqv3LoM.png
12 KB, 858x152
>>54530094
I don't think you understand.

It's like a drug.

Workflow:
Can I use LINQ in this function?
>Yes
Great, let's use LINQ!
>No
Bullshit, watch this.
>>
>>54530161

Lord have mercy.
>>
>>54530161
I do this a lot in F#. Except with |>, which lets you do that sorta shit except you can use any function instead of only linq ones.

Shocking sometimes how much you can get done without any variables, state or mutation.
>>
>>54530161
>GroupBy(x => x)
>multiple ToList
Now, I'm not claiming to be a LINQ expert, but are you sure this is right?
>>
>>54528721
If you want some general manipulation, I think linear algebra has some applications. read page 1 and 2 of Elementary Linear algebra by spence, Insel to see what I mean.
>>
File: LinearAlgebra.png (801 KB, 1920x1053) Image search: [Google]
LinearAlgebra.png
801 KB, 1920x1053
>>54530276
This is what I mean by manipulation.
>>
>>54530234
>I didn't declare any variables, so they don't exist :^)

Of course there is state, a long chain cannot possibly be atomic.
>>
>>54530347
The state could be ephemeral, i.e. only existing as parameters or return values.
>>
>>54528721
The essence is the image data is stored as arrays of numbers which represent brightness percents for each pixel of 3 colors, red, green, and blue, which when combined form a composite color.

A pixel is a small segment of the image. When you render an image, it corresponds to a dot on your monitor.

>red:0
>green:255
>blue: 0
is maximum brightness green
>red:50
>green:50
>blue:50
is a dark gray


Here's some file format info:
Simple
>http://www.ue.eti.pg.gda.pl/fpgalab/zadania.spartan3/zad_vga_struktura_pliku_bmp_en.html
Hard
>http://libpng.org/pub/png/spec/1.2/PNG-Structure.html

>>54528762
What a useless answer.
>>
>>54530347
>I didn't declare any variables, so they don't exist :^)
Exactly.

>a long chain cannot possibly be atomic.
so?
>>
>take an SQL class
>love the shit out of it because databases are fun

how do I enhance my knowledge on this shit? I wouldn't mind making a career out of doing databases.

I am up to B-trees and hash indexes and clustering.
>>
>>54530347
the long chain just passes through more functions without any state (everything is passed as an argument)
>>
>2016
>not using dependent types
>>
>>54530374
Honestly, get a job working as a DBA and BI dev.

I liked databases, but it wasn't until I got to play with living, breathing data that I really understood the way things work, how to optimize, etc.

It's wonderful having a huge live database to play with.
>>
>>54530339
>>54530276
thanks lad, lin. algebra sounds nice, i already was planning on reading up on it
this is good
>>
>>54529776
This. So much this.

Combine this general with a CS curriculum and you're set.
>>
>>54530103
thank you very much, senpai
>>
>>54530386
I try to when I can, although library support for Idris is so tiny
maybe I should start porting libraries to it
>>
>>54530386
>not fibrations
>>
>>54530239

It's probably right. You end up needing to do the same thing (x => x) with OrderBy.
>>
>>54530478
I don't use linq much. Seems silly they wouldn't have a Order() method. I hate the x => x stuff.
>>
>2016
>not using dependent types
>not using linear types
>not using indexed inductive-recursive definitions
>not using homotopy type theory (truncated to sets for the computational behaviour)
>>
>>54527337

i just want to watch porn with my vpn g
>>
>>54530402

I have used yelp business data and hard drive failure data in applications and that was pretty damn fun.

been thinking about some form of database stuff but I am worried if that will lessen my career options.

I am a recent CS graduate.
>>
What does map/filter/reduce do and why do I see it so often?
>>
File: 052.png (292 KB, 500x541) Image search: [Google]
052.png
292 KB, 500x541
>>54528627
Please share more information, anon-kun!
>>
>>54530042
do you ever get Lost In Stupid Parenthesis?
>>
I need help with this python script. I want it to have basic signature checking function, like an AV. It's supposed to open all directories, then sub-directories, and then at last open the files to create a MD5 checksum for scanning. I'm pretty much stuck:
 import os
import hashlib


database = raw_input('>')

files_to_be_scanned = open("output.txt", "w,r")
# root prints the directories from specified path
# dirs prints the sub-dirs form root
# files prints all files from root and directory
for root, dirs, files in os.walk("./"):
for name in files:
# write all files to output text for later scanning
files_to_be_scanned.write(os.path.join(root, name))
# write new line after each file
files_to_be_scanned.write("\n")
with open(os.path.join(dirs, name), "r") as checkfile:
# reading the contents of the file
data = checkfile.read()
# pipe contents of file for checksum generation
md5_returned = hashlib.md5(data).hexdigest()
# if the files checsum matches any of those in cvd
# the message infected! is displayed, otherwise clean. is displayed
if aline == md5_returned:
print "Infected!"
else:
print "Clean."
>>
>>54530493
>I hate the x => x stuff.

Me too, but if you need the default comparator, that's how you get it.
>>
>>54530535
No, that's not possible if you use a good text editor.
>>
tfw you work for a company and all their in-house software is made in vb6
>>
>>54530509
You can write an algorithm once and have it work for all sorts of sequences and trees.
>>
>>54530509
Not valid code but you'll get the idea
>map
map(square,{1,2,3}) -> {1,4,9}
Applies a function to each member of a list.
>filter
filter(even,{1,2,3,4}) -> {2,4}
Removes all elements that don't pass the test.
>reduce
reduce(+,0,{1,2,3,4}) -> 10
It takes a binary operation A,A -> A and for each successive element, applies the "accumulation value" against that element.

You see them so often because they're tools used to compose more complex algorithms. Fizzbuzz can be thought of as a map of some function onto a list of numbers.
>>
>>54530504
>thinking about some form of database stuff but I am worried if that will lessen my career options
Quite the opposite.

Entry-level programmers and webdev are a dime a dozen.

Database experience means you have rock-solid job security.

The best thing you can do for yourself is to combine knowledge of databases with something else. Personally, I did MIS at a reputable business school, so it's a combination of business + database. Alternatively, you can combine it with development experience, which would put you in a great back-end dev job market, doing API and enterprise dev.
>>
So I am learning to program in Swift, and quite like it. However, I'm generating a large number of code files, which aren't particularly searchable.

So I thought I'd start blogging about what I'd learnt, with code snippets and as good an explanation of what is going on for my own benefit. If anyone else reads it, that's OK.

However, Wordpress themes don't seem to handle code in a pleasant way. They sort of highlight each line, so it doesn't look like one continuous block.

Is there a good Wordpress theme I can use (free!) or just a better blogging site to use?
>>
>>54530509
they transform collections is one way or another.

map takes a collection and returns a new collection that is the same as the old collection except each item has been transformed with a function you pass. example:
[1, 2, 3].map((num) => num + 1);//returns [2, 3, 4]


filter returns a new collection with certain items filtered out based on the method passed.
[1, 2, 3].filter((num) => num < 3);//returns [1, 2]


reduce accumulates all the items in a list into a single value and returns value.
[1, 2, 3].reduce(0 /*initial value for accumulator*/, (num, accumulator) => num + accumulator));//returns 6


This is pseudo code. Don't rag on that this isn't valid code for whatever language. i know.
>>
>>54530583
Reduce (fold) is more general than that. The accumulator/result type can be different from the element type.
>>
File: WpNNtlN.png (6 KB, 644x103) Image search: [Google]
WpNNtlN.png
6 KB, 644x103
>>54530493
>they wouldn't have a Order() method
You mean Sort()?
>>
File: Output.png (33 KB, 1280x720) Image search: [Google]
Output.png
33 KB, 1280x720
The way I generated this makes me feel dirty.
>>
>>54530509
>>54530578
You can think of reduce in particular as being a "generalized for loop".
>>
>>54530643
Yeah, i suppose i do..
>>
>>54530509
map transforms all elements in a data structure. It's very flexible, you can use it to access multiple things at once easily
addresses = map(lambda person: person.house_num + person.address1 + person.address2, people)


filter selects the elements that resolve to true given a function. Very useful for querying data easily
rich_people = filter(lambda person: person.salary > 50000, people)


reduce helps group data
richest_person = reduce(lambda current_richest, current_person: current_richest if current_richest.money > current_person.money else current_person, people)


People typically use for loops combined with ifs for things that are as simple as map, reduce, filter

In Python, it's even more elegant using list comprehensions.
In Javascript, you can use bigger functions

Other languages have their own unique quirks
>>
>>54528613
who is this cum drum?
>>
>>54530683
>tfw this anon thinks I'm rich
>>
>>54530683
>In Python, it's even more elegant using list comprehensions.
I kinda prefer my map famalamalamalam
but it is the same
>>
>>54530583
Oh yeah and you can implement map and fold in terms of reduce (often called fold). And fold has a left-sided version and a right-sided version because your operation might not associate.

(define (map f alist)
(foldr (lambda (elem newlist) (cons (f elem) newlist)) '() alist))

(define (filter predicate alist)
(foldr (lambda (elem newlist) (if (predicate elem) (cons elem newlist) newlist)) '() alist))

>>54530642
Yeah I guess. I guess B,A -> B or A,B -> B depending on which fold it is would be better.
>>
>>54530683
>In Javascript, you can use bigger functions
Forgot to add that in JS, they are a function of arrays and/or dicts, and that you can use bigger functions in Python if you sub in a function rather than inline a lambda

>>54530714
I'm a bonglad, £50k is pretty respectable if you use 4chan (not that I make that much)

>>54530723
I like them too, but I prefer it only in languages where it's a function of data structures because it looks cleaner in bigger queries
>>
>>54530683
>>54530724
Basically all set theory, similar to how TSQL is formed.
>>
A small daemon to change the niceness value of games under linux.
>>
>>54530683
>In Python, it's even more elegant using list comprehensions.
I always found these pretty messy and confusing. Not that I can't read them, but you sort of need to read them out of order to understand how data is being transformed. "natural language" stuff in programming langugaes has a habit of being shit.
>>
>>54530549
i never liked LISP anyway
>>
what is a qt programming project to surprise your qt3.14 programming gf with, /dpt/?
>>
>>54530741
Oh, that's like $74k in burgerbux, that makes a bit more sense.
>>
File: 0201423006.jpg (70 KB, 485x648) Image search: [Google]
0201423006.jpg
70 KB, 485x648
Is systems programming comfier than application development?
>>
>>54530535
Not with my symbols of power colorized.
>>
>>54530758
To work on together or as like a cheesy gift?
>>
>>54530751
Set syntax is very easy to understand, even if you didn't deal with it much in school. I can only imagine it being messy if you are chaining a variety of things together without new-lining things. It uses the query functions in a way that's pretty human-readable
>>
>>54528780
What the fuck is wrong with you?
>>
>>54530775
ideas for both?
>>
>>54528613
Learning cmake. Some of it makes sense. Some of it is retarded. Any other good build systems?
>>
I'm adding some jailbreak tweak detection to one of the iOS apps I work on. Should come as a nasty surprise to those getting a free ride.
>>
>>54530790
makefile :^)
>>
>>54530779
nah
[x * 2 for x in S if x % 2 == 0]

is a pretty retarded way to set up list comprehension syntax.

The logic starts at "S", which is in the middle. Then it get's filtered with "if x % 2 == 0", which is at the end. Then it get's mapped with "x * 2 for x in" at the start. I don't know what they were smoking, but I don't want any.
>>
>>54530809
>jailbreakers are pirates
Scum.
>>
File: businessman.gif (150 KB, 234x390) Image search: [Google]
businessman.gif
150 KB, 234x390
>>54530819
cmake makes makefiles you dip ;p

Seriously, is it worth it to learn straight up Makefile syntax, or is cmake so much more easily maintainable for larger projects that it's the best way to go?
>>
>>54530827
Jailbreaks aren't scum until they patch apps to get access to paid content.
>>
>>54530843
I honestly never used cmake friendo so I didn't know that
>>
>>54530822
>is a pretty retarded way to set up list comprehension syntax
The thing you posted literally sounds like a natural language sentence, wtf are you on about
>>
>>54530822
Just from a 1-second glance I can tell it squares numbers in S if they are even. It follows a typical natural sentence structure

What are YOU smoking?
>>
>>54530862
>The thing you posted literally sounds like a natural language sentence
That's why it's bad. It's bad for the reason i mentioned. Making shit "natural language" does not make them simpler. There's a good reason this sort of shit is barely used in programming langugaes.
>>
>>54530872
>What are YOU smoking?
logic
>>
>>54530874
>Making shit "natural language" does not make them simpler.
It looks simple to me. Maybe you're just retarded
>>
>>54530843
>grunt
>gulp
>npm
Haha
>>
>>54530888
>It looks simple to me.
Thats because you are an imbecile.
>>
>>54530790
>good
>build system
Pick one.

They're all messy kludges to work around lazy compiler devs.
>>
>>54530822
The only thing retarded about that is if instead of and.

Otherwise it's perfectly fine. Did you take anything in math beyond Calculus?

>>54530872
Except it doesn't do that, I think, I think if S is
{1,2,3,4} it outputs {4,8}.
>>
File: cute.jpg (25 KB, 400x304) Image search: [Google]
cute.jpg
25 KB, 400x304
>>54528613
I'm writing an S-expression printer/parser in Hasckell (innb4 doubble memme). I write my parser logic using Text.Parsers.Char, it's really nice being able to program to an interface rather than to an implementation. Because of that, I decided to do a wrapper for ParsecT so that I can have a MonadState instance on my user state. So far I have
newtype CharParser u a = Do { unDo :: forall s r. Stream s (Cont r) Char => ParsecT s u (Cont r) a }
instance Functor (CharParser u) where
fmap f (Do x) = Do $ fmap f x
instance Applicative (CharParser u) where
pure v = Do $ pure v
Do f <*> Do x = Do $ f <*> x
instance Monad (CharParser u) where
Do x >>= f = Do $ x >>= unDo . f
instance MonadState u (CharParser u) where
get = Do getState
put v = Do $ putState v

(No luck with GeneralisedNewTypeDeriving) But I also need MonadCont, and in this case, the naïve approach fucks up:
instance MonadCont (CharParser u) where
callCC :: forall a b. ((a -> CharParser u b) -> CharParser u a) -> CharParser u a
callCC f = Do $ callCC $ \cc -> unDo $ f $ \v -> Do $ cc v

GHC says
[snip, next post]
I get what it means, but I can't find a way. How do I do this, /g/?
>>
>>54530911
>{1,2,3,4} it outputs {4,8}.
You're right. I'm not wearing my glasses, thought it was **
>>
>>54530937
src/Helper/Parser.hs:21:57:
Couldn't match type ‘s’ with ‘s1’
‘s’ is a rigid type variable bound by
a type expected by the context:
Stream s (Cont r) Char => ParsecT s u (Cont r) a
at src/Helper/Parser.hs:21:14
‘s1’ is a rigid type variable bound by
a type expected by the context:
Stream s1 (Cont r1) Char => ParsecT s1 u (Cont r1) b
at src/Helper/Parser.hs:21:52
Expected type: ParsecT s1 u (Cont r1) b
Actual type: ParsecT s u (Cont r) b
Relevant bindings include
cc :: a -> ParsecT s u (Cont r) b
(bound at src/Helper/Parser.hs:21:29)
In the second argument of ‘($)’, namely ‘cc v’
In the expression: Do $ cc v

src/Helper/Parser.hs:21:57:
Couldn't match type ‘r’ with ‘r1’
‘r’ is a rigid type variable bound by
a type expected by the context:
Stream s (Cont r) Char => ParsecT s u (Cont r) a
at src/Helper/Parser.hs:21:14
‘r1’ is a rigid type variable bound by
a type expected by the context:
Stream s1 (Cont r1) Char => ParsecT s1 u (Cont r1) b
at src/Helper/Parser.hs:21:52
Expected type: ParsecT s1 u (Cont r1) b
Actual type: ParsecT s u (Cont r) b
Relevant bindings include
cc :: a -> ParsecT s u (Cont r) b
(bound at src/Helper/Parser.hs:21:29)
In the second argument of ‘($)’, namely ‘cc v’
In the expression: Do $ cc v
>>
>>54528613
Have an excel spreadsheet I have to fill out and log what I did for the day to get paid. I keep forgetting until the last minute to fill out everything I did for the previous two weeks.
I've just been writing whatever my git commits say into my task descriptions for the day but that's tedious.
Just finished writing a small python script that's run as a post-commit hook which reads all commits since 00:00 of that day and writes it to the spreadsheet for me.
>>
>>54530911
Why would "and" be better than "if"?
[x * 2 for x in S and x % 2 == 0]

looks clear and more readable to you?

>I can tell it squares numbers in S if they are even
>It looks simple to me.
>it's perfectly fine.
what compelling counter arguments.
>>
File: I'll allow it.gif (986 KB, 500x243) Image search: [Google]
I'll allow it.gif
986 KB, 500x243
>>54530895
>it's a /dpt/ mercilessly but justifiably shits on js episode
>>
>>54530977
You're retarded assuming only 1 person is replying to you
>>
>>54530993
I didn't assume that. I was pointing something out about all the replies i got.
>>
>>54530977
Yeah.

It's a short notation for construct a set by doubling the members of S that pass x%2 ==0.

Standard shit.
>>
>>54530822
SELECT x * 2
FROM S
WHERE x % 2 = 0


Nigga, this shit is intuitive as fuck.
>>
>>54530908
Yeah, that's what I was dreading. It seems to work ok right now, but it's a shame that no language / compiler has a built-in kickass build tool

I feel like this is something Linus Torvalds should be doing.
>>
>>54530977
Except x in S binds x, so it's not in the same category than
x % 2 == 0
. and implies commutativity.
>>
>>54530977
I'd prefer WHERE, but I'm a database guy, so...

>>54531008
This
>>
>>54531007
Except it constructs a list
>>
>>54531007
>Standard shit.
In what?

>>54531008
Then explain why instead of just saying it is.
>>
>>54530977
you're being an obstinate moron right now
map(lambda x: x*2, filter(lambda x: x%2 == 0, S))

isn't much more clear
it's the same thing really
>>
>choosing
filter(lambda x: x % 2 == 0,
map(lambda x: x * 2, S)
)

>over
[x * 2 for x in S and x % 2 == 0]


Yeah nah family, I prefer the construct that makes sense if you've done basic math or english
>>
>>54531037
In fucking math. Don't CS majors have to take baby's first number theory and abstract algebra aka discrete math?
>>
>>54531039
i agree.
S.filter(x => x%2 == 0).map(x -> x*2);

is. You can read the logic left to right very easily. You can reorder and extend the operations easily too.
>>
>>54531039
Be real.
(for/list ([x S] #:when (zero? (remainder x 2))) (* x 2))


Schemic syntax is so consistent: almost everything is an expression, and binding goes before usage.
>>
>>54531037
>Then explain why instead of just saying it is.
It's intuitive for the same reason that TSQL is easy to learn and reads like English.

>Show me all of element 'x' from the set 'S' where x is even.

SELECT FirstName, LastName
FROM Students
WHERE LastName LIKE '%stein'


>Show me the first and last name of all of the jews at this school.

Pretty basic understanding of properties of groups of things.
>>
>>54531037
Set comprehension
Closer to English (you know, the thing languages try to approach through abstraction?)
>>
>>54531008
It doesn't make it explicit that x is being drawn from S, a big syntax bad design to me.
>>
>>54531070
Math notation doesn't make it into programming very much, unless there's no clearer way of describing the logic of what you want the computer to do.
>>
>>54531104
>It doesn't make it explicit that x is being drawn from S
Yes, it does.

The explicitness comes from the FROM keyword.

>Show me this element, from this set, but only things that meet these conditions.
>>
>>54531104
S is the only table there. It's an illegal query if x wasn't in S. It's only ambiguous when 2 or more tables are involved
>>
File: bobine.jpg (265 KB, 547x800) Image search: [Google]
bobine.jpg
265 KB, 547x800
>>54531102
>DWIM meme
M8 do you even Tractatus Logico-Philosophicus? Language restricts thought, better have as many different ones as possible to choose from.
>>
>>54531116
>I like stagnation over clarity
Thanks for clarifying
>>
>>54531116
You misunderstand the fucking point of programming then. Programming is all about abstraction. You shouldn't give a fuck how python gives you that list.

You try to avoid telling the computer what to do, but try to tell the computer what you want.
>>
>>54531128
what comes from S? it doesn't explicitely define x: the variable name is just floating around in the SELECT and WHERE parts, and you're supposed to guess its contents will be drawn from S without explanation.

>>54531129
Wait x isn't a local name? It's a column name? I admit I don't know SQL. What do you do when two tables have a column with the same name and you want both?
>>
>>54531129
>It's only ambiguous when 2 or more tables are involved
Which is why any sane DBMS forces clarification when there is ambiguity.

The following query is not valid in most DBMS, given a common 'FirstName' column:

SELECT FirstName, LastName
FROM Students s
JOIN Teachers t ON t.TeacherID = s.TeacherID


You would need to specify:
SELECT s.FirstName, s.LastName, t.FirstName, t.LastName
FROM Students s
JOIN Teachers t ON t.TeacherID = s.TeacherID
>>
>>54531158
If you're in a giant cushy interpreter, sure.
Feel free to ignore the implementation details of the list.
That shit doesn't fly if you actually want to write the interpreter tho.
>>
>>54531170
>>54531174
question answered in fact. I opiniate that it's an acceptable shortcut.
>>
>>54531170
x is a column, or element of the table, or set S.

See >>54531174
>>
>>54531170
>What do you do when two tables have a column with the same name and you want both?
`table1 name`.x
`table2 name`.x

you can use an alias like >>54531174 posted

>>54531174
Off course
>>
>>54531176
You realize that programming languages are abstractions of assembly/machine code right?

Objects and OO-languages can be written in C, for example since it's close to assembly. That doesn't mean people should use non-OO structures for emulating OO functionality, when an OO language can give you that functionality easily

Same goes with choosing to implement functional programming in C (which I'm sure some are) over just using a functional programming language

So why limit yourself when it comes to simple and short list comprehensions?
>>
>>54531189
>>54531196
How bad does it feel that SQL can't into α-conversion?
>>
>>54531176
>That shit doesn't fly if you actually want to write the interpreter tho.
THANK YOU CAPTAIN OBVIOUS.
Plus it's not even true, PyPy exists. Also bootstraping techniques, etc.
Thread replies: 255
Thread images: 24

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.