[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: 28
File: yF1VCTm.jpg (89 KB, 1366x768) Image search: [Google]
yF1VCTm.jpg
89 KB, 1366x768
old thread: >>51819395

What are you working on, /g/?
>>
>>51825909
First for D
>>
Rewriting the Linux kernel in Haskell
>>
>>51825998
Making Linux Slow Again
>>
Fourth for Forth.
>>
Is semaphore.h available on all unix and linux based systems?
>>
Rewriting lunix in lolcode
>>
Rewriting the Linux kernel in PHP
>>
Rewriting the Linux kernel in Russian
>>
Rewriting the Linux kernel in proprietary Java
>>
>>51826102
cheki breki
>>
Rewriting the Linux kernel mostly in C but with a bit of assembly
>>
>>51825909
I'm writing a program that parses my ssh log files into json data that is readable by https://github.com/dataarts/webgl-globe, so that I can see the amount and severity of bruteforce attacks from different parts of the world

basically a globe that lights up around india, eastern yurop, and china
>>
>>51825998
>not lisp
u r fagutt
>>
>>51826040
I'd assume so.

http://www.csc.villanova.edu/~mdamian/threads/posixsem.html
>All POSIX semaphore functions and types are prototyped or defined in semaphore.h
>>
when a user inputs a number bigger than INT_MAX, should the program refuse it or handle the number?
>>
>>51825658
First of all, it's not really useful to define data types like that, not in the core type theory. What my language does is this:
Vect : Set -> U32 -> Set
Vect a "0" = Unit
Vect a (Succ m) = a & Vect a m

Functions of types are compiled to structures, unions, etc. This works very nicely because the totality checker ensures you're not creating an "infinite" structure. Things like lists must be encoded with pointers, which guard the recursion and pass the totality check.

Implicit parameters are just syntax, and don't exist in the core type theory.

The last issue is a tricky one. As you probably know, it works if the (i < n) proof is constructive, since the proof itself is what you recurse over, not the index. This is actually something that I'm working on: how do you preserve this kind of logic with native unsigned integers and non-constructive proofs? My intuition is that there is a pattern: notice how I defined "Vect" as a type that is recursive over U32, which is what you want to index it with?
>>
>>51826516
Depends on what the program is.
>>
>>51826540
a program that averages 2 ints
>>
>>51826544
Depends what that average will be used for.

Smells like homework.
>>
>>51826566
nah, it's just some autismos that keep posting "/g/ can't average two numbers" and I'm actually confused about it now
>>
File: 99X3uRh.webm (3 MB, 720x404) Image search: [Google]
99X3uRh.webm
3 MB, 720x404
Ask your beloved programming literate anything.
>>
>>51826596
do you like massive throbbing cocks, massive veiny cocks, or moderately sized cocks that cum a lot?

anyway, what's the best programming language? i want to get into programming
>>
>>51826596
Let's see if you are really literate.

Is Swift a good language?
>>
File: head.jpg (38 KB, 1280x720) Image search: [Google]
head.jpg
38 KB, 1280x720
>Interview
>Have project to do
>You have 1 day to complete it
>Get drunk the night before as can code in my sleep
>SURPRISE project is IQ Test

Well time to keep sending out applications because I'm apparently retarded
>>
>>51826532
Oh, and before you ask how you can prove recursion over an unsigned int is total in the first place, it's done with something similar to QuickCheck. The gist of it is that you define your eliminator, somehow, and then at compile time it's checked that the recursion is bounded for "all" values.

And before you then say "isn't that the halting problem", I'm a bit more conservative than that. Since a native unsigned integer is bounded by memory, all you have to do is show that the number of steps will never exceed UINT_MAX. If the recursion hits UINT_MAX steps, you know that you've got an improper definition of the eliminator.

Or I could just build it all in, since unsigned integers are AFAIK the only time where experimentally proving totality is necessary.
>>
I heard you guys all crossdress while you program things
>>
>>51826705
>Not coding cross platform
pleb
>>
>>51826705
Here we go
>>
Is it possible to decode H.264 in a deterministic way across different codecs, software and hardware?
That is, the resulting bitmaps should be identical, pixel by pixel.
>>
>>51826233
Neat,
>>
>>51826631
>anyway, what's the best programming language? i want to get into programming
i have a preference for scheme but having a good tutorial is more important than the language.

:: Structure and Interpretation of Computer Programs
http://sarabander.github.io/sicp/
http://paste.lisp.org/display/151208/raw

:: How to Design Programs
http://htdp.org/
https://www.edx.org/xseries/systematic-program-design-0

:: Concepts, Techniques, and Models of Computer Programming
not free

:: Composing Programs
http://composingprograms.com/

:: CS for All
http://www.cs.hmc.edu/csforall/
https://www.edx.org/course/cs-all-introduction-computer-science-harveymuddx-cs005x

:: Program Arcade Games With Python And Pygame
http://programarcadegames.com/

>>51826639
it's not innovative (doesn't bring anything new to PLT) but it's the long awaited update for people developing on apple devices. objective-c is not a bad PL at all but it's really getting old because, especially now that the functional revolution is happening: it's time to ditch the C heritage one for good.
>>
>>51826596
>>51826620
>>
>>51826566
So?
>>
>>51826516
It if needs to, it should handle it.

$ dc <<<'2 100 ^ 2 102 ^ + 2 / p'
3169126500570573503741758013440
>>
>>51826866
How is that even possible? GMP? I guess for common sense that averaging two ints doesn't require shit like that, and if it did I would just use some implementation of big int.
>>
File: CLgm1XqVEAAQRzT.jpg:large.jpg (80 KB, 1023x682) Image search: [Google]
CLgm1XqVEAAQRzT.jpg:large.jpg
80 KB, 1023x682
>>51826803
Please don't bully
>>
>>51826575
That's because it's a legitimate issue. Averaging 2 numbers has no reason to cause overflow
>>
>>51826927
>ISIS
No wonder the software keeps blowing up
>>
>>51826927
>isis
>>
>>51825909
What a fucking FAGGOT.
>>
I'm only interested in making practical tools/applications, I know that I'm a freak but I need a project to work on.

Any ideas?
>>
>>51826947
>>51826948
An egyptian name you uncultured cunts.
>>
>>51825909
Why are chinese cartoon lovers massive faggots every fucking time?
>>
File: cidr-chart.jpg (96 KB, 486x534) Image search: [Google]
cidr-chart.jpg
96 KB, 486x534
I am writing something that parses CIDR prefix notation into netmasks for one of my projects.

There is a fixed # of CIDR prefixes and they look like this /8

/8 would be 255.0.0.0

Would it be better to try to convert the prefix into the address or should I just use a json file for mapping?
>>
>>51826983
>A terrorist name you freedom lovers
ftfy
>>
>>51826983
>ISIS is from Egypt
It actually makes sense

it's why bombing them does nothing to their leadership
>>
File: 1435613166906.jpg (13 KB, 222x216) Image search: [Google]
1435613166906.jpg
13 KB, 222x216
The debate of the year, what do you do?

a) Do you free all your memory at the end of your program

b) Do you let the OS clean up anything you claimed
>>
>>51827002
Wow, you're so clever. I bet you're the top of your highschool class aren't you.. Bottom in the locker room though, faggot.
>>
>>51827021
fuck off sand nigger
>>
>>51827010
Depends on the language
>>
>>51827010
b)

literally retarded to call free() or close() (or w/e) just before exit, just pointless busywork that only serves to delay the closing of your program.
>>
>>51827010
c)
>>
>>51827010
My goal: Prevent memory leaks. I will clean up memory that will allow my program to spiral out of control during runtime, but if I reach the end of the program and I know the OS will claim the memory, I won't spend the extra time free()ing them.
>>
>>51827031
All we have here in Canada are asians, which at worst just take too many pictures.
White here, champ.
Fuck off back to the school yard.
>>
>>51827080
east coast us islander, feels good to be 1% black and .2 % sand negro :^)
>>
>>51827073
>>51827044
Not closing sockets can result in a port (networking) not being usable for up to several minutes.
>>
>>51827080
>canada
oh kek you mean the asians sleeping with canadian women right
>>
Python's closures suck. You can't even do this in Python

package main

import "fmt"

// fib returns a function that returns
// successive Fibonacci numbers.
func fib() func() int {
a, b := 0, 1
return func() int {
a, b = b, a+b
return a
}
}

func main() {
f := fib()
// Function calls are evaluated left-to-right.
fmt.Println(f(), f(), f(), f(), f())
}
>>
>>51827095
white is right amirite or amiwite?
>>51827121
The asians here are the biggest sluts, and white girls here rarely go for 4'10 asians. So no.
>>
>>51827102
Calling close() doesn't necessarily help with that either.
The proper solution is setting the SO_REUSEADDR option for the socket so you can immediately reuse the address if you need to use the same port.
>>
File: 1444216777417-4.jpg (75 KB, 615x820) Image search: [Google]
1444216777417-4.jpg
75 KB, 615x820
>>51827137
Fuggg
def fib():
a, b = 0, 1
def fibber():
nonlocal a, b
a, b = b, a + b
return a
return fibber

def main():
f = fib()
print(f(), f(), f(), f(), f())

main()
>>
>>51825909
Anime?
>>
>>51827342
Yup!
>>
>>51827359
lol
>>
so, where is the real /dpt/ ?
>>
>>51827405
/dog petting thread/?
>>
File: tumblr_m8a14xwrON1r0yamfo1_400.jpg (36 KB, 278x278) Image search: [Google]
tumblr_m8a14xwrON1r0yamfo1_400.jpg
36 KB, 278x278
>>51826994
>>
>>51826994
JSON mappings are easier and better to maintain.

[spoiler]I would choose the other way though :^)[/spoiler]
>>
>>51826994
As far as I can tell, JSON is way overkill for what you need, just use a DSV:
CIDR1#NETMASK1
CIDR2#NETMASK2
...


Data File Metaformats
http://nakamotoinstitute.org/static/docs/taoup.pdf
>>
>>51826994
convert it, it's some really basic bit operations and a billion times cheaper than reading from a file
>>
>>51827509
This is my solution, it's not very good.

public string ParseCidr(string CidrString)
{
int CidrValue = 0;

bool isValidNumber = int.TryParse(CidrString.Trim('/'), out CidrValue);

int BitCount;
int FullOctetCount = 0;

if (isValidNumber)
{
// if it is >/7 then we only need the bit count
if (CidrValue < 8)
{
BitCount = CidrValue;
}
else
{
// Gets the ammount of populated octets and the ammount of bits in the next octet
FullOctetCount = CidrValue / 8;
BitCount = CidrValue % 8;
}

byte [] AddressArray = new byte[4];

int ZeroCount = 8 -
int OctetIterator = 0;
for (OctetIterator = 0; OctetIterator < FullOctetCount; OctetIterator++)
{
AddressArray[OctetIterator] = 255;
}

// Build the binary for the last octet
// There has got to be a better way to build a binary string
if (BitCount > 0)
{
string BinaryString = "";
for (int i = 0; i < BitCount; i++)
{
BinaryString += "1";
}

for (int i = 0; i < ZeroCount; i++)
{
BinaryString += "0";

}
AddressArray[OctetIterator] = (byte)Convert.ToInt32(BinaryString, 2);
}

IpAddress ReturnAddress = new IpAddress(AddressArray);
return ReturnAddress.ToString();

}
}


I think json will be better for readability as well
>>
>>51827044
You need to call close() so that you can check the return status. Or do you just assume that everything always succeeds?

>>51827102
> Not closing sockets can result in a port (networking) not being usable for up to several minutes.
There's no difference between an explicit close() and process termination. A socket is "closed" at the exact point when the number of processes in which it is open reaches zero. close()ing a socket which has been inherited by another process does nothing until that process close()s it or terminates.

A socket getting stuck in FIN_WAIT states tends to arise from a firewall, NAT, load balancer etc that forgets about an idle connection and consequently discards the termination packets when one end eventually decides to close it.
>>
I want to write a big project to practice, not just small program and algorithms. But I don't know what to do. Suggestions?
>>
https://github.com/cristianceron/CharacterEditor/blob/master/core/src/gui/GUI.java
WHY EVERYONE TELL ME MY FORMATTING STYLE IS TRASH.

WHAT IM DOING WRONG

FUCK
REEEEEEEEEEEEEEEEE

fuck you
>>
>>51827986
If close fails then you're pretty much fucked. You can't even call close again because that's undefined.
>>
File: 1449808841454.png (296 KB, 514x390) Image search: [Google]
1449808841454.png
296 KB, 514x390
>>51828093
>>
>>51828093
literally everything senpai
>>
>>51828093
Because you put { when declaring a method in a newline
>>
>>51828093
I like your drawings m8.
>>
>>51828156
>>51828212
>>51828218
I DONT KNOW WHAT STYLE IS THE CORRECT ONE

I THOUGH

function()
{
// Tab code
}

FOR EVERYTHING LOOKS NICE

REEEEEEEEEE
>>
>>51828265
Normally you put the { on the same line of your method declaration for Java. Yours is more like C#.
>>
File: app.png (651 KB, 1768x1198) Image search: [Google]
app.png
651 KB, 1768x1198
app
>>
Is it possible to output no value from a vertex shader? What if I want colour to be exclusively handled via uniform?
>>
Can anyone explain to me the difference between memory banking and virtual memory?
>>
>>51828304
The vertex shader only outputs what you tell it to.
>>
>>51828296
I hate those transparency effects in OS X more than life itself.

Fuck you Ive.
>>
>>51828336
It doesn't matter I got it. I was just under the impression that not passing a value from the vertex shader to the fragment shader would result in no fragment shading occurring.
>>
>day 12 AoC solution in C is over 200 lines now
i fell for the meme
>>
File: fuckyoucaptcha.png (14 KB, 721x147) Image search: [Google]
fuckyoucaptcha.png
14 KB, 721x147
>>51827314
We know. Yeah this has influences from itertools, get over it.
function fib()
local a, b = 0, 1
return function()
a, b = b, a+b
return a
end
end

function count(n)
local i = 0
return function()
if i == n then return nil end
i = i + 1
return i
end
end

function takewhile(truthiter, ...)
local iters = {...}
return coroutine.wrap(function()
for i in truthiter do
local q = {}
for iter = 1, #iters do
q[iter] = iters[iter]()
end
coroutine.yield(table.unpack(q))
end
end)
end

for f in takewhile(count(5), fib()) do
print(f)
end
>>
>>51827314
He said Python, not the still born nuisance known as Python 3.
>>
>>51828330
>memory banking
RAM modules, physical memory.. I assume

>virtual memory
the, err, memory managed by the OS, which does translations between addresses in physical memory and logical memory... or something. actually, there is yet another "translation" stage, the MMU, but I don't think I ever learned this well.
>>
what is AoC?
>>
>>51828265
whichever you like, but stick with one of them.
w/o newline is often used in JS, Java, meme languages
with newline is often used in C, C++, C#, PHP
>>
File: 1432323884812-0.png (26 KB, 431x499) Image search: [Google]
1432323884812-0.png
26 KB, 431x499
>>51828093
Well I would set your editor to use 4-space tabs, in vim that would be
set expandtab
and
set shiftwidth=4
in your vimrc.
Most of your code is pretty bad to be quite frank.
For instance your C++ projects in fact do not use any C++-specific features and may just as well be compiled by a C compiler.
Your organization of OpenGL state is poor, the main loop should be in the main function when using C.
You're using the deprecated glBegin and glEnd functions, so if your hardware supports it you should use OpenGL 3.3+ and do batched rendering, it is very fast that way.
Rather than SDL I would use GLFW and for an image library use a single-file lib such as stb_image.
Your error handling is non-existant, in most places you seem to have forgotten about checking for them, when using C you should at least have an error function with a general interface like so
void die(const char *format, ...)
{
va_list vargs;
va_start(format, vargs);
vfprintf(stderr, format, vargs);
va_end(vargs);
exit(1)
}

And then wrap this up in a macro:
#define DIE(format, ...) die("File: '%s', line: %d\n" format, __FILE__, __LINE__, __VA_ARGS__)


Also, just before your rendering routine you should always query glGetError() just in case.
>>
>>51828330
Memory bank -> Actual memory
Virtual memory -> OS abstraction for software, every program thinks that they're writing from address "0" onwards and the OS translates that to the real address to make it easier.
>>
>>51828156
What is this from
>>
Thank you for using an anime pic.
>>
>>51828567
Age of Conquest
Age of Consent
Administrator of Cocks
Advent of Code
take your pick
>>
somehow I miss this question every time its asked but I swear I understand the concept.
Is this a memory leak
int* x= new int(5);
int y=5;
x=&y;
>>
>>51828583
This guy knows what he's saying.
>>
>>51828650
No, the OS will do the cleanup on program exit.
>>
Stupid question, Is arg a copy or a reference?
    std::vector<std::string> args(argv, argv + argc);
for (const auto arg : args) {
}
>>
>>51828679
You know I was tempted to respond. But I couldnt come up with anything for this troll.
>>
>>51828650
This is a memory leak
for (int i = 0; i++ < 10;) {
int *x = new int[5];
}

the pointer to the first allocation gets lost when the next step of the loop occurs, now there is no way to free this memory under program exit. If your program is not a long running program and doesn't consume a ton of memory intermediately then the leak is not important. But say you did the above every second, it would take a while but eventually that process would claim a ton of memory.
>>
>>51828757
A copy.
To get a reference, use:
 auto & 
>>
>>51828504
Python 3 is objectively superior
>>
What's the best way to learn Python? It's my first language. I'm reading "Learn Python the hard way" right now and i'm at excercise 17, but i feel like i don't get it. Am i too stupid, will i get it eventually or is there a better tutorial?
>>
>>51828867
>this opinion somehow exists
>>
>>51828883
Start writing small throw away programs, you'll get it eventually
>>
Seriously how do you find the bus, slot and, function for an IDE controller on PCI? My OS is getting so close to being self hosted.
>>
Can the Day 12 pt 2 solution be a negative number or did I fuck up?
>>
>>51828794
the size of the leak isnt really the important part. Its the data that cant be freed.
>>
>>51828924
Depends, your inputs and outputs are picked randomly from a set, so we may not know. You'd have to try it yourself or take a quick glance at the json file as well as your first answer
>>
>>51828883
You're feeling like you're not getting it because you're reading a "book" with a very bad reputation.
Find an actual book, such as Programming Python or whatever. One of the O'Reilly books.
>>
>>51828942
(cont.)
Here's my solution if you're using python. It's less than elegant, and looking at other people's solutions, my initial attempt (summing as I dive deeper into the json) would have been quicker if I knew more about type checking

import re, json

data=open("Advent12.txt").read()

def deleteRed(items):
if type(items) is dict:
if "red" in items.values():
items.clear()
return items
for i in items.items():
items[i[0]]=deleteRed(i[1])
elif type(items) is list:
for i in items:
deleteRed(i)
return items

#uncomment the following 3 lines for part 2
#data=json.loads(data)
#data=deleteRed(data)
#data=json.dumps(data)

print sum(int(i) for i in (re.findall(r'-?\d+', data)))
>>
I have an Arduino Due, and I was thinking of writing (or rather porting) a NES emulator to it to play some retro vidya. As it has two DAC one can be used for mono audio, and one for video output (via RCA). Are there any hardware or software limitations that may make the project impossible?
>>
>>51828983
big data
>>
>>51828983
An arduino is a microcontroller
think about it
for one
second
>>
>>51828942
nevermind, i figured it out, my seeking algorithm is counting multiple objects twice.

i hate json so fucking much
>>
>>51828988
Due has 512 kB rom

>>51828999
but the Due has a 84 MHz ARM processor, 512 kB rom, 96 kB ram. it should be way more than enough to run NES games, check NES' specifications
>>
>>51827137
>go
>good
lmaoing at this fag
>>
Of C++, Java and Python, which has frameworks/libraries I can study which will be the most likely to land me the job. Please no java applets shit
>>
>>51829046
>go
>not good
just look at yourself
>>
What's a good laptop for programming Perferably under 1000 with a nice screen (1080p+)? ItS going to be for simulation work when im on the road. Also light would be great.
>>
>>51829034
looks fine, glhf
>>
>>51829084
Depends on the field you wanker.
Web stuff, AI stuff, python
muh desktop apps, web stuff, Java
Actual stuff, lower level stuff, image stuff, robot stuff, basically anything, C++
>>
>>51829091
Dell chromebook with Linux distro loaded onto it.
>>
>>51829091
Thinkpad X220 with your favorite distro :%)
>>
>>51829091
Gnupad t420/x220/P70
>>
>>51829116
bit mean tbf lad

but yeah doesn't matter what field, as long as it's the highest chance of landing a job of those options, and what the framework/libraries are. I know that, for example, a lot of job applications are looking at Django with python, but maybe there are some things for java and c++ that are more popular?
>>
>>51829155
Learn the Android SDK.
>>
>>51829091
>simulation work when im on the road
chromebook and ssh into your desktop to compile and run
>>
>>51829183
Oh I'm actually quite familiar with that. Alright, I'll go to work on expanding my portfolio with it
>>
>>51829183
oh and thanks for the list of fields per language too

night lads, gotta wake up early for AoC day 13
>>
>>51829133
>>51829135
>1080p
>under 1000

>>51829194
This 100% you can buy them for like $200 and have all the power of your home server
>>
>>51829281
x220 is like $200 lol
T420 you can get 1080p and for <$400
>>
how do I make an efficient quadtree that can hold millions of elements? The one I made chokes when there's a lot of elements but small capacity per node. How do I determine a good number of elements for each node to hold / the depth I should go before I stop?
>>
How future proof is programming as a job?
>>
>>51826799
>it's not innovative (doesn't bring anything new to PLT)
Neither was Scheme.
>>
I program with an X200 and it only cost $60 shipped with a battery included.
>>
>>51829410
Programming as a professional will probably be the last thing to be automated away.
Then some kek will come up with a neural network that can produce better code than you and put all programmers out of work.
>>
>>51829410
>>>/india/
>>
>>51829431
pretty sure it's been being worked on for a while
there aren't going to be jobs in the future desu
it'll just have to do with maintenance vs labor pay
we'll all be harvesting strawberries and corn
>>
>>51829410

do you live in india? then you're good to go.
>>
>>51829046
Go has better closures even if it otherwise sucks as much as your reading comprehension does
>>
I know how to program but not how to program right, I know C# and can do stuff in it but I don't know about data structures, how to write good programs or stuff like that, algorithms I'm working on, basically what seems to me like intermediate stuff, how do I learn it? any recommended books?
>>
>tfw you submitted so many wrong answers on AoC that you got banned for being a spambot

maybe this programming thing just isn't for me
>>
>>51826927
>look at me im speshul xD
>>
>>51829950
Head First: Design Patterns
>>
>>51825909
 
#include <iostream>
using namespace std;

int main() {
const int NUM_VALS = 4;
int hourlyTemp[NUM_VALS];
int i = 0;

hourlyTemp[0] = 90;
hourlyTemp[1] = 92;
hourlyTemp[2] = 94;
hourlyTemp[3] = 95;

for(i = 0; i < NUM_VALS; i++) {
cout << hourlyTemp[i] << ", ";
}

cout << endl;

return 0;
}



the problem is I want the last number to NOT have a comma and space after it.

should I use another loop?
>>
>>51830116
????
   for(i = 0; i < NUM_VALS; i++) {
cout << hourlyTemp[i];
if(i < (NUM_VALS - 1))
cout << ", ";
}
>>
>>51830116
(string)(i == NUM_VALS -1 ? "" : ", ")
>>
>>51830092
I really really hated Head First when I picked one for learning C#, I'll give this one a look but I'm pretty skeptical

any other books that preferably don't treat you like a retard or a toddler with 0 attention span?
>>
>>51827986
>You need to call close() so that you can check the return status. Or do you just assume that everything always succeeds?
And what exactly are you gonna do when close() fails?
Process termination is defined to close all open file descriptors.
So as I said, if you want to be able to reuse some address/port immediately you should enable that option - that's what it's there for.
If you don't have a problem waiting on TIME_WAIT then there's again no problem - manual close() or close from exit() achieves the same thing.
>>
>>51830116
cout << hourlyTemp[0];
for (i = 1; i < NUM_VALS; ++i) {
cout << ", " << hourlyTemp[i];
}
>>
can you implement lambdas in C with macros
>>
>>51830152
what about
for(i = 0; i < NUM_VALS; i++) {
if(i) cout << ", ";
cout << hourlyTemp[i];
}
>>
>>51830116
change cout to a string then cout that string after the loop using:
tempstring = tempstring.substr(0, tempstring.size() - 2)
cout << tempstring;
>>
>>51830152
well that was stupid.

I was playing around with an if but I kept saying NUM_VALS - 2 instead of 1
>>
>>51830211
unfortunately I'm not allowed to do that. This is basic C++, we don't learn strings until next semester
>>
>>51830028
this
>>
>>51830172
yeh. I dunno what ones though. I recommend this one because it explains design patterns with a lot of good practical examples of when and why you would want to use each one. Apparently it's one of the better books for doing this. Most of the others are very academic.
>>
>>51830200
Nope, C macros only do text replacement, so you can't make them place text anywhere but their usage. So you can't make macros move the definition out of the function and replace the definition with a call. GCC has anonymous function declarations as an extension, you can use that.
>>
>>51830244
sounds like a class taught by pajeets
 for(i = 0; i < NUM_VALS; i++) {
cout << hourlyTemp[i];
if(i != NUM_VALS -1)
cout << ", ";
}
>>
>>51830244
>we don't learn strings until next semester
haha holy shit
this is what people are getting into decades of debt for
>>
>>51830337
Stanford doesn't even teach programming anymore.
>>
>>51830302
I'll still keep it in mind and give it a look, thanks bud
>>
>>51828504
>He said Python, not the still born nuisance known as Python
>>
>>51830337
You can pay off the debt you incur for a bachelor's within 5 years at a leisure rate at what the avg programming job earns.
>>
dudes, weed lmao.
>>
>>51830502
shut up
>>
>>51830493
That's only if you can manage to find work.
Enjoy washing dishes.
>>
>>51830337
I think the point is to teach beginners how arrays work before going into objects in the second semester
>>
>>51830551
>a whole fucking semester
my Intro to Programming with C course started from nothing and ended on binary search trees lmao
>>
>>51830493
This guy gets it.
>>
>>51830551
Am I reading this right?
It takes an entire year to teach people about strings?
Try to justify that, you can't.
>>
Is anyone here relatively good at Machine Learning?

Are there meant to be performance differences between online and offline techniques? I'm trying to determine if a online or offline linear perceptron is more accurate on average (over 30 data sets), but even though they seem better individually on some data sets it appears to balance out in the end.
>>
>>51830518
Yeah your right, programming jobs are rare when you live in a shithole .
>>
>>51830601
>>51830605
Remember that we're on /g/, and what kind of people would frequent this board in the first place. Intro courses are meant to be easy and introduce people to a topic. Going into BSTs in the first semester would most likely scare many people away from programming
>>
>>51830601
Same. Teacher went over most of the C language in half a semester (7 weeks) from 'this is a variable' to pointers to structs and malloc. And we spent the second half of the course doing a project of our own selection while he went over lists, binary trees, dynamic arrays and so-on.
>>
>>51830738
I'm not sure how you can justify spending an entire year on for loops and other basic things when that's the sort of thing you learn your first week when self-teaching.
>>
Can this trap OP meme fucking stop? thanks
>>
>>51830770
Introductory courses are supposed to teach to the lower common denominator, which is fucking gay IMO. Maybe going to trees by the end of an introductory course is too much, but ending on arrays would be too slow for me and most here I'd think.
>>
>>51830770
Because people are retarded and/or have only a cursory interest in the subject. Most people don't self-teach We, on the other hand, are already interested and try to learn for ourselves, taking intro courses only because we need the prerequisites for more advanced courses.
>>
How do people solve this probem?

I write the key required to encrypt/decrypt for my cipher.

But the key is hardcoded in the source...

anyway to hide the key, or will someone who gets access to server be able to get key (and decrypt all messages)?
>>
>>51830605
Well, strings actually are pretty complex constructions. For instance to truly understand algorithms like Aho-Corasick, Crochemore and Reverse Backward Oracle Matching, one has to know a great deal of things.
>>
>>51830830
Oops here's relevant code

Note how the KEY var is readable... is this normal or can people hide this?


from Crypto.Cipher import AES
from os import urandom
import sys

KEY = b'Sixteen byte key'


def encrypt(text):
""" encrypt plaintext """
iv = urandom(AES.block_size)
print(sys.getsizeof(iv))
cipher = AES.new(KEY, AES.MODE_CFB, iv)
msg = iv + cipher.encrypt(text.encode())
return msg

def decrypt(text):
""" return plaintext """
iv = urandom(AES.block_size)
cipher = AES.new(KEY, AES.MODE_CFB, iv)
msg = cipher.decrypt(text)[16:]
return msg.decode()


a = encrypt("Buy the gun for $300 dollars")

b = decrypt(a)

print(a)
print(b)

>>
Is anyone experienced in the absolute hell that is writing high-level data structures in assembly?
>>
>>51830845
You can prompt for the key when you run the script.
>>
>>51830842
it's a null terminated char array
i hope you're being facetious
>>
>>51830852
Yes byte layouts are your friend
>>
>>51830860
True, but it will be used by a web application with no command line inerface
>>
>>51830757
This was precisely how my class went. There were only 20 or so students in it so the odds are slim lol
>>
>>51830673
As far as I have understood, they solve different problems; but supposedly if they both get the same amount of data, they should converge to the same solution.
>>
>>51830868
>it's a null terminated char array
Don't confuse C char arrays with languages that have actual strings, sure their internal buffer is still a char array but the overall interface is advanced far beyond that.
>>
>>51830830
>>51830845
https://en.wikipedia.org/wiki/Salt_%28cryptography%29
?
>>
>>51830910
>internal buffer
I don't care about how your language likes to abstract strings, all it comes down to is how they're implemented in memory.
>>
>>51830873
By byte layouts you mean something like structs where every fields are at known offsets and each has a particular composite size?
>>
>>51830921
>I don't care about how your language likes to abstract strings, all it comes down to is how they're implemented in memory.
I don't care about your opinion, we're talking about strings here, not char arrays, two different terms.
>>
>>51825998
>not writing a C to Haskell compiler.
>>
>>51830926
Yes but things can be variable, you just need a something at a known location to take the variable size.
>>
>>51830868
Well yeah, in the most basic level strings are very simple. But when it comes to effective string processing, which is everywhere in computing, you are going to need rather complex algorithms and data structures. Programs like grep are a culmination of decades of research, not some childishly easy stuff that any first year compsci student could create without instructions.
>>
>>51830955
You sound like you have no idea what you're talking about.
>>
>>51830984
I'm studying stringology.
>>
>>51830984
If you're interested, take a look at how many POSIX-compliant systems implement keyword matching: http://www.opensource.apple.com/source/grep/grep-14/grep/src/kwset.c
>>
>>51830955
>decades of research

you mean math. Most of the algorithms you use today are all based off math from decades ago.
>>
>>51831131

I thought Dijkstra invented everything.
>>
I believe that the monadic approach to programming, in which actions are first class values, is itself interesting, beautiful, and modular. In short, Haskell is the world’s finest imperative programming language.
>>
>>51831162
Dijkstra was a mathematician that went deep in comp theory
>>
>>51831351

Also, he was a fucking genius, so that helps, too.
>>
>>51830921
>I don't care about how your language likes to abstract strings, all it comes down to is how they're implemented in memory.
Programmers don't deal in raw bytes for a reason. Text is extremely complicated.
http://unicode.org/faq/casemap_charprop.html#11
>>
>>51831385
All of the great "CS" guys were geniuses and mathematicians for the most part.
>>
>>51831299
>the monadic approach to programming
>in which actions are first class values
You don't need monads for that.
>>
>>51827010
B. I don't even call close() on WinForms stuff, I just throw an outofmemory exception and let the OS figure it out.
>>
>>51831439
Name a single good language with first class actions that dont obey the monad laws.
>>
>>51831464
>Enterprise code QA: Approved
>>
>>51831577
>good language with first class actions that dont obey the monad laws.
All the good ones.
>>
what if you could add member variables and member functions to objects at run time
>>
>>51831765
that'd be fucking dank bro
>>
What Android app should I make, dpt?
>>
>>51831814
An actual native Android IDE that can write and deploy apps without having to use an external computer.
>>
>>51831765
JavaScript does that.
>>
>Look up what a Trie is
>Example is in a Turing Tarpit language:
Lookup and membership are easily described. The listing below implements a recursive trie node as a Haskell data type. It stores an optional value and a list of children tries, indexed by the next character:

import Prelude hiding (lookup)
import Data.Map (Map, lookup)
 data Trie a = Trie { value    :: Maybe a,
children :: Map Char (Trie a) }

We can look up a value in the trie as follows:
 find :: String -> Trie a -> Maybe a
find [] t = value t
find (k:ks) t = do
ct <- lookup k (children t)
find ks ct
>>
>>51831765
every dynamic language.
>>
Can someone in /dpt/ explain to me what a ``frob'' is?
>>
Can someone tell me what I'm doing wrong?
I knew writing this in C was a mistake, but I've already spent too much time on this, and I've gone through 3 rewrites already.

http://pastebin.com/G5ffeRAz
>>
>>51831979
Post a screenshot of the AoC problem and your input please?
>>
>>51832038
Not him but you can try it against:
Day 12: https://paste.installgentoo.com/view/raw/4d1d34d3
Day 12 input: https://paste.installgentoo.com/view/raw/a22ea1a7

This is not his input, but given this input the answer is 87842.
>>
>>51832038
problem
http://pastebin.com/g5RUbsFP

input
http://pastebin.com/eZ4Us6fJ

>>51832075
Everyone has the same answer.
I've been considering just putting that number in, but i'd just be cheating myself.
>>
File: proj.png (1 MB, 1920x1080) Image search: [Google]
proj.png
1 MB, 1920x1080
Can't get Halo 2 to activate so I'm writing a program to rename / manage the campaign files. It can play the first 3 levels without activating so if you rename a map to one of those 3 it works
>>
>>51832123

Racket doesn't look so bad.
>>
File: 1428469460313.jpg (82 KB, 500x603) Image search: [Google]
1428469460313.jpg
82 KB, 500x603
How does realloc work?

Does it allocate a new memory location or just extend the current allocated location?
>>
>>51832201
Both
If there's extra room after the current location, it extends it. If not, it's moved to a new spot
>>
>>51832181
It's chill man. It's better to override methods of the GUI objects than putting everything in the call-backs (as I am) but who cares.
Any racket questions?
>>
>>51832201
Depends. If it can, it will extend, otherwise it'll get a new block.
>>
Give me one good reason not to malloc the target machine's entire memory block upon initialization.
>>
>>51832250
Give me one good reason to
>>
>>51832250
Because there is literally no reason to.
>>
>>51832264
-avoids potential memory errors
-allows the program freedom to operate without the real bounds of hardware rather than arbitrary bounds of software

there that's two
>>
>>51825909
>taking easiest exam of your life over an intro cs course
>so cocky you dont sleep for 28 hours
>Ill just grab a monster and itll be fine
>get to exam
>suddenly become dyslexic
>cant read English syntax anymore
>misinterpret every question to be 10x harder than it really is.
>tell teacher than what shes requiring I can do but its way beyond the scope of the class
>teacher just thinks Im phishing for answers
>spend 15 minutes explaining how the questions are wrong
>teacher gets fed up and throws a hint
>tell the teacher that its irrelevant
>suddenly able to read again
>apologize to teacher
they probably think Im an idiot but I aced the exam.
>>
>>51832275
Enjoy crashing your computer
>>
>>51831972
Yeah, what is a [FROB]?
>>
>>51832250
Your program isn't the only one running on the machine.
You're gonna force the machine to thrash the disks copying to the swap.
People will hate you.
>>
>>51831765
I think you can inject methods in lots of languages. I've never done it, though
>>
>>51832233
>Any racket questions?

None in particular. It's just on my list to learn, and it honestly doesn't look so bad.
>>
>>51832275
>avoids potential memory errors
You would have to write your own allocator in order to use that space properly, and you're basically back where you started.

>allows the program freedom to operate without the real bounds of hardware rather than arbitrary bounds of software
>real hardware
With virtual memory: no, you're not.
Only the kernel gets access to RAM directly.
>>
>>51825909
trying to learn C++ by writing a game using SDL2
>>
>>51832327
noice, did that in C about a month ago. Doing a platformer? top down?
>>
>>51832317
Aight man, I'm not gonna go all lisp fanatic on ya but it is pretty fun. Check out http://docs.racket-lang.org/ when you have a minute
>>
>>51832327
>trying to learn C++ by writing a game using SDL2
No. You dont learn C++ to practicality. You could use any language and method for that and it wont help. Open up an algorithms book and learn c++ that way so that when I ask you to sort a heap you know wth Im talking about and what I expect.
>>
>>51831963
how exactly is Haskell a turing tarpit?
also there's a Python example right below if you're too much of a faggot to actually read the code because of a stigma you associate with the language
>>
It's not even that hard.
int main()
{
for(int i = 0;;++i)
{
malloc(i);
if(!1) return i;
}
}
>>
>>51832357

Thanks, mang. Are there any good books? I always prefer a proper book.
>>
>>51832359
>sort a heap
That just isn't fun. I don't think I want to program as a career.
>>
>>51832275
If you think your program will need that much memory you should probably stop programming
Thread replies: 255
Thread images: 28

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.