[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Voyeur Cams | Click for more| Home]

/dpt/ - Daily Programming Thread

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.
Voyeur Cams

Thread replies: 378
Thread images: 23

File: trap programmer.png (1MB, 1702x2471px) Image search: [iqdb] [SauceNao] [Google]
trap programmer.png
1MB, 1702x2471px
Previous thread: >>51443261

What are you working on, /g/?
>>
First for C.
First for functional programming is fucking retarded.
First for people who like traps are 100% faggots.
>>
porgramming in MIPS assembly
>>
So I have two tables, and I'm trying to set "projectScore" equal to "projectAvgScore." I tried just making projectScore a Foreign Key in the PROJECTSCORE table, but I kept getting an error in foreign key constraint of table. I've spent the last 3 hours trying to fix it but can't fucking figure it out.

create table PROJECT (
projectID int(10) NOT NULL AUTO_INCREMENT,
studentFName VARCHAR(20),
studentLName VARCHAR(20),
projectScore int(2) NOT NULL,
divisionNum int NOT NULL,
categoryNum int NOT NULL,
PRIMARY KEY (projectID)
)ENGINE=InnoDB;


create table PROJECTSCORE (
projectID int(10) NOT NULL,
projectAvgScore int(2) NOT NULL,
judgeCounter int,
scoreSum int,
FOREIGN KEY (projectID) REFERENCES PROJECT(projectID),
PRIMARY KEY (projectID, projectAvgScore)
)ENGINE=InnoDB;


The SQL command should be:
INSERT INTO PROJECT (projectScore) SELECT projectAvgScore FROM PROJECTSCORE WHERE projectID = 1;


This adds a projectID = 21 instead updating projectID = 1
>>
I did one of the moderate challenges on codeeval and now they're giving me links to apply for jobs.
Are these legit or just generic job listings?
>>
>>51449776
legit if you live in the states. sends your resume over. you are one of many though.
>>
>>51449735
What if I write C while dressed like a girl?
>>
>>51449735
Yeah, if you like developing shit slow as fuck (but hey, at least it runs fast, right?). For the people with more mental plasticity than you and who actually want to get shit built, >>51449847

>still using Java/C/C++ on the regular
>shiggy
>>
>>51449928
functional programming is a meme
>>
>>51449735
What we call functional programming is somewhat of a shibboleth for good-taste programming. We prefer the best programming languages, like Ocaml and Clojure, but we don’t actually restrict ourselves to writing functional programs. Do we use C when it’s the right tool for the job? Hell yeah. Do we put mutable state into a program when it makes it simpler (as is sometimes the case)? Hell yeah. On the other hand, we trust the aesthetic and architectural decisions made by brilliant, experienced, gray-bearded engineers far more than we trust business fads.
>>
>>51449952
You know how I know you've never solved any non-small real-world problems in a reasonable time frame?
>>
>>51449986
Because you've never done it either?
>>
How do you compare dates in SQL? I have a DATETIME field that only contains a date (no time), and I want to compare it to a string with the same formatting (dd.mm.yyyy).
But when I do this:
SELECT [ID] FROM [Table] WHERE [date_field] > '01.01.2015';

It gives me records from before that date as well.
I'm not sure what kind of database this is (oracle etc.), only have remote access.
>>
File: 1444378145195.png (2MB, 1696x2467px) Image search: [iqdb] [SauceNao] [Google]
1444378145195.png
2MB, 1696x2467px
>>51449882
then you've become a living meme
>>
>>51450021
>>51449718
who the fuck keeps making these?
>>
>>51449988
I finish shit, motherfucker. Why would I use anything low-level if the problem doesn't require it and high-level techniques get it done faster and with less code?

Why would you use C unless you're working close to the hardware? Why would you use C++ unless you're working on a 3D game engine or embedded systems? And why do all the best-performing companies in my area doing actual software development want Clojure and Scala devs, despite everyone claming "there are less jobs in FP"?
>>
>>51450042
autist
>>
File: Variables2.png (26KB, 481x1173px) Image search: [iqdb] [SauceNao] [Google]
Variables2.png
26KB, 481x1173px
So I'm not a programmer really, working on it. and I'm making a turn based RPG combat game

I've read up on tables and how I should be using them more, I kind of get them now, but don't see how they can do this

But is there a faster way to transfer loads of variables onto other variables? I mean this isn't too slow since I set it up so I could easily copy and paste it, but there has to be a better way right?


The Variables with P are player variables, so they store the player's character(s) info, and the T variables are temporary variables for storing in battle info

There are 8 character slots, and current 4(later 8) in battle slots with 4 as a front row, and I'm going to add a back row mechanic later.

So I need to be able to move the permanent variables into temporary ones for battles, and I'll be turning each into it's own function so it can refresh at will.

tl:dr:
How do I make a bunch of variables equal a bunch of other variables faster? Otherwise I have to write this out at least 32 times, and probably hundreds of times for enemy variables

Yes I realize my variable names are horrible, going to stick with (Capital)(lower case(Number)(letter) from now on rather than having half of them be all caps
>>
>>51450220
>that code
I had a sudden glimpse of the abyss. What language is this?
>>
Look up arrays.
They're incredibly useful.
>>
http://lmgtfy.com/?q=How+do+you+compare+dates+in+SQL%3F
>>
>>51450220
DRY = Don't Repeat Yourself

For example, you could have an instance of the character with all that data. Then you'd place that instance into a party/battle/whatever slot, and could refer to that character's equipment through that slot. Or if you want you could have a table (or other collection) and clone it.

Basically, read up on arrays, (hash)maps, enums... they will make your job incredibly easier.
>>
>>51450283
>>51450005
>>
>>51450276
Lua
>>
>>51450295
But the temporary variables can change in battle freely, and the permanent variables hold important info that's permanent since you can lose HP/MP in battle
>>
>>51450426
A character should have a max HP (pool size) and a current HP.
>>
>>51450283
>>51450299
why respond when you cant help? kill yourself, of course ive tried googling this shit
>>
>>51450444
but the temporary variable already does that job, and the max HP for the game is 50, characters can gain bonus HP however
>>
>>51449735

http://conal.net/blog/posts/the-c-language-is-purely-functional
>>
>>51450515
I bet you haven't even figured out structs yet.
You can literally assign an HP/MP/condition all at once and treat it like a single data structure.
You can even use it like a data type and make an array of type PlayerCharacters.

Seriously, go learn some programming before you make something worth turning into a CS grad meme.
>>
>>51450513
Try google a bit more.
>>
>>51450546
I know of structs,couldn't get the code from the website working though

And I'm not sure how putting my data into a single structure would help it, wouldn't I have to remember the order of it inside the struct/table?
>>
>>51449735
But Haskell and C go along like bread and butter.
>>
>>51450585
Try (hash)maps. They consists of keys paired with values. So your keys would be strings like "currentHP" and values would be ints and what not. Then you could get the value by calling the corresponding key in the map.
>>
>>51450614
But isn't that the same as just having variables with X name?
>>
>Can someone give me a hint for how to solve the 0/1 knapsack problem. I keep coming up with solutions but they're all greedy
>>
>>51450635

Only sort of. You'll be able to access and modify them in mostly the same way, something like

map["CurrentHP"] = 100;


But they do what data structures do best: make everything look less like a pile of hot garbage.
>>
File: rage.png (20KB, 381x400px) Image search: [iqdb] [SauceNao] [Google]
rage.png
20KB, 381x400px
Trying to fix annoying rounding errors in my GUI's scrollbar code.

No matter how carefully I calculate the thumb position and size, I can always find some combination of total size, visible size and scroll position that causes a rounding error and annoyingly leaves a small one-pixel crack somewhere. Fuck!
>>
>>51450684
Snap to the edges if it's <2 pixels to the edge or some shit.
>>
>>51450667

Use the double penetration approach. Fairly straightforward, but it's not as space efficient.

Here's a professor's lecture on the problem:

http://cse.unl.edu/~goddard/Courses/CSCE310J/Lectures/Lecture8-DynamicProgramming.pdf
>>
>>51450702
But that's a hack! I don't do hacks!

Shit. I'm afraid I have to hack it unless I want to waste my whole day on this... :-(
>>
>>51450737
Then enjoy your floating point arithmetic.
>>
>>51450737
>But that's a hack!

As far as hacks go, that barely scrapes the surface of shittiness.

It could be much, much, worse.
>>
>>51450791
>>51450753
It's currently all-integer code.

It's not that I can't hack the calculation. I did that. But that hack then messed up the code that calculates where to scroll the screen when the scrollbar is dragged with the mouse. So I hacked that part too. But that caused problems in yet another place. So it's hacks piled on top of hacks. The original code was 15 lines, now it's 30 with hacks. I can't accept that.
>>
>>51449865
> ()))})($(
> the best

are you for real
>>
>>51450862
How about fixing those rounding problems then.
>>
>>51449760
POST THE ERROR MESSAGE, DUMBASS
>>
>>51450684
In C, integer division and converting a float to an int truncate rather than round.

Also, with floating point, x*(1/y) is typically not equal to x/y even when x is an exact multiple of y. So don't calculate a scale factor a/b then multiply y=(a/b)*x. Store the scale as numerator and denominator and calculate y=(a*x)/b using integers.

There may be other issues. In particular, whether the scale factor (ratio of scrollbar movement to document scroll offset) is less than or greater than 1 probably need to be separate cases. The latter is typically more complex, as not all possible scrollbar positions are used, and you want to ensure that the used positions include the minimum and maximum.
>>
>>51450545
>C is purely functional
>by the way, I'm talking about C preprocessor, not about actual language
>a lot of parts of C preprocessor are functional, except for those cases where it is not
>and that means C is purely functional

is this a joke or is that guy a retard
>>
File: 1447042753722.jpg (424KB, 1920x1200px) Image search: [iqdb] [SauceNao] [Google]
1447042753722.jpg
424KB, 1920x1200px
>>51449718
Working on a higher or lower card game, I am extremely new to programming and I am on babby's first logic error. Been stepping through each piece of code for an hour, still can't figure it out.

What do you /g/ents do when you are stuck on a logic error?

This is C# by the way.
>>
>>51450978
> you want to ensure that the used positions include the minimum and maximum.
scrollbar_offset = document_offset * (scrollbar_range-1) / (document_range-1)

Where
scrollbar_range = scrollbar_height - thumb_height
document_range = document_height - viewport_height

The -1 is necessary to avoid leaving a space below the thumb when you're at the end of the document.
>>
>>51451042
how about you post the fucknig error
>>
>>51451058
There is no error, it is a LOGIC error. Nothing shows up, it is just doing something it is not supposed to do.
>>
>>51450005
dd.mm.yyyy is usually not valid SQL datetime format. Try to determine and use correct format. You may also try casting/converting into datetime.
>>
Trying to FizzBuzz on codeeval.
Failed due to the entire thing being in comments (I didn't notice bacause I haven't used Python in a while and there's no syntax highlighting so I just didn't care). This is probably why FizzBuzz have such a great failure rate.
>>
>>51451069
Talk to a duck.
>>
>>51451042
Calculate each result yourself and check if it matches with the output of your application.
>>
>>51451113
I tried talking to a picture of a black guy, but it isn't working fuck.

I swear to christ 70% of programming is thinking of what to do, 15% going through my shitty code, and 15% actually coding.
>>
>>51451069
The error is your code, post the code and describe the error.
What I do:
>make the following method:
private void write(string s, params Object[] args)
{
Console.WriteLine("[" + s + "]", args);
}

>call method for every area where there's updated variables (usually inside a loop or before an if statement)
>make sure variables are what I actually want
>when the problem's fixed comment out Console.WriteLine
>delete the call to write when you finish
Before you ask, I use a custom write method so I can change it between writing to textboxes/console/etc whenever necessary and to add those square brackets to make sure I can see the whitespace.
>>
>>51451163
Uh, you don't know how to step through with a debugger?
>>
>>51451236
Yeah but that's annoying. With this it's guaranteed write once and every time something happens it automatically updates in the console (for example, mouse movement).
Hell, the only time I really use the debugger is to quickly break at specific lines to check the data of large objects or to tell me that event's actually being called.
>>
File: pgrammerfuel.jpg (67KB, 687x720px) Image search: [iqdb] [SauceNao] [Google]
pgrammerfuel.jpg
67KB, 687x720px
>>51451042
Oddly enough your problem can be fixed by reciting/explaining your code out-loud to someone else or an object. If it is a logic error it would sound retarded to say out loud and you'd find it fairly quickly.
>>
>>51449718
fuck what's the name of the original
>>
I just reinstalled win, and now visual studio recompiles everything even if there are no changes. What's wrong with it?
>>
>>51451009
>is this a joke

Yes.
>>
looking at making a giant robot MOO. mite b fun.
>>
>>51451163
1. You could make it so it only prints the shit in Debug builds
2. You could parameterize the output stream
And then you can just leave it in and have excellend debug output when you want and none if you don't, also redirecting it to a file would be a breeze.
Unless C# can't do that. Which would make me very sad.
>>
>>51451411
System time is wrong, files' last modification date is in the future.

Also, the obvious
>installed win
>>
>>51451472
You probably could do that, I'm just too stupid and/or lazy to do it.
Was also thinking of just making it a public method in some utility class that took an extra argument (error number or something) so I can turn off some and keep others active.
It's hardly a professional solution.
>>
>>51451479
>System time is wrong
most likely since even after setting the tz, the clock is still ~10 hours into the future
shouldn't windows pull that clock from the internet?

>installed win
because I fucked up my arch install, had to format the drive, do it all over again :^)
>>
Hi, /dpt/.
I have a 30GB SQL database file thing that I need to work with. The problem is that I've never worked with any DBMS other than redis. So trying to fuck around on my own in mysql isn't helping me understand it.

Can anyone recommend a good beginner's tutorial for MySQL?
>>
>>51449718
>What are you working on, /g/?
The official /dpt/ C toolkit: a sate of art, community driven, FOSS, general utility library for C.
>>
>>51451536
>shouldn't windows pull that clock from the internet?
Yeah, I have the activated as well. It just never does it. Always have to do it manually.
>>
>/g/ programmers have an unusually high ratio of C "it's the most hardcore" fanboys
>4chan has a high ratio of NEETs

Hmmmm
>>
>>51451614

It's probably just a coincidence.
>>
>>51451690
None... none of you have jobs, do you?
>>
>>51451697
Stop reminding me how much of a useless piece of shit I am ;_;
I never feel qualified (hell, I'm probably not) and I'm really not sure what area I'd want to go into.
>>
>>51450069
The C cultists here aren't real programmers and just write toy programs to have open in desktop threads.
>>
>>51451697
Joke's on you, I do have a job.
>>
>>51451697

I'm going to school, and I also had/have job(s). In fact, I think most people on /dpt/ are employed, it's just that there's an unusually high concentration of neets here.
>>
>>51451266
No, it's not annoying, it's much faster and better. Peppering your code with random print statements and making sure to track them down and remove them later is annoying.
>>
>>51451768
>>51451772
And what languages do you use for real work? And which would you use if you had the freedom of choice? Let me guess, neither is C.

>>51451797
I think the right way to do debug print is to have it controlled by a single global debug flag (or build setting). So you don't need to comment each one out.
>>
>>51451797
>right click method
>call hierarchy
Better yet:
>delete/comment out method
>errors highlight where they are
But yes, take extra time pausing while you step through or to retype shit and getting an output that takes extra time to read because you didn't format it yourself.
>>
>>51451822
>what languages do you use for real work?

Whatever becomes necessary. C++, Java, or C# for Wandows.

It depends.

>which would you use if you had the freedom of choice?

C#. It's too good.

>Let me guess, neither is C.

You win.
>>
>>51451797
Stepping through the debugger to track down problems quickly becomes very pointless as soon as multiple interacting threads are introduced.
Debug statements also skew the time relations, but not nearly as bad as that.
>>
>>51451766
I can confirm that as a professional C programmer. I come here for the laughs.
>>
>>51451822
I'm and Android developer, so most of my work is in Java. I would only use C if I had to do embedded stuff, which I don't. Using C for general application development (i.e. 'apps') is just batshit insane. C is great if you want to know exactly what is going on. That's why it'll never fade away in the embedded industry or software that has to interact with drivers. C is also useful for educational purposes, since it lacks basic functionality like sorting, dynamic arrays etc.
Ideally I want to do less UI work. Android is full of 'muh material design' hipsters. I've been to several Google events and it's amusing to see how material design advocates are praising material design. Either writing b2b software or backend development.
>>
File: out.webm (485KB, 768x832px) Image search: [iqdb] [SauceNao] [Google]
out.webm
485KB, 768x832px
>>51449718
The code for a settings dialog. (only the sync page and half of the vo settings are working at the moment.)
>>
>>51451888
>Stepping through the debugger to track down problems quickly becomes very pointless as soon as multiple interacting threads are introduced.
Why do you say that?
>>
>>51451963
If you had read the post to the end you'd already have your answer.
>>
>>51452045
I did, but he didn't explain why a debugger is pointless in multithreading situations. He just claimed debug statements were better.
>>
>>51452086
Are you trolling or fucking dense or have you never had to debug multithreaded programs before?
>>
>>51452139
I do it all the time. Debuggers are particularly good for it.
>>
>>51452086
>>51452139
No wait, maybe you are just retarded. Let me start off differently. With a quiz.

If you have a multithreaded application which does stupid shit because of threading errors, what could happen if you change the time either of the involved threads requires to process its data?
>>
File: C.png (136KB, 2000x2126px) Image search: [iqdb] [SauceNao] [Google]
C.png
136KB, 2000x2126px
>>
>>51451944
This is starting to look really nice. Keep up the good work. I think a lot of people are waiting for a good mpv GUI and Linux MPC-HC alternative.
>>
File: mathtex.gif (4KB, 274x80px) Image search: [iqdb] [SauceNao] [Google]
mathtex.gif
4KB, 274x80px
if a i have a view matrix with a layout like pic related and want to multiply it with a Vector4, do i multiply it as is (red) to calculate the X coordinate of the resulting Vector4 or do i need to transpose it first (blue)?
>>
>>51452207
what the fuck
i dont know why 4chan fucked up the picture
>>
>>51452160
>what could happen if you change the time either of the involved threads requires to process its data?
lots of things synchronization issues, race conditions etc. But I would imagine most of those would be errors in the code anyways. You shouldn't really have code that's dependant on a thread finish certain tasks within a certain amount of time, since that is typically not very predicable. Especially for the kind of work that separate threads tend to be created for.

I'm not really sure what you're saying though. Using a debugger must suck because it will probably break something? When you break in C#, all threads a paused. The debugger lets you see the call stacks of all the currently running threads. So I'm not sure where an issue is likely to come up.
>>
>>51449970
lmao the only time lets say, a lisp is "the right time for the job" is when you're sitting around circlejerking with your boyfriend and one of you can only get off to parens, 2bh senpaitachi)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
>>
>>51452354
tool*
>>
How do I start contributing to open source projects dpt?
>>
File: 1435317768008.jpg (43KB, 402x480px) Image search: [iqdb] [SauceNao] [Google]
1435317768008.jpg
43KB, 402x480px
>>51452458
1) Find open source project
2) Contribute to it.
>>
>>51452253
>But I would imagine most of those would be errors in the code anyways.
No fucking shit.
Why even use a debugger? Just write correct code.
>>
>>51452487
Thanks, Anon!
>>
>>51452565
Because the debugger wouldn;t cause any extra problems with that anyways, and in fact is rather excellent for getting to the bottom of them. The .NET one at least is.
>>
>>51452646
Any changes in thread runtime can make existing problems disappear. Regardless whether you only stop the thread you're debugging or you're stopping all of them and just step through one.
>>
>>51452683
Sure, that's *possible*. I've been in a situation like that personally. That hardly makes multithread debugging "pointless". It can be incredibly useful the freeze all threads, and see what the current state of each thread is at a given time to learn more about what might be causing you problem.
>>
I wanna do something low level. I'm fucking tired of web apps and shit. wat do?
>>
>>51452854
I feel your pain. Tired of all this 'web app' faggotry
>>
>>51452854
Buy Arduino.
>>
>>51452854
Make a VM.
>>
>>51452854

Android App
>>
What are some good programming sites to keep up with? I love reading programming articles but it feels like every programming site has turned to mostly navel gazing programming culture discussion and "language hits version 1.X!"
>>
>>51453355
stack overflow is the only one i use
>>
>>51453355
>>51453465
>stack overflow
only programming site that actually focuses on programming
>>
>>51452207
As is, red, provided that you do matrix times vector and not vector times matrix
>>
File: index.jpg (11KB, 195x258px) Image search: [iqdb] [SauceNao] [Google]
index.jpg
11KB, 195x258px
Is this book still worth reading, even with the outdated code examples and instruction? And if so, why?
>>
I am practicing with some standard coreutils like grep, sed and sort. Right now I'm trying to sort the output of last by the day of the month on which the user logged in, regardless of month. so I tried something like this
last | sort -n -k6,6

But some numbers are still out of order when I do that. What would be the correct command?
>>
>>51453994
It's a great book if you're new to C. Once you've finished the book, read up on the latest C standard.
>>
Why would anyone unironically program in Brainfuck?

That syntax is hard to understand for the sake of being hard. A better solution is just program in Assembly, which is literally computer language and thousands of times faster.
>>
>>51454041
Are you retarded? Why do you think the language is called Brainfuck?
>>
>>51454041
As a challenge
Using it to train other key concepts like writing interpreters/compilers
Perhaps to reason about things, since the language is so small (unlikely)
>>
Guys I'm trying to display a chart with ASP.NET MVC from a Mysql database. I have found hundreds of online tutorials but none is working for me.
If I try to do it directly in the view then I get an error
>{"A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)"}
@using WebMatrix.Data;
@{
var db = Database.Open("MySQLConnection");
var data = db.Query("SELECT user_IP, user_Country FROM user_stats");
var myChart = new Chart(width: 600, height: 400)
.AddTitle("Naslov")
.DataBindTable(dataSource: data, xField: "user_IP")
.Write();

}
>>
>>51454053
Are you blind? Those nigger cocks on your eyes are preventing you to read "unironically"?
>>
>>51454077
you really should be doing this stuff in the controller and not in the view itself
>>
>>51454087
You're still retarded for asking stupid questions.
>>
>>51454097
I know, the view was my last resort since I tried doing it in the controller but I get an error
>data does not exist in the current context
        private void chart(String userIP, String userCountry)
{
cWebTrafficDb checkUserStatsWrapper = new cWebTrafficDb();
checkUserStatsWrapper.cmd.CommandText = string.Format("select * from user_stats where user_ip = '{0}'", userIP);
MySqlDataReader reader = checkUserStatsWrapper.cmd.ExecuteReader();

cWebTrafficDb insertUserStatsWrapper = new cWebTrafficDb();
var myChart = new Chart(width: 600, height: 400)
.DataBindTable(data, "Name")
.AddSeries("Default",
xValue: data, xField: "Name",
yValues: data, yFields: "Price");
}

Disregard the select and variables.
>>
Hey /g/. I have a C struct (struct1) that contains a pointer (struct1.pointer) to another struct (struct2). When I first initialise struct1, I set its struct1.pointer to NULL. Then, later, I change it with struct1.pointer = malloc(sizeof(struct2*)). The problem is that I get a memory corruption error in the malloc. Am I doing something fundamentally stupid here ? It seems that the error disappears when I do not set struct2.pointer to NULL, but I get another crash somewhere else in the program because struct1.pointer contains garbage values.
>>
>>51449735
>implying you can't have a referentially transparent functional programming language with manual memory management and no GC
>>
>>51454399
Why not just sizeof(struct2)? You are trying to dereference it with that asterisk, aren't you? If so, what are you trying to dereference exactly?
>>
This fucking C++ ebook I'm reading for an EE course is ridiculous

sometimes it's the little things:
   string lineString;        // Holds line of text
>>
>>51454480
Because I'm one dumb motherfucker.
Thank you Anon.
>>
Why are programming textbooks so awful? I'm really starting to think that the grim truth about programming is that if you don't start young, you're pretty much fucked. Something about how kids learn and blah blah blah, but the stats say that programmers pretty much never read books on the subject. And I have literally never met a decent programmer who wasn't at least a middle class white kid who played Doom and shit, even curries start young. Name one well known programmer who started past age 18.

The learning curve seems really weird, it's not like other difficult subjects. With stuff like graphic design you can pretty much just gruel through it and make progress, but with coding you seem to either get it or you don't, and I've spent hours getting almost nowhere. Website tutorials on programming are terrible, textbooks on programming are terrible, so how the hell are people learning to program?
>>
>>51454534
Are you learning by yourself, or is someone teaching you this stuff while you are reading up on programming?
>>
>>51454534
Internet resources are often written by people who don't know what they're talking about themselves.
Textbooks are often written as a supplement to university courses.

You're just finding inappropriate material.
>>
A alternative lexical analizer generator, the idea is replace the old Lex and Flex
>>
>>51454534
buy books about programming in a book store. not university text books.

What kind of stuff are you trying to learn?
>>
>>51454564
>>51454568
I'm learning myself and wasting weeks on bullshit.

What typically happens:

>hey this book looks good
>starts by explaining the difference between software and hardware
>of course I already know this because I'm not 5 years old
>next page: wall of text involving a shitload of unexplained concepts that I only vaguely know from reading and giving up on other programming textbooks

It's retarded, a book will assume you don't know the difference between hardware and software, then the next page expects you to be compiling from notepad. I'm getting nowhere because instead of working through the books like any other subject, I'm getting progress-halting stuck on every other page.

>oh look here's a simple concept he could have explained in two sentences and it's mired in such obfuscated language that it took me 3 hours on google to realize I need to use single quotes instead of double quotes
>>
>>51449718

Where do you guys get ideas for projects? I'm here learning Python (coming from Java/Android) but I have zero ideas on what to build.
>>
>>51454647
You know, you're allowed to Google specific things you don't understand when reading a book.
>>
>>51454534
You don't need to start programming early in life, but your brain probably needs to have a proclivity for math/logic in order to easily absorb programming concepts. I started programming when I was 22 and I've had no problems.
>>
>>51454627
I've tried books on C++, Java, and Python, but I would prefer to actually have a solid foundation of knowledge that seems to come with knowing a low level language.
>>
>>51454534
>filename
kek'd
>>
>>51454660
read in a list of names and numbers and store them in a binary search tree based on the name
>>
>>51454664
Reread the last line of the post.
>>
>>51454683
so... get a book on C then? What are you trying to accomplish with programming?
>>
>>51454695
Alright, I'm not sure what your problem is then, other than having ADHD.
>>
what's 'dynamic programming'?
>>
>>51454689

Lol I don't wand to build some shit algorithms dude, that's boring.
>>
>>51454683
you need K&R
>>
>>51454716
programming with a dynamically typed programming language.
>>
>>51454716
Marketspeak for "memoization".

>>51454749
No.
>>
>>51454749
C++?
>>
>>51454697
What is a book on C that doesn't go from

>here's the difference between software and hardware

to

>lmao hack into the FBI mainframe and defeat the matrix

on the next page? That's pretty much my only criteria. Haven't checked out any books on C but what are some good ones?
>>
>>51454762
>having trouble with the command line
>>
>>51454647
What book(s) are you reading? Post some of the concepts you feel were just "dropped" on you.
>>
>>51454761
that's statically typed, not dynamically typed.

>>51454762
Dunno. But then I haven't read any books like that before either. A thing with learning a programming langugae sometimes is that there's a lot of concepts you have to understand at the same time before you can understand how anything really works. There's no avoiding things appearing complicated at the start. But if you read a good book on it from cover to cover you should know everything you need to know to write good code.
>>
>Foundations of Python network programming

Anyone read this? I'm thinking of doing some networking programming.
>>
>>51454647
>notepad
There's your problem. Get into Linux and you'll find programming a lot more convenient and easier to understand.
>>
>>51454399
>sizeof(struct2*)
That's returning the size of a memory address I think? In which case that almost certainly ends horribly.
>>
>>51454534
I was similar, I couldn't understand it for the life of me, you just have to have it explained in a way that makes it click.
I think my main problem was while I was reading it I wasn't actually understanding it, I was just reading it and hoping information stuck (that's what happens when you go from college to uni I suppose). Don't treat it like a normal book.
Also, the exercises in those books are really useful for a beginner, be sure to do them.
>>
>>51451869
>C#. It's too good.

show me a real problem that you actually solved because it seems like you're retarded
>>
>>51454850
Why not Go?
>>
>>51455017

I wanted to learn python and know nothing about network programming besides building some simple servers and such, so I thought it might be a good idea. Do you suggest otherwise?
>>
>>51455053
I'm not very familiar with Python, so I cannot help you.
Someone on /dpt/ suggested me using Go for my server and I'm pretty happy with it. But that won't help you if you want to learn Python.
>>
>>51453355
define programming sites
what kind of topic gamedev/webdev/embeded/...?

if you have problems/ need code examples use google which will probably lead you to stackoverflow 90% of the time

General Programming news, dunno, might be interesting if someone knows a good site. For specific topics/languages I use google and check out latest blog posts or official websites.

I also occasional listen to some presentation on InfoQ.com.
>>
ignore tranny threads

report tranny posters
>>
>>51455110

I don't even know dude, I think I'll just skip Python for now. I have literally no idea on what to build with python and just further reading books is pointless now. I've already read the official tutorial.
>>
>>51455110
are you a noob? if so, did it take you long to learn Go?
I'm happy that people are happy with Go, but I wonder how much time would it take for a noob to learn Go.
>>
>>51454983
C# is one of the best productivity languages out there though.
>>
>>51455295
Not >>51455110, but I've been looking at Go recently as well, seems like a fairly beginner friendly language.
>>
>>51455383
>no macros
>shitty templates, no specialisation
>>
Hey /g/uys just started learning Java this month and so far I still am pretty new. Although I have this idea for a website that I think has quite a bit of potential. Just wondering if anyone could give me some advice.

What should I learn if I want to create my own website?
Can my (future) knowledge of java be used in developing my website?
Also would any experienced programmers here be interested in talking with me?
>>
>>51455429
doesn't have macros, but has a lot of other nice things.

What do you mean by specialisation?
>>
>>51455503
template specialisation

and macros are a big deal
>>
>>51445700
>>51445717
>>
>>51449928
>>>51449847
I was thinking "good parody, OP" and then I googled the text.

Functional programming is the programming equivalent of those fedora atheist memes.
>>
>>51455525
I know. And C# has a lot other nice features too.
>>
>>51455554
doesn't have template specialisation
doesn't have macros
forced garbage collection

it's shit
>>
>>51455552
someone post the article where they compare functional programmers to cult members
>>
>>51455410
you sure? the slices vs arrays thing is kinda difficult to explain. also, variable shadowing, error management, ... and let's not even talk about concurrency
>>
>>51455629

there's no comparison needed, they're one and the same
>>
>>51455585
>forced garbage collection

This is how I know you don't know shit. And here you were trying to call me out.
>>
>>51455585
if you like metaprogramming so much why don't you try a language with real macros?
>>
>>51455585
there are dialects of C# without any GC and there's also a way to disable it inside parts of your code. please go read up on this shit before you start arguing about it
>>
Just let me get this straight.

When you talk shit about "functional programmers" are you talking about "people who use functional programming languages" in general or about "people who talk about how using functional programming languages makes them superior"?
>>
>>51455676
Fuck off speech impediment, C++ macros are turing complete

>>51455663
It specifically calls it unsafe, it actively doesn't want you to use it
>>
>>51455720
there isn't that much of a difference
>>
>>51455733
Well, there's a pretty big difference between essentially attacking functional programming itself and attacking those who use it to act elitist.
>>
>>51455727
>C++ macros are turing complete
so is brainfuck
>>
>>51455663
Is shilling for C# all you ever do in these threads?
>>
>>51455663
>TRIPCODE
>>
>>51455585
Why so salty?

Managed memory is nice when you can spare the performance costs. There's awesome debugging tools like being able to edit code on the fly. async/await keywords are extremely useful these days.
>>
Daily reminder - if your language doesn't have partial specialisation, it doesn't have templates and it doesn't have generics
>>
Why have templates when you can have dependent types and pattern matching over those types?
>>
>>51455727
>It specifically calls it unsafe

Fair enough, but it also means that GC is not forced. And it's not even akin to sun.misc.unsafe because it's sticking around, just for interop reasons.

>>51455760

Nah, I actually don't talk about C# that much.
>>
>>51455819
because complex type systems frighten most programmers (probably since they're so heavily based in math)
>>
>>51455819
>tfw you've never used templates
>>
>>51455585
What kind of stuff can you do with templates that can't be done with generics just as easily?
>>
>>51455899
see >>51455819
also see any decent use of templates ever
>>
>>51455899
Templates can do more than just types. You can have them take values (units of measure in C++ do this: http://www.boost.org/doc/libs/1_55_0/doc/html/boost_units/Units.html) and they can be partially applied.
>>
>>51455925
Templates aren't fully dependent types, they're just type-level programming.
>>
File: fug.png (97KB, 499x504px) Image search: [iqdb] [SauceNao] [Google]
fug.png
97KB, 499x504px
Hey guys, is C a good language for learning, or is the whole 'more efficient coding in other languages after learning C' thing a meme?
>>
>>51455960

You should learn it just for the sake of learning C. It'll come in handy at some point.
>>
>>51455930
What's the point though exactly? Why pass a value to a template when you can just pass it to a real function instead?
>>
What is the proper way to delete all data in a hashtable in c++?

it consist of a string and a pointer.
My plan was to loop through the table and call delete on all the pointers and then clear the table but that is not possible.
For now I just call delete on all pointers but I would prefer to remove the indexing string as well.

What is the approach?
>>
>>51455960
Learn C, Forth, Common Lisp, Java, Prolog and Haskell.
Then you can pick any language you want and stick to it, because you will have mastered every paradigm in existence.
>>
>>51456075
good list
>>
>>51456087
Thanks. I feel like it might be lacking something actually. Any ideas on what's missing?
>>
File: C++.png (66KB, 1418x624px) Image search: [iqdb] [SauceNao] [Google]
C++.png
66KB, 1418x624px
// Daily Valid C++ Reminder //
>>
>>51456016
It has the same point as dependent typing. It lets you move code into the type system, both to save code from being used later and to have slightly increased safety (although dependent types are significantly safer than plain old templates).
>>
>>51456096
one of the array-based languages is the only real hole I can see
>>
>>51456075
Forth seems redundant, given C
Also, Haskell and Prolog could be coalesced into Agda or Idris
>>
>>51456126
Runtime edition

Meta<int> operator "" _mi(unsigned long long int x) { return store(int(x)); }
int main4()
{
return ((3_mi & 4_mi) | Demo<int>::Squared) >> Ty<Demo<int>::Sum>();
}
>>
>>51456075
>>51456149
>>51456154
We should make a "language wheel" (like the colour wheel), with the most important languages as "primaries" and so on.
>>
>>51456239
>with C++ in the centre because it's the best multi paradigm language
>>
>>51456126
>>51456237
what's the difference between brainfuck and C++?
>>
>>51456257
No, with C++ *near* the centre because it's that disgusting grey-ish looking colour you get when you mix different colours.
>>
>>51456274
That makes a lot of sense actually
>>
>>51456268
C++ operators are overloadable
>>
>>51455542
>fuck is C++ really the best language
yep
>>
>>51456154
>Forth seems redundant, given C
what the fuck ??
>>
>>51445700
The one I'm designing

>good templating
>macros
Dependent types

>operator overloading
First-class type classes + custom, mixfix operators

>is not interpreted
>has lambdas
Check
>>
>>51456338
>The one I'm designing

Which is?
>>
>>51445700
>>51456338
Oh, and it does have manual memory management

>>51456359
I've posted about it several times, the one with dependent/linear types
>>
>>51456368
>I've posted about it several times

Go on. :)
>>
>>51456368
Which is?
>>
>>51456268

I should point out it's only valid C++ once you have about 7 relatively short helper classes. The | and >> through and into functions are operators overloaded on a template class. The _mi is a user defined literal that automatically converts literals to literals of this class. The functions have some constraints - if you're using the compile time version, you need a struct that can be templated with the argument types and has a static Invoke function. (And you wrap it into an object with Ty<...>()).

Basically just a small library. The runtime example really is simple - it just has to take the right type. You could use inline lambdas if you wanted.

>>51456338
Do dependent types allow for partial specialisation?
>>
>>51456384
>>51456397
Unlike most projects on /g/, I've decided to just work on it and not make up a name/logo/CoC before it has any substance. So it's not really identifiable.

I'm the one always going on about linear capabilities and stuff like that.

>>51456415
What C++ calls template specialization is just pattern matching over types. So yes, "partial specialization" is definitely possible.
>>
>>51456483
>I've decided to [...] work on it

Well, you're already 90% ahead of most posters here.
>>
>>51456503
And I have actually gotten a good bit done. I've mostly formalized it into a type theory, although I've been reiterating on it and not making substantial (to someone on the outside at least) progress lately.
>>
>>51450220
Holy shit you fucking faggot you still haven't read up on tables? I told you to like two days ago. You aren't going to get anywhere programming video games if you don't know how to program.
>>
>>51456525

Sounds pretty neat, m80. Now, of course, I'm a retard about all this fancy type-shit and whatnot, but it'd be interesting to learn more about it, and take in a new language at the same time.

Keep us updated, I guess.
>>
>>51456483
no logo? why no logo? you should have a logo bro.
no logo = no real project.
>>
Why aren't you coding in nim, /dpt/?
>>
>>51456338
How do dependent types make for better macros? I'm sure he was talking about making the macro system more than text substitution by allowing the creation of language syntax like Rust.
>>
>>51450156
that could be anybody on this website
>>
>>51456415
>Do dependent types allow for partial specialisation?
You can partially apply the types~
>>
>>51456338
ayy same here, although im trying my best to incorporate a true macro system
>>
>>51456706
>like Rust
you mean like lisp right?
>>
>>51456774
Originally yeah. I'm not super familiar with Lisp, which is why I said Rust.
>>
>>51456706
Well, macros are just compile-time programming, and so are dependent types to a certain extent. I suppose dependent types aren't REALLY usable as a full macro system unless you have some way to access the AST of the language (like Template Haskell).

The presence of mixfix operators lets you do a lot of custom syntax. Idris also has a system that makes things like monad or arrow notation part of the standard library, so I'll probably look into that as well.

The thing about macros is that they're not really part of a language, they're ways to program the parser, at least when talking about compiled languages.
>>
>>51454041
https://esolangs.org/wiki/Joke_language_list
>>
don't forget to filter:
/^!/
>>
>>51456877
What have you done so far and what are your problems (specify)?
>>
>>51456871
Or maybe 'Anonymize' on 4chanX?
>>
Long time lurker, first time poster.

My dad has done programming for most of his adult life, and always wanted to teach me. The most I ever did was some Java scripts in Eclipse and some tinkering with an Android VM. That was years ago, and now I'm bored enough to get interested in it again.

Where should I start? Is there a pastebin or a beginners wiki I can read? I'm interested in stuff like C#, Python and Ruby. Or really anything else.
>>
>>51456903
you still see tripfag posts and it gets confusing when people refer to them by name
best policy is to filter tripfags and recursively filter any post that replies to a tripfag
>>
>>51456947

Thank you for posting.
>>
>>51456937
start wherever you like. What kind of stuff do you want to do with programming?
>>
hey guys can i get some help with a cache simulator?
"All further lines contain integer addresses that your simulation attempts to read from main memory through the cache, one per line."

How do I read from the main memory?
>>
>>51454087
>unironically using the word 'unironically'
>>
>>51456965
The user first inputs
# sets,
# lines per set
# bytes per block
m, where m is m-bit addresses
>>
>>51456961
I can't imagine I would enjoy doing it professionally, but I've always had tons of personal productivity program ideas floating around in my head.

I mostly want to use Python for visual novels and Ruby for personal websites, but I feel like that would be easier once I familiarize myself with a widely known and supported language (learn how to learn).
>>
Criisizing Go for not having generics is a joke. Generics is an example of why C++ is bad. C++ is not a 'multiparadigm' language, it has a single paradigm which is everything is inhertance based OO. The fact that everything is a class or sub-class is very constraining and a very narrow way of looking at programming problems. Design patterns have to be used to break out of this way of programming. You cant program imperatively because even things like strings, I/O, vectors are all part of OO. When you have to use preprocessing macros (thats all templates are, saying they are turing complete is stretching the definition) to hide code should be an indicator that something is wrong. C++ is dependent on macros to change the language because of its instance on being backward compatible with C. The core language of C++ can never be change so the new language standards are constant heaping on new template libraries to do things that would be trivial to add to languages like Go and D. C++ is a legacy language born out of tight memory constraints and primitive operating systems that forced the use of systems languages to write directly to memory. Those days are gone, and C++ should be gone as well.
>>
>>51449735
First for stop being a fucking faggot who doesn't know to use the right tools for the job.
>>
>>51456937
There are two good ways to start.
One is to pick a goal and work towards that.

Make your self a project that you would like to have the end result of or make a project which seems like it would be doable.

Then make a design and make a set of sub goals needed to make it work.

Another way is to get a book which describes a lot of things about the language you want to learn.
Then make a lot of small projects using the stuff covered in that book.

What is your background?
Maybe there is something there which can help determining what would be a good starting point.
>>
>>51457019
>functional programming
>traps
>ever the right tools for the job
>>
File: 1444050396299.png (91KB, 875x593px) Image search: [iqdb] [SauceNao] [Google]
1444050396299.png
91KB, 875x593px
>>51456820
>>
>>51456529
I read up on tables and get them to some degree, but I don't see how it's going to help me accomplish what I need to do
>>
>>51457028
I might have to try the book method first, haha. Thanks much anon.
>>
>>51457078
>reverse("hello", 5);
The problem lies here, the space where strings are stored is readonly
use
char hello[] = "hello";
reverse(hello, sizeof hello);
>>
>>51457078
"hello" is char const (you can't alter it because it's supposed to be constant)
>>
>>51457078
reverse("hello", 5)

"hello" is a constant string. Use an array declaration of the string, or don't do the string reverse in-place.

>>51457117
What about them do you not get? Your code is 1) unreadable and 2) not easy to pass in an out of functions.
>>
>>51457145
>>51457147
>>51457155
Hi, sorry I deleted my post. Thanks for the advice, I'm stupid.
>>
>>51457147
>"hello" is char const
No, it is not. It is true that you can't alert it but it's type is actually char[].
And actually there is (was?) a GCC option that made the strings writable.
>>
Anons, need help here. I want to learn programming to be a backend developer.
At this moment I'm learning Ruby on codecademy, later I'm going for Rails.
What else is necessary in order to be a RUBY backend dev?
I have 0 knowledge of programming in general.
>>
>>51457165
>mutable literals
GCC literally stalin, yet again
>>
>>51457165
char const *, whatever anon, the important part is that it can't be altered.
>>
>>51457180
adick in your butt
>>
How would I be able to access some arbitrary memory location in c?
>>
>>51457155
 a = {}     -- create a table and store its reference in `a'
k = "x"
a[k] = 10 -- new entry, with key="x" and value=10
a[20] = "great" -- new entry, with key=20 and value="great"
print(a["x"]) --> 10
k = 20
print(a[k]) --> "great"
a["x"] = a["x"] + 1 -- increments entry "x"
print(a["x"]) --> 11


Going from that it just looks like a way to organize variables and set them to keys so when it's called it accesses the one related to the key

As far as replacing a bunch of if/else statements I can see it being useful for that, but I don't see how I can use it to move variable values.
>>
>>51457053
>have to write some scripts to aid in analyzing some mathematical series
>functional programming
>not the right tool for the job

(define (productofcoprime m)
(define (productofcoprime-iter cur result)
(if (> cur m) result
(let
((canidate (lr-sequence cur)))
(let ((n (if (iscoprime canidate m) canidate 1)))
(productofcoprime-iter (+ cur 1) (mod* result n m))))))
(productofcoprime-iter 1 1))
>>
Hex dump program for an assignment.
>>
>>51457253
>not product-of-coprime
cmon son
>>
>>51457253
Have you heard the good news?
Have you ever heard of C++?
>>
>>51457235
uintptr_t location = 0xFFFF;
*(char *)location;
>>
>>51457009
Generic programming is not exclusive to OOP. You don't need classes, inheritance, etc. in order to create generic types. Go or C could easily be used in exactly the same way, but with generics. For example, someone could create an extension to C that allows for:
typedef struct<T> {
T x;
T y;
} example_t;

(or something somewhat similar)
and then just let you write
example_t<int>
as a type. That wouldn't create any sort of OOP, since there's still no inheritance going on and no classes are involved. For an example of something kind of like this check out Jonathan Blow's JAI language.
>>51457071
try not to hurt yourself with that sharp edge, kiddo :^)
>>
>>51457276
literally just
execvp("xxd", argv_with_NUL);
>>
>>51450220
>>51457117
>>51457252
-- creation
perm = {}
perm[1] = {
slot = ...,
name = ...,
race = ...,
class = ...,
-- and so on
}
perm[2] = {
-- same thing for the second character
}

-- copying
-- loads of ways to implement table copy, just look it up and find the one that suits your needs
temp[TEQtemp1] = copy(perm[pcV])

I'd also suggest making more meaningful variable names. What the fuck does TEQtemp1 mean?
>>
>>51457336
>try not to hurt yourself with that sharp edge, kiddo :^)
It's real.
https://esolangs.org/wiki/Joke_language_list#General_languages
>>
>>51457253
you can make anything in C++ and it'll be a lot easier to read than whatever the shit you wrote
>>
>>51457071
typical strayan fag
>>
>>51457253
That's just recursion, anon.
>>
>>51457304
Why the fuck would you use C++ for something that's best done with an interactive command line? C++ is the antithesis of rapid prototyping and hacking some shit together.
>>
>>51457338
Yeah except it has to match the sample output and it's checked sandboxed on the submission server.
>>
>>51457363
Yeah, because he just edited the page
>>
>>51457340
Temporary Equipment Temp1

I don't need it anymore actually
>>
>>51457252
>but I don't see how I can use it to move variable values
You don't create variables. You make all values in terms of the table keys. This allows you to group variables together and pass them as one unit. You know what structs are apparently so it's the same concept.
>>
>>51457376
>interactive command line
>hacking some shit together
absolutely disgusting
>>
>>51457402
Do you at least understand how tables can help you?
>>
>>51457376
What exactly does functional programming have to do with a REPL, other than the fact that Lisps typically have both?
>>
>>51457374
Yes but it's also functional programming.
>>51457364
C++ isn't good for hacking shit together. Besides, you're just unfamiliar with the syntax. All the functions in there are self explanatory, except for lr-sequence, which when run through an enumerator produces 0, 1, -1, 2, -2, 3, -3, 4, -4 . . .
>>
Apart from python/c++, what other languages might a hobbiest programmer find useful?
>>
>>51457404
As far as structs go, I know there's like a thing that exists, and that it's called struct

>>51457412
Well it's slightly clearer now
>>
>>51457404
Tables are also useful for lists so instead of having multiple variables allocated for each player use a table to keep a list of all player. They are very versatile data structure and used for everything in Lua.
>>
>>51457432
I don't see any usage of first class functions.
>>
>>51457071
love it
>>
>>51457071
>look at me I can edit a wiki
okay anon
>>
>>51457336
>not OOP
>OOP requires inheritance
>classes and structs are completely different
>>
>>51457453
Yeah this was written a while ago, I didn't know what first class functions were, thus the unreadability.
>>
>>51457472
Pretty much, yeah.

>>51457491
You have no idea what you're talking about.
>>
>>51456937
https://automatetheboringstuff.com/
>>
>>51457005
>I mostly want to use Python for visual novels
there's a library for that
see: Ren'Py
>>
>>51457071
>Country: Australia
Not surprising.
>>
>>51457472
If structs are OOP then C and Go are OOP. That's obviously not what the original post said. Anyways, OOP is more complex than just structs; it's a style of dealing with abstraction for data and functions that operate on that data. Kind of like how functional programming is more complex than just having anonymous functions.
>>
>>51457071
Reported to your ISP, have fun lol.
>>
>>51457432
>you're just unfamiliar with the syntax
literally one post later:
>>51457491
>unreadability
>>
>>51457533
but nothing to do with inheritance

templated structs would be oop imho
>>
>>51457607
Why?
>>
>>51457607
>templated structs would be oop imho
So now your opinion determines what's what in a programming language?

Y'know, in my honest opinion, strings are pretty much the same as functions. I'm going to have to say that Bash is a functional programming language.
>>
>>51457633
they're parametrised and everything, they're clearly meant to be used as objects
>>
>>51457547
>Implying they care.
>>
>>51457133
The two are not mutually exclusive.
I mean I have learned a lot by creating a problem I have not considered before.

If imagining a project is impossible (it might be if you do not know the limits or capabilities) then try to implement data structures.
It is a good way to learn both how the language works, learn how to store and access data and most important: learn when to use different data types when they are provided to you.
>>
>>51457655
So now your opinion determines what's what's what in what's what in a programming language?
>>
>>51457661
// not an object
struct Thing {
int value;
bool flag;
}

// suddenly an object
struct Thing<T> {
T value;
bool flag;
}


Right, makes a lot of sense. Perhaps you should look up the accepted definition of what is and what isn't OOP.
>>
new thread
>>51457707
new thread
>>
>>51457693
// not an object
struct Thing {
int value;
bool flag;
}

// suddenly an object
struct Thing {
Thing(int v);
int value;
bool flag;
}
>>
whats the best way to learn lisp?
reading SICP?
or
following the MIT SICP lectures?
>>
>>51457731
Makes sense to me. Blame C++ for lumping aggregate types and classes under the same keywords.
>>
>>51457661
OOP doesn't mean "language has a notion of objects"

Would you prefer to use a language where the only data types are primitives (string, int, bool, float) and lists? Or are lists too OOP for you because they're kind of objects?

Languages without a notion of objects are pretty much unusable for any sort of productive programming. Generics are just a way of making generalized types so that you don't have to rewrite the same thing multiple times / rely on standard library "magic" (e.g. Go). Also, proper generics provide a combination of code safety and speed that type erasure or dynamic typing does not.
Go lacks generics because of some other design flaws ("choices"), e.g. int cannot be nil, so there is no generic "nothing" value.
>>
#define Thing(x) \
struct Thing \
{ \
x value; \
bool flag; \
};
>>
>>51457804
*struct Thing_##x
>>
>>51457804
What's your point?
Is that supposed to be a valid solution?
How about generic functions?
>>
>>51457827
void* params
>>
OOP has a very specific definition. It's programming using objects, where objects have both fields and methods. There's also great emphasis on encapsulation, inheritance, and subtyping (a specific kind of polymorphism that doesn't include generics).

In a similar manner, FP is about programming using first-class functions/closures, with emphasis on pure or referentially transparent functions.

The thing to realize is that programming paradigms aren't mutually exclusive. You don't have to say "OOP is the best, you don't need anything else" because that's like saying "screwdrivers are the best, you don't need anything else" since you can technically whack nails with the handle of a large screwdriver.
>>
>>51457852
I thought C programmers were against adding layers of abstraction/indirection?
>>
>>51457852
See >>51457852
>proper generics provide a combination of code safety and speed that type erasure or dynamic typing does not.
>code safety
>type erasure
void* doesn't even work at all.
What if 'x' has a different size? How will alignment work? How will the generic function know where the field is?
>>
>>51457862
Generics are subtypes.
I think it's mostly member methods that make OOP oo, and generics are effecitvely type member functions
>>
>>51457881
generics are exactly that
>>
>>51457904
>Generics are subtypes.
You what now?

>>51457906
Maybe by the Java definition. I don't think there's anything about the term "generic" that implies "type erasure by pointer".
>>
>>51457937
std::vector
std::vector<int>
std::vector<float>
std::vector<std::vector<int>>


subtypes.

Hell, they even inherit.
>>
File: 1428670267684.jpg (60KB, 706x706px) Image search: [iqdb] [SauceNao] [Google]
1428670267684.jpg
60KB, 706x706px
>>51457958
>>
>>51457958
c++ is so ugly desu
>>
>>51457994
how is this ugly
>>
>>51458006

It's not.
>>
>>51457958
It's not OOP just because you reinvented/butchered the meanings of "subtype" and "inheritance".
>>
>>51458009
That settles that.
>>
File: cruz.jpg (208KB, 750x500px) Image search: [iqdb] [SauceNao] [Google]
cruz.jpg
208KB, 750x500px
>Do you like my code /g/?

https://github.com/mypetbirdrules/4chan-Thread-Downloader
>>
>>51458031
How are they not subtypes?
>>
>>51458039

C++ gets much worse. It would be wrong to consider that ugly.
>>
>>51458068
For one, std::vector isn't a type. std::vector<int> can't be a subtype of a type that doesn't exist.
>>
>>51458091
std::vector is a type
It's a template type.

You can parametrise another template with std::vector using a template template parameter.

>can't be a subtype of a type that doesn't exist
>what are abstract classes
>>
>>51458066
>#!/bin/python
#!/usr/bin/env python
also: use argparse
https://stackoverflow.com/questions/7427101/dead-simple-argparse-example-wanted-1-argument-3-results
https://stackoverflow.com/questions/15301147/python-argparse-default-value-or-specified-value/15301183
>>
>>51458140
I'm assuming you're just making that as a personal learning thing, but if not, something better exists: https://github.com/bibanon/BASC-Archiver
>>
>>51458108
>std::vector is a type
>It's a template type.
Templates aren't types. They're basically type-level functions.

>You can parametrise another template with std::vector using a template template parameter.
What does this have to do with anything?

>can't be a subtype of a type that doesn't exist
>what are abstract classes
Abstract classes are types.
>>
>>51458140
Argparse is okay but I prefer to write my own argument parsing. It's not hard to implement basic argument parsing.
>>
>>51458170
They are types. Asserting template types aren't types would beg the question.

You can (sometimes must) use them as types.

Yes, template types tend to work the same as abstract classes.
>>
>>51457733
Why not both?
>>
>>51458213
>Asserting template types aren't types would beg the question.
They aren't, though, and that's why you're completely wrong. Besides, the term is "template", not "template type". Templates are literally templates for types, and can be seen as type-level functions since they give you a type when fully applied with type parameters.

This is all a template really is:
#define PAIR(a) struct a##Pair { a fst; a snd; };

Is "PAIR" a type? Obviously not.
>>
>>51457733
lisp and scheme have some fundamental disagreements about things, but to outsiders their similarities are greater than their differences

just know that there is historical butthurt about scheme being lisp
>>
>>51458213
>>51458309
Also, please provide me an example of this:
>You can (sometimes must) use them as types.
>>
>>51458309
A type function can be a type. They're metatypes.

I wouldn't call PAIR a type in C, but the equivalent in C++ I would because C++ has actual facilities for templates. With that #define all you can do is replacement. C++ templates aren't just substitutions.
>>
>>51458405
>A type function can be a type. They're metatypes.
A function from integers to integers isn't an integer. Also, there's no such term as "metatype".

>C++ templates aren't just substitutions.
Actually, they are. The only difference is that you can specialize to sometimes do different substitutions for particular type parameters.
>>
>>51458385
You wouldn't consider them being used as types.
I consider template template parameters as types.
>>
>>51458435
A meta type is a type of types.

>the only difference is you can specialise
(and do lookups via function templates)
makes a world of difference
>>
>>51458441
>I consider template template parameters as types.
Templates don't just take type parameters, though. They can take template parameters, type parameters, and certain non-type parameters including integers and pointers-to-members. So just because you can use them as a template parameter doesn't make them a type.

>>51458460
>A meta type is a type of types.
A "type of types" is a universe, or large type. Not a template, or type-level function.
http://ncatlab.org/nlab/show/type+of+types

>makes a world of difference
It's still fundamentally just doing substitution. And even if they didn't just do substitution, how does that somehow make a template a type?
>>
>>51458108
>std::vector is a type
test.cpp:4:1: error: invalid use of template-name ‘std::vector’ without an argument list
std::vector r(std::vector x) {
^
>>
>>51458559
I consider template types to be types, that's the whole argument.

That's an even more meta type. A superclass is a type of types. It specifies subclasses to some degree.

Everything programming related is just a substitution.
>>
>>51458639
>abstract base classes are types
then why cant i instantiate them
checkmate
>>
>>51458674
Because a type doesn't have to have any values. Void is an example of that. Abstract base classes do have their own values, per say, but they can use values from different classes. So a value of an abstract base class can be stored, returned, taken as an argument, etc.
>>
>>51458651
>I consider template types to be types, that's the whole argument.
>I consider
So you concede to the original point? >>51458031

>That's an even more meta type. A superclass is a type of types. It specifies subclasses to some degree.
Now I just don't think you understand what a type is.

>Everything programming related is just a substitution.
Even so, that doesn't have any bearing on the definition of a template and why templates aren't types.

>>51458723
I fucking hate subtyping, as someone intimately familiar with type theory. It convolutes things far too much.
>>
>>51458723 the point is your example proves nothing

>>51458789
Literally begging the question.

A super[anything] specifies a sub[anything] to some degree.

It means "its just a substitution" has no bearing on whether or not it's a type.
>>
>>51458838
But it does. It proves that C++ compilers (or at least VC++, Clang, and GCC) do not consider
std::vector
to be a type, but a template for a type. There is no such type
std::vector
in the C++ standard library.
>>51458789
Yeah, it's pretty shitty in terms of type theory. I recall some article about how it's the main reason that OCaml couldn't have type classes
>>
>>51458838
Supertypes and large types are totally orthogonal concepts. A given type could be either one, both, or neither. In the context of C++, and pretty much every other programming language out there, there aren't large types at all.

>It means "its just a substitution" has no bearing on whether or not it's a type.
You're absolutely right. Whether templates can do more than just "dumb" macro substitution or not, it doesn't make them types. Furthermore, C11's macro system does actually allow switching based on types, which is how specialization works.
>>
>>51458838
>>51458915
This argument is done, too, since you aren't denying that you're just trying to pass off your opinion as fact.
>>
>>51458914
Abstract base classes do two things:
- constrain derived types
- allow a reference to a variant over derived types/a type that can derived types can be treated as

templates can do this

>>51458915
I don't think we're going to agree
>>
>>51459002
You're right, templates can be used to implement subtype polymorphism. That doesn't make a template a type.

>I don't think we're going to agree
See >>51458982.
>>
>>51459018
The point is that template types can be types in the same sense an abstract base class can be.

If abstract base classes can be types, so can templates
>>
>>51459044
Correlation does not imply causation.
>>
>>51459076
Two wrongs don't make a right.

I can quote unrelated platitudes too
>>
>>51459120
>unrelated
You're saying that because templates and abstract base classes share the ability to do polymorphism, and abstract base classes are types, templates must be types. Proving causation by correlation is exactly what you're trying to do here.
>>
>>51459156
>Virtual base classes are types
>Templates can be virtual base classes
>Templates can be types
>>
>>51459198
>Templates can be virtual base classes
What? You can inherit from a fully specified template, e.g. std::vector<int>, which is a type. You can't inherit from std::vector.
>>
>>51459232
std::vector<int> inherits lots of stuff from std::vector, almost all (if not entirely) interface
you wouldn't consider it inheritance because you don't consider vector<int> to be a subtype of vector, you'd consider specialisation/derivation to be something else.
>>
>>51459314
as an example:
std::vector<T> has size_t size() const and has void push_back(T);

I can't see the former being argued, I accept the latter but I could see someone disagreeing with it because it's specialised, but it certainly inherits a method of that form (and that's part of my point)
>>
don't you die on me you bastard
Thread posts: 378
Thread images: 23


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]
Please support this website by donating Bitcoins to 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
If a post contains copyrighted or illegal content, please click on that post's [Report] button and fill out a post removal request
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.
This is a 4chan archive - all of the content originated from that site. This means that 4Archive shows an archive of their content. If you need information for a Poster - contact them.