[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: 29
File: DPT.png (389 KB, 934x1000) Image search: [Google]
DPT.png
389 KB, 934x1000
Old thread: >>51942683

What are you working on /g/?
>>
>>51949011
Is that sailor moon?
>>
1st for if you can't write C then you're a non-programmer
>>
Is the trap poster MIA?
>>
First for assembly master race
>>
File: 1450369221617.png (80 KB, 694x732) Image search: [Google]
1450369221617.png
80 KB, 694x732
>>51949011
>>
File: logo-and-text.png (18 KB, 396x120) Image search: [Google]
logo-and-text.png
18 KB, 396x120
>>51949043
#lang racket/base
(lambda (x)
(/ (foldr + 0 x)
(length x)))
>>
>>51949120
You can just AOT compile if you don't like byte code. What exactly is it you don't like about .NET and byte code?
>>
>>51949043
\x -> div (foldl (+) 0 x) (foldl (\x y -> (x+1)) 0 x)
>>
>>51949043
This is a dumb question. You write a function average(x) to average a list, sure, trivial (unless we're using C :^)). Then they want you to make it into a lambda? uhhh sure? \x -> average(x). What do we gain from making it a lambda?
>>
>>51949086
>I'm pretty fluent and contribute to a few open F# projects
oh yeah? Which ones? Or what kinds of projects are they if you don't want to drop names?
>>
Any suggestions on how to decrease the amount of code?
void Config::parse()
{
const size_t size = args.size();
for (size_t i = 0; i < size; ++i) {
const std::string &arg = args[i];

if (arg == ARG_SOURCE && i + 1 < size) {
source = args[++i];
} else if (arg == ARG_METHOD && i + 1 < size) {
method = args[++i];
} else if (arg == ARG_WINDOW_SIZE && i + 1 < size) {
try {
windowSize = std::stoi(arg);
} catch (const std::exception &e) {
throw std::runtime_error("config: invalid window size");
}
} else {
std::ostringstream msg;
msg << "config: invalid argument " << arg;
throw std::runtime_error(msg.str());
}
}
}

args is
const std::vector<std::string>&
>>
>>51949253
Nothing hardcore like the F# compiler, but as I work with F#, I've made a few smaller contributions to the libraries that I use.
>>
Would a job ever require me to use VIM

I keep getting the feeling that I should learn it but Atom is a lot easier.
>>
File: h4Ub9fZ.webm (3 MB, 720x404) Image search: [Google]
h4Ub9fZ.webm
3 MB, 720x404
Ask your beloved programming literate anything.
>>
>>51949282
Just learn basic operation. How to write some lines and how to quit. That's enough to get you by.
>>
>>51949043
[1.0; 2.0; 3.0]
|> (fun (nums) -> List.sum average nums)
|> printfn "%d"
>>
>>51949227
It's still going to be running in a VM, even if you're not distributing MSIL.
>>
>>51949282
Maybe if you're a sys admin.
>>
>>51949234
>foldl (+) 0 x
you mean sum x?
>foldl (\x y -> (x+1)) 0 x
you mean length x?
>div
this rounds down, are you sure you want this? is this a troll function?
>>
>>51949011
Doing project euler problem #11, I have this so far, it gets the largest product of any 4 adjacent numbers but it only scans horizontally.

http://pastebin.com/Cet0B7ek

How should I start scanning vertically?
I could make the input into a matrix and rotate it, so that I could simply have one (radically simple) function (or piece of code without its own routine) that scans and another one that changes the orientation.
The only hold up is that I fear the time complexity of matrix rotations.

The straight forward way would obviously be to have three different loops, one for scanning in each respective direction.
With this, though, I fear there will be too much duplicate code.
I would like to instead have a general interface to a function that scans in a particular direction based on arguments I give it.
>>
>>51949273
Bad programmers worry about code

Good programmers worry about algorithms and data structures

That being said you've got a bunch of conditionals with the same thing and a comparison so maybe do

if (i + i < size) {
switch (arg) {
case ARG_SOURCE:
// etc
}
} else {
// blah blah
}
>>
>>51949338
I thought the image was about doing it in a retarded way?
>>
>>51949322
and what exactly is the problem? Every functional language that I know of uses a VM of some kind.
>>
>>51949293
I can't wait to not do something like this in VR ever
>>
File: Fotolia_11453646_XS.jpg (64 KB, 404x297) Image search: [Google]
Fotolia_11453646_XS.jpg
64 KB, 404x297
>'main' must return 'int'

Literally ebola. Someone please explain the reasoning to me.
>>
>>51949354
this is basically what games like super mario would feel like in VR. get ready.
>>
>>51949353
I agree that it's no problem, but for whatever reason it seems to matter to the anon who asked the question.
>>
>>51949381
the operating system expects an exit code when your program quits, to get an idea if everything went okay.
>>
>>51949348
>switch string
>in c++

that's not D buddy
>>
>>51949381
When a program terminates, it returns an int to the operating system. 0 means "ok", anything other than that is supposed to mean some kinda error. By checking the return code of a program, you can know if the task went okay, or not - so when you're doing some automated script or whatever, you can use that.
>>
>>51949381
Because of exit status, one of many important concepts of real OSes like GNU/Linux
>>
>>51949348
Using a nested if statement will do. Too bad you can't do a switch statement on a string in C++.
>>
>>51949353
Haskell compiles to native code.
>>
>>51949419
http://www.cplusplus.com/doc/tutorial/control/
>Another selection statement: switch.
>>
>>51949043
average = lambda x: sum(x) / len(x)
>>
>>51949452
There's still a VM anon. .NET can compile to native too.
>>
>>51949419
>>51949442
That just raises the question of why in god's name someone would use string for something that takes a limited number of options like that.
>>
>>51949460
And?
>>
>>51949486
>why in god's name someone would use string for something that takes a limited number of options
I've always thought that C's fopen option string is quite elegant.
>>
>>51949273
Does this even work?
Wouldn't `i` go out of scope after the loop?
Also wouldn't you just be overwriting `arg` with each iteration?
And I would at least take out the blocks for single-consequent control contstructs.
>>
>>51949011
>C#
top kek

double d = 9000000000000000000d;
while (d == 9000000000000000000d)
{
d += 500;
Console.WriteLine(d);
}
>>
>>51949510
I prefer the ol' O_RDWR type options

Added benefit of being able to | a bunch of them together if the API is well designed
>>
>>51949482
how do you define a vm?
>>
>>51949141
you cant call an anonymous function /a/non
>>
>>51949576
>double d
This killed me.
>>
>>51949273
Hey wait a minute

>for (size_t i = 0; i < size; ++i)
>checking if i + 1 < size

what the hell are you doing
>>
Threadly reminder that there is nothing wrong with implementing a stack as a singly linked list.
void stack_push(stack_t *stk, int data)
{
frame_t *frame = (frame_t *) malloc(sizeof(frame_t));
frame->data = data;
frame->next = stk->head;
stk->head = frame;
stk->size += 1;
}

int stack_pop(stack_t *stk)
{
if (stk->head == NULL)
printf("Stack empty.\n");
frame_t *frame = stk->head;
int data = frame->data;
stk->head = frame->next;
stk->size -= 1;
free(frame);
return data;
}
>>
>>51949621
except when performance is critical or you have limited memory available, but hey, good luck to pass CS 101
>>
>>51949251
>I dont know what currying is
>I cant use lambda as part of my average function because I use built in list functions to do it
If you didnt youd see lambda is really useful here.
>>51949338
>I can only use built in functions to do this
disgusting
>>51949234
Only correct answer
(define (average x)
(/ (foldr + 0 x) (foldr (lambda (y z) (+ 1 z)) 0 x)))
>>
>>51949583
probably inaccurately. What I mean is all the run time stuff like garbage collection, bounds checking etc is still done with compiled code. That's probably not what a VM is really.
>>
>>51949141
>length x
Son Im disappointed.
>>
>>51949652
>Only correct answer

stop posting your faggot solution
>>
>>51949621
reminder that you should always program to interfaces:
Deque<Integer> stack = new ArrayDeque<Integer>();
stack.push(4);
...

later profiling reveals that a linked list implementation is more performant:
//only need to change this line 
Deque<Integer> stack = new LinkedList<Integer>();
stack.push(4);
...

later, you optimize with your own custom implementation:
Deque<Integer> stack = new MySuperfastQueueDoNotSteal<Integer>();
stack.push(4);
...
>>
>>51949706
>I dont know what fold does
Its okay. If you do a bit of reading you could probably understand.
>>
>>51949714
var stack = new ArrayDeque<Integer>();
var stack = new LinkedList<Integer>();
var stack = new MySuperfastQueueDoNotSteal<Integer>();

works just the same in all those examples, and is much cleaner and more readable.
>>
>>51949714
wouldn't i had to add function pointers or a vtable to the stack_t struct?
It'd look like
stack.push(stack, 4);
.
>>
>>51949684
ok, simple misunderstanding then. I thought you were referring to something akin to the JVM.
>>
>>51949774
It's pretty much like the JVM or CLR, except without the jitter.
>>
>>51949728

But I do, though.
>>
>>51949381
You don't have to return explicitly, 0 is assumed unless otherwise stated.
Why must the type must be int and not some other type?
Well, it can be void, or any type really.
However, returning a type that is compatible with int is equivalent to calling exit(return_code), returning a type that isn't compatible with int is undefined and for all intents and purposes breaks your shit and makes you a shit programmer.
You may return void, but this is a dick move, think about the OS.
What if you called a library routine and it fails but returns nothing and doesn't set errno?
That's how the OS feels when you return void from main.
>>
>>51949381
>not declaring main as a bool
Learn to program
>>
So, what exactly does it mean to `push` and `pop` to and fro a stack?
Do these terms apply to other things as well and not just stacks?
>>
>>51949913
in terms of a stack, push means to put it on top and pop means to take it off the top (the only way to access a stack assuming it follows specification.) Push and pop can be general though, e.g. a queue (FIFO) could push (put at back) and pop (remove from front.)
>>
>>51949940
Thx :3
Any idea where those terms come from?
>>
>>51950031
think of a pez dispenser
you push candy into it, and that candy can only be popped in the order it was pushed into the dispenser.
>>
>>51950031
Honestly, wherever they were first used in a specification/language. I can't tell you where but that's generally how it works: whoever does it first coins the term. The term can change of course, a good example of this is Dijkstra and his paper on semaphores.
>>
I posted this in /sqt/, but didn't get any responses.

I have a logitech g510s keyboard that I got a few months back. How would I go about making an app for the lcd display that shows GPU temp and usage, CPU temp and usage, and other stats like that? I already know a good amount of Python, but where do I start to make an something like that for this lcd display on my keyboard?
>>
>>51950105
find out if someone has made an SDK for that keyboard and it's LCD. Then check if that SDK has python bindings. It almost certainly doesn't though.
>>
>>51950105
>>
>>51950077
>The term can change of course, a good example of this is Dijkstra and his paper on semaphores.
Explain?
>>
>>51949120
Mine won't. Compiles using LLVM with no GC or anything like that.
>>
>>51949011
Fuck off weebs
>>
Where would be a good place to look for open source projects to contribute to in my free time?
>>
>>51950250
Find a project you use often and then think of ways to improve it.
>>
>>51950231
You compile and run .NET code without a GC?
>>
File: hopes and dreams.png (75 KB, 694x732) Image search: [Google]
hopes and dreams.png
75 KB, 694x732
>Go to interview
>pic related happens
Hardest question I've ever been asked.
>>
File: Xtra300.jpg (44 KB, 300x289) Image search: [Google]
Xtra300.jpg
44 KB, 300x289
>>51950264
This is the most common thing, but let's say that the stuff I use on a day to day basis are almost always either really big projects or closed source?

Where would I start looking in that case?
>>
>>51950327
No, I'm answering
>Is there any functional language that doesnt compile into some byte-code virtual machine bullshit
>>
>>51950339
What FP language doesn't have a GC? Ada?
>>
>>51950186
>>51950170

Okay, I found the SDK. Now what? It's a .dll file which I don't know what it does.
>>
>>51950332
>he hasn't read sicp
You should just kill yourself
>>
>>51950332
create a linked list implementation with the following function pointers stored in the head node
initialization
destroy
add node
remove node
>>
File: Screenshot (18).png (11 KB, 622x154) Image search: [Google]
Screenshot (18).png
11 KB, 622x154
>>51950368
>>
>>51950366
Ada is not a functional language.
>>
>>51949027

LISP hackers before C even existed == non-programmers
>>
im working on a stain/blood/dirt recognition system so i can interface with closed source plc units to identify and reject automatically product.

i have made zero progress but i am learning a lot.
>>
>>51950369
>>51950379
his was actually something I had to learn how to do back in uni for lisp. Some bs about the use of mutation. I did it in racket here but it was pretty hard doing it on the spot without references. My syntax was a bit off but the concepts were there so I dont think theyll look down on it.
>>
>>51950395
oh yeh
>>
File: 1447527600690.jpg (20 KB, 384x404) Image search: [Google]
1447527600690.jpg
20 KB, 384x404
>Shell languages
>Spawning an entire process and possibly multiple threads for every command.
>There are people here who actually unironically write whole programs in these languages.
Even a fucking scripting language is leagues better than a shell language, in both performance and sane syntax.
>>
>>51949831
>processes returning with ints

Join the Plan9 master reace boyo

(good writeup though)
>>
>>51950332
protip: before doing anything discuss what OOP means for the interviewer because that's a huge checklist nobody can agree on (and if you try to do everything that's gonna be one long interview)
>>
>>51950582
Slow development is far more costly than spawning a UNIX process.
>>
>>51950677
You write it once and run it many times.
>>
>>51950217
Dijkstra, who is Dutch, first called the operations on semaphores P and V for proberen and verhogen. Signal and wait are much more common for obvious reasons.
>>
>>51950582
>multiple threads

Oh no!!! you mean i could create and consume a stream of data in parallel?

THE HORROR!!
>>
>>51950684
There are some problems which don't require a 'fast' solution. That's where shell scripting comes in handy.

I do agree with the first post though that larger programs should at least be written in a scripting language.
>>
>>51950684
And then it breaks because the user doesn't have x program installed, or user has differing implementation of x program installed, causing incompatibility.
>You write it once and run it many times.
The exact same thing can be said about any scripting language, except the program is not only easier to write, but it also runs faster.

Literally the only thing shells languages are good for is small init scripts like starting some programs daemons upon starting the X server or window manager.

>>51950732
Thread creation has huge overhead, that's really really bad if your doing that every command, imagine if you entered a loop! that'd be slow as all fuck.
>>
File: Screenshot_2015-12-19_15-12-52.png (42 KB, 1601x899) Image search: [Google]
Screenshot_2015-12-19_15-12-52.png
42 KB, 1601x899
Having fun putting in more entries for my assembly reference.
Lot's
and lot's
of fun
>>
Any expert programmers here? I'm supposed to design an algorithm that can search, insert and delete in O(1) worst case.
>>
>>51950843
you can insert and delete in O(1) with a linked list but good fucking luck traversing in O(1) with any form of data structure.
>>
>>51950843
>search, insert and delete in O(1)

A list with a maximum of one element.
>>
>>51950843
For some N that is larger than the size of any input, it does N iterations for each operation, independent of the actual size.
>>
What's the difference between the overflow and the carry flag?
Is it okay if my VM only has an overflow flag and uses it for carry? since there doesn't seem to be any reliable way to detect carry, and as far as i can tell, overflow is the same thing as carry anyway, and both GCC and Clang provide __bultin_x_overflow() to reliably and efficiently detect overflow.
>>
>>51950791
>Thread creation has huge overhead,

define "huge" on modern OSs with lightweight threads and COW paging.
>>
>>51950944
Oh god it's been forever since I've done this, but iirc the carry flag is set for each operation that carries over to the next whereas the overflow is set at the end when overflow occurs. You'd need separate flags because your last carry could be equivalent to signaling overflow but overflow may not have occurred.

I hope we're talking about the same thing. ;_;
>>
How do I motivate myself?
I've been trying to work on my programs for a while and I just can't bring myself to code anymore.
>>
>>51950889

That was my initial guess also, but other aproach would be to make those operations nonterminating.

I think it still counts as O(1)
>>
>>51951049
Okay, i just did some googling.
So carry occurs in unsigned arithmetic, and it happens when the result requires more bits than you've got, so you need to do two operations.
And the carry flag happens in signed arithmetic when the sign bit changes. This correct?
Okay so GCC and Clang both provide builtins to detect overflow, but how can i detect carry?
>>
>>51951118
>And the carry flag happens in signed arithmetic
Sorry, overflow flag.
>>
>>51951054
Create goals for yourself. Do you want to have a nice job, where people respect you? You earn good money, have a nice car and house and score a qt3.14 wife with your increased self confidence and self esteem? Or do you want to be a miserable cunt your whole life? Think of your dream project, what kind of stuff do you really want to do. What do you need to do to achieve those goals? Decide and start working towards them now. Don't feel like working on it today? You'll never make it. Know that not working towards your goals when you should will mean you'll never get what you want. Decide what you want more, more time to procrastinate for years on 4chan, or have an actually fulfilling life long term.

Hope that helps. Works for me.
>>
>>51950843
You cant search in O(1). You have to know where its already at. With an array you can delete by moving the last element of the list into that spot but the search would have to take the index of the array you want.
also
>worst case O(1)
KEK
>>
>>51951249
baited xd
>>
>>51951085
perfect hash table.
>>
Reminder that an O(n) cache-friendly algorithm may outperform an O(log n) cache-thrashing algorithm in all practicality.
>>
>>51950843
Hash table m8.
>>
>>51950366
None. You need a Gc to avoid state.
>>
>>51951295
that means you have index keys but that's not a guarantee in general for "algorithms"
>>
>>51951362
That's false, and even then, purity doesn't mean "no state". Purity means checked side effects using either linearity, monads, or some other equivalent.
>>
>>51951361
hash tables are not O(1) worst case, sadly.
>>
>>51951389
What FP languages don't have GC?
>>
>>51951361
>hast table
>worst case O(1)
Nope. Its O(N) if you have to go through the entire array due to collisions.
>>
>>51951402
ATS, and mine that I'm working on.
>>
File: dick9we.jpg (47 KB, 640x480) Image search: [Google]
dick9we.jpg
47 KB, 640x480
>>51951276
>baited xd

You devious bastard. You just ruined all of our life
>>
>>51951118
yeah that's right. When it comes to carry:

You have two values A and B that fit in 4 bits. When you perform an operation on them, the result C doesn't fit in 4 bits. So the result C must be less than A and/or B, right? I wish I still had my materials on this stuff, I could tell you for certain.
>>
>>51949756
Until it's a return variable. Or large legacy code.

Var and auto are cancerous Band-Aids over poor language design failures.
>>
>>51951468
>Var and auto are cancerous Band-Aids over poor language design failures.
Care to explain? I'd say that not being able to have var/auto is a failure of language design.
>>
>>51951488
there are languages that do this?
fucking nasty
>>
>>51951468
>Until it's a return variable. Or large legacy code.
How are either of those in any way a problem?

>Var and auto are cancerous Band-Aids over poor language design failures.
Not at all. They are just used by good programmers who know how to keep things simple without creating problems.
>>
I want to create Windows applications. Does /g/ recommend C, C++, or C#?
I learned Python, but I want something that's compiled instead so I can run it on other machines.
Which do you guys recommend?
>>
>>51951546
C
>>
>>51951488
not OP but basicly need keywords for stuff like this if type inference is added to the language as an aftertought
>>
>>51951559
What are the advantages of C vs. C# and C++
>>
>>51951540
This guy gets it. in F# everything is declared with auto by default, unless you specifically add more code to specify you want the variable to be of a certain type.
>>
>>51949555
>>51949610
I loop over the arguments.
The array looks like:
--argument
value
--other-argument
othervalue
...

So each time I find the key, I know that the value should be the next element of the array.
>>
>>51951593
C lets you write applications for any language.
C# is an interpreted bytecode language like Java, only you're stuck on windows permanently.
>>
>>51951598
>>51949756
I find I type annotations so useful I write them even when optional. Auto is useful on occasion, though.
>>
>>51951619
>you're stuck on windows permanently.

mono seems to work
>>
>>51951563
type inference is part of F# by default, and many other languages. you still need to write "let" before a variable declaration to make clear you are declaring a new variable and not trying to set or compare the value of an existing variable. The same way you need to write "var" before variable declarations in JS, even though there's no static typing in JS (though TypeScript will infer the types at compile time without any extra type declarations).
>>
>>51951650
I agree that sometimes type annotations are practically necessary for documentation/safeguarding, but if I had to actually define the type of all lambdas/auxiliary functions (bound using "where") in Haskell I'd go insane.
>>
>>51951654
You're not getting winforms anytime soon.
Just write your application in an OS agnostic language like C/C++.
>>
>>51951619
What about C++? Everywhere I read it says that C++ is basically C, but better
>>
>>51951422
>ATS
Lel ats is both functional and imperative. When using references with functional code, a Gc is needed.
http://ats-lang.sourceforge.net/DOCUMENT/ATS2TUTORIAL/HTML/c642.html
>>
>>51951650
I find they're usefulness if kinda overstated. They create more of a burden than benefit in most cases. Cleaner, easier to maintain code is more valuable. I'll agree it's down to taste largely. But when you use a language like F# or even TypeScript were all the variable types are inferred by default, writing the type declarations each time feels like a waste of time and an unnecessary burden on the readability of the code.
>>
>>51951593
>What are the advantages of C vs. C# and C++

C is the lowest level you can go while still being portable. You can't write assembly language that works across different CPU architectures (e.g. x86 vs PowerPC). But you can write the same C code and compile and run it on different platforms.

THAT DOESN'T MEAN THAT ANY PROGRAM YOU WRITE CAN RUN ON ANY PLATFORM.

It means that any "hello world", or otherwise self-contained program will. As soon as you start touching external libraries, you're no longer portable. You then need some kind of intermediate abstraction layer if you want portability.

C# is like Java, in that it's OOP-oriented and complies to virtual machine instructions. The development tools are pretty great. Java can be run on everything from desktops to web servers to embedded microcontrollers. C# is mostly on Windows desktop and servers. In the future, it may be just as reasonably to deploy C# on Linux servers, but it's unlikely that you'll ever be able to write GUI applications for both Windows and Linux in C#.

C++ is a clusterfuck. The language has improved *dramatically* with C++11 and C++14 (new standards), but it's still a clusterfuck. It's an ugly language with extremely complex implications. It's not worth your time. Use C for systems stuff, use C# or Java for higher level stuff.

C++ is only talked about on /g/ because there are misguided 19 year olds who think that wasting time on a poorly thought-out language makes them superior to others. It's just alpha-nerd bullshit, their hormones tell them it will get them laid.

BTW I'm a C++ programmer.
>>
Is it "wrong" to post my Euler project code on my Github?
>>
>>51951720
C++ is a giant bloated extension of C.
You can do nice things in it, but most people end up overengineering their programs because they feel compelled to use all of C++'s featureset.
It does have a massive standard library tho.
C does not.
C is literally the combat knife of programming languages, while C++ is a chainsaw.
>>
>>51951540
The majority of arguments I've heard from senior engineers regarding auto in c++ has to do with the ugliness of defining and managing template and related variables. That is a crude way of avoiding fixing the underlying problem with the language.
>>
>>51951667
you can make comparison == or eq
also you can use := for declaration
even if you use let in most of languages you need only one let for arbitrary many declarations
>>
>>51951691

Why are you talking about Winforms in 2015? WPF.
>>
File: adelman_leonard_2.jpg (7 KB, 250x250) Image search: [Google]
adelman_leonard_2.jpg
7 KB, 250x250
Transferred from a state school to a school that is trying to break into the top 10 in CS. And jesus fucking christ the level of work is so much higher than my previous school. I retook Data Structs because I thought my last school did a shit job on the material, and now I find myself actually understanding Intro to Algos (which I didn't before last semester). So that's something I guess.

Really scared for my Algorithms class. Being taught by Leonard Adleman. Yeah, the "A" in RSA Encryption.
>>
>>51951723
Never mind, then. Guess I'll be the first to make a pure functional language with no GC.
>>
What the fuck i'am i doing wrong?

#!/usr/bin/env python2 

import sys # Used for the sys.exit function

target_int=raw_input("How many integers?")

try:
target_int=int(target_int)
except ValueError:
sys.exit("You must enter an integer")

ints=list()

count= 0

while count< target_int:

new_int=raw_input("Please enter integer {0}:".format(count + 1))
isint = False

try:

new_int= int(new_int)
except:

print("You must enter an integer")

if isint == True:

ints.append(new_int)

count += 1

print("Using a for loop")
for value in ints:

print(str(value))

print ("Using a while loop")


total = len(ints)

count = 0

while count < total:

print(str(ints[count]))

count += 1


The output
 ile "connstruct.py", line 24
except:
^
IndentationError: unexpected unindent


spacing's arent the issue i double checked
>>
>>51951619
>C# is an interpreted bytecode language like Java, only you're stuck on windows permanently.
Could no be further from the truth

>>51951691
>You're not getting winforms anytime soon.
http://www.mono-project.com/docs/gui/winforms/
It's been part of mono for years now. I don't even remember when it didn't work. Do try to keep up.
>>
>>51951724
It is a matter of taste and it is highly useful when you're writing lambdas. But in that particular case,
Deque<Integer> stack = new MySuperfastQueueDoNotSteal<Integer>();

is more readable than
var stack = new MySuperfastQueueDoNotSteal<Integer>();

because I need to read the shole statement in the latter and I dont need to read anything beyond the equals sign in the former.
>>
>>51951720
>Everywhere I read it says that C++ is basically C, but better

Filthy lies.

C++ is better in the same way as a 220 lbs girls is twice as pretty as a 110 lbs girls

ps: i'm not encouraging the use of C either
>>
>>51951786
try triple checking ;^0
>>
>>51951757
I would say that's actually more of a credit to type inference than a failure.
>>
>>51951765
I'm assuming you're referring to USC, which is a good university, but it's not a top 10 CS school by any widely used rankings.
>>
File: ewrtrerw.jpg (20 KB, 500x375) Image search: [Google]
ewrtrerw.jpg
20 KB, 500x375
Business idea:

HTML5 tower defense game based on the migration crisis.

Thoughts?
>>
>>51951546
>I want something that's compiled instead so I can run it on other machines

I have no idea why you think this is the case or what you are trying to achieve.
>>
>>51951766
Lel. Good luck then. You can't maintain referential transparency with explicit memory management for obvious reasons.
>>
>>51951839
ill help build it
>>
How do I get people to use my software? Is shilling the only way?
>>
>>51951852
>You can't maintain referential transparency with explicit memory management for obvious reasons.
Sure you can, with linearity.
>>
>>51951740
>Use C# or Java for higher level stuff.
No, just no. Both languages are fine for your normal 'app' stuff, but when you're doing heavy computation C# and Java shit themselves.
That's why C++ is still used. It's practically as fast as C, but provides some higher level stuff.
>>
>>51951839
Enjoy getting your hosting terminated because of SJWs.
>>
>>51951810
>I don't need to read anything beyond the equals sign in the former.
Of course you do. How do what you were the Deque<Integer> came from and how it was created if you don't read the right side? In this example the right side will inform me of the performance characteristics I can expect. Or it might happen that MySuperfastQueueDoNotSteal is not very well tested yet, and may be a potential culprit for any bugs I find. The right side informs me that this queue is brand new, is empty, and has no chance of being null. How can you not read the right side?
>>
>>51951766
>pure functional language with no GC

what's your roadmap for resource handling then?
do you have a writeup somewhere?

Is your language publicly hosted?
>>
>>51951852
>obvious reasons
do elaborate
>>
>>51951835
They're trying to break into the top 10 for CS. The sequence and courses have been completely overhauled.
>>
>>51951834
Type inference is way cool it's just that auto is not that good at it.

though i heard it is much better in C++14
>>
So C is easier to learn than C++. But C++ offers larger libraries.
And C# is an interpreted language.

Basically C is the best option because it's not a clusterfuck.
>>
>>51951994
>And C# is an interpreted language.
>>
>>51951994
just learn C++ and you can easily learn C.
>>
>>51951917
>what's your roadmap for resource handling then?
Linearity >>51951886, I got the idea from papers about "linear capabilities". It's fundamentally C style malloc() and free(), and using linear capabilities, the type system doesn't let you forget to free anything or use an invalid pointer, stuff like that.

>do you have a writeup somewhere?
I don't have the skills to formalize things yet, so no.

>Is your language publicly hosted?
It will be free software.
>>
>>51951994
>C# is an interpreted language
stop this meme
>>
>>51949756
All you want to know about those is that they're Deques.
>much cleaner
A program that abstracts the implementation details is cleaner.
>>
>>51952006
>not writing a C# interpreter in C#
>>
>>51951994
C# compiles to an intermediate bytecode which is executed by a virtual machine, an idealized cpu middleware that gets ported to every platform the language supports.
>>
>>51951913
I sort of glance at it, yeah. But by the time I get to "= new", I know that it is an empty stack. I know what to expect from it.
>How do what you were the Deque<Integer> came from and how it was created
This is my exact problem with var, actually. Imagine the following code:
var stack = makeNewStack();

ho boy. What's the type of stack? now I need to jump to the definition of makeNewStack and read it. God help me if the developer didnt annotate the type of makeNewSack. I could spend whole minutes trying to figure out what to expect from this stupid 'stack' variable, all because the programer was too lazy to write an annotation.
>>
>>51952033
One already exists.
>>
>>51952009
No, learn C and you can easily make use of the good parts of C++.
Most of C++ is horrible.
>>
>type inference is crippled by imperative, object oriented languages
No shit
>>
>>51952009
wouldnt be easier to learn c then c++?
>>
>>51952049
>But by the time I get to "= new", I know that it is an empty stack.
no you don't. It might be a stack that accepts initial items in the constructor. And again, depending on what it is it may be faster or more buggy, and that's worth knowing about.

>What's the type of stack?
Doesn't matter, all you need to know is that it's a stack. Wasn't that your point?

>I could spend whole minutes trying to figure out what to expect from this stupid 'stack' variable
hovering over stack in any IDE will tell you what the type is. Will take 2 seconds at most.
>>
File: intrigued.gif (59 KB, 372x200) Image search: [Google]
intrigued.gif
59 KB, 372x200
>>51952010
>papers about "linear capabilities".

can you point me to some?
>>
>>51952049
Wow, you might actually have to understand the code before you start shitting out your own!
>>
>>51952138
>hovering over stack in any IDE
Doing this is a huge pain. I need to take my hands off of my keyboard, move them to the mouse, move the mouse to the variable, double click it, stroke my neckbeard, read the type (which should have already been on my screen) then move my hands back to my keyboard.

Besides, we are taking about "readability." Readable code shouldn't need an IDE or other complex programs to be read. That's what readable means, that you can read it without difficutly.
>>
>>51952145
Just google "linear pointer capabilities", the first few things that come up should give you an idea.

The way I envision them being used practically requires both dependent types and linearity, where a given capability's type depends on the value of the pointer (which is basically always a variable). There is also a type-level "reference count" which is used to determine whether the capability is unique, which gives write/deletion access while still permitting concurrent reads.

From what I can tell, they're basically a more formal, first-class version of Rust's lifetimes.
>>
>>51951839
Sounds racist.
>>
>>51952250
>Just google "linear pointer capabilities",

yeah i've googles "linear capabilities resources" but that didn't give me anything usable
>>
>>51952145
>>51952250
Some example types:

// Heap is linear, guards the side effect (sort of like the IO monad)
new : Heap -> (Heap, ptr : Ptr a, Cap ptr 0)
delete : ptr : Ptr a -> Cap ptr 0 -> Heap -> Heap

fork : Cap ptr m -> (Cap ptr (m + 1), Cap ptr (m + 1))
join : Cap ptr (m + 1) -> Cap ptr (m + 1) -> Cap ptr m

// shared reads, unique writes
load : ptr : Ptr a -> Cap ptr m -> (Cap ptr m, a)
store : a -> ptr : Ptr a -> Cap ptr 0 -> Cap ptr 0


>>51952285
There aren't really any papers about them, the way I've described them. It's just the idea that the pointer itself should be separate from whatever facilitates the static verification.
>>
>>51952213
Posts like this is why I love /g/

>hovering over stack in any IDE... is a huge pain
>I need to take my hands off of my keyboard, move them to the mouse, move the mouse to the variable
If this takes longer than 1 second, please see a doctor.
>double click it
>hovering over stack
>double click it
>hovering
okay. keep going.
>stroke my neckbeard
bonus points for making fun of your own argument
>read the type (which should have already been on my screen)
so... not really taking extra time then.
>read the type (which should have already been on my screen)
yeah, you'll need to have a rest after that. How long did that take you in the end?

>Readable code shouldn't need an IDE or other complex programs to be read.
True. but you don't really need an IDE to know makeNewStack() returns a Stack either.
>>
When implementing singly linked lists, why should all elements be pointers? I understand that there needs to be a pointer to the head, but I really don't understand why all the other elements have to be pointers. It's very confusing.
>>
>>51952416
struct Node<T> {
T value;
Node<T> next;
};

Nothing looks wrong to you about this?
>>
Using Racket and C for some shit and I need to allow Racket to call into the C code. My two options are basically to make the C code a daemon (which is a lot more complexity than I want) or two embed the Racket interpreter and then provide extensions for Racket as part of that, but the Racket docs don't talk about that at all (embedding and extending are mentioned separately, despite being grouped together here: http://docs.racket-lang.org/inside/overview.html#%28part._embedding-and-extending%29. Does anyone know if/how you can do both at the same time? If not I might just switch to using Guile.
>>51952350
Hey man, nice to see you back here again. Haven't seen you post in a while~
>>51952416
Because you can't describe the size of a list ahead of time. C's structs are all about size of objects (they work by memory offsets). How would you be able to know the memory offset of a 2 item list versus a 3 item list at compile time?
>>
>>51952433
>>51952440
So just make 'next' a pointer and declare it with the reference of a normal node then?
>>
>>51952350

But this seems like something which would allow _more precise and easier_ GC. Why does this makes you want to omit it?
>>
>>51952460
yep. the next node will have a reference to the one after that and so on.
>>
>>51952475
Yeah, so why do all nodes have to be pointers?
Option a) would be
a->next = b;

whereas b) would be
a->next = &b;

where b is just a normal, non-pointer node
Why is this not a thing?
>>
>>51950332
For those who dont know how to do this heres how I did it for the interview in racket
(define object
(let ((var '('var1 'var2 'var3)))
(define (method call)
(cond ((eq? call 'setvar1) setvar1!)
((eq? call 'setvar2) setvar2!)
((eq? call 'setvar3) setvar3!)
((eq? call 'getvar1) getvar1)
((eq? call 'getvar2) getvar2)
((eq? call 'getvar3) getvar3)
((eq? call 'sum) sum)
(#t(error "Bad method name"))))
(define (setvar1! variable)
(set! var (cons variable (cdr var))))
(define (setvar2! variable)
(set! var (cons (car var) (cons variable (cdr var)))))
(define (setvar3! variable)
(set! var (cons (car var) (cons (cadr var) (cons variable '())))))
(define (getvar1)
(car var))
(define (getvar2)
(cadr var))
(define (getvar3)
(caddr var))
(define (sum)
(foldr + (foldr + (foldr + 0 (getvar1)) (getvar2)) (getvar3)))
method))
>>
aaaaaaaaaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAaaaaaaaaaaa
>>
>>51952508
b
>>
What laptop do you guys use for school?
>>
>>51952500
struct s {
struct s a;
};

you have a struct in a struct in a struct ... ad infinitum
it's impossible practically
pointers aren't an actual instance of the struct so you can have a pointer to the same type of struct in that struct
>>
>>51952500
If not a pointer than it cant be a struct
>>
>>51952469
Performance. After type checking and type/proof erasure, all you have left is something that can be straightforwardly translated to an intermediate representation like C or LLVM and compiled without any sort of garbage collector.

But you're not wrong, most of the papers about capabilities really just use them as a starting point to talk about regions, which are a precise and relatively fast form of garbage collection. A decent compromise between manual memory management and overarching garbage collection schemes.
>>
console.log(10 == "10"); // true
console.log(0 == false); // true
console.log(' \n' == 0); // true
console.log(' ' == 0); // true


Kek. Why is JavaScript so retarded, /dpt/?
>>
>>51952522
x220 with arch
>>
File: ponder.jpg (61 KB, 640x480) Image search: [Google]
ponder.jpg
61 KB, 640x480
>>51952508
Also a valid point
>>
File: 1448949815568.png (547 KB, 457x570) Image search: [Google]
1448949815568.png
547 KB, 457x570
>>51952539
I sure am fucking glad I don't use Javascript.
>>
>>51952528
What I meant was
struct s {
struct s* a;
};

And then making that pointer point to just a normal node
That way it would still be a pointer
>>
>>51952358
Multiply the inconvenience by the number of times you use 'var.' var this, stoke my neckbeard, var that, stroke my neckbeard, var a, stroke, var b, stoke, var c, stoke. Then multiply that by all other people who will be reading your code (you are contributing to open source projects, right anon?). You can imagine a scenario where you could power a small city with wasted energy from all the neckbeard stroking as a result of your bad code.

Over time, this will add up, contributing to global warming. Unless we put a stop to it, excessive use of var could literally destroy the world.
>>
>>51952536
>Performance
Aren't computers supposed to be super fast nowadays?

Anyways thanks for pointing me to this research. It is really interesting
>>
>>51952607
that's literally what you're supposed to do matey
>>
>>51952500
a struct is a value type, unlike classes in most languages. that means that when a struct is
struct x {
int a;
int b;
};

then you have 2 ints in a row in memory, as in: ..., a, b, ...
if you have a pointer to a and then add sizeof(int) to it, you reach b
if you were to have a list without pointers to the next value then where would the next node be located?
next would be offset by sizeof(struct node), but then its next field would be offset by an indeterminate amount (since the fields are part of the memory size of the current object).
if that happened, the size of every single node would not be determined until the program is run.
this doesn't work for C because C is all about manipulating memory (and also because generating code for that would be impossible unless you filled up your memory with all sorts of values to mark where everything is located and then iterated over all of memory to find that whenever accessing a variable, etc.).
tl;dr for things to be able to be located relative to a memory address everything must be known as soon as the program has been compiled and using non-pointer nodes would make that impossible.
>>
>>51952586
It's ok if use triple equals all the time.

console.log(10 === "10"); // false
console.log(0 === false); // false
console.log(' \n' === 0); // false
console.log(' ' === 0); // false
>>
File: 1449088853998.jpg (33 KB, 419x419) Image search: [Google]
1449088853998.jpg
33 KB, 419x419
void* ptr;
void * ptr;
void *ptr;

Which is correct, /g/?
>>
>>51952625
Yes. I am a bit obsessive about performance since I'm geared towards game development, but it's also almost out of spite for people who think the only way you can have safe code is to write in languages like Java where you have tons of redundant bounds and null checking, glorified under the name "defensive programming".
>>
>>51952619
>Multiply the inconvenience by the number of times you use 'var.'
inconvenience that doesn't really exist though. 99% of the time at least you can easily infer what the type of the variable will be by reading the right side. I can't think of an example where this isn't obvious.
>>
>>51952539
Pro tip: look up variable hoisting.
>>
>>51952676
void *ptr;

Because this wouldn't make any sense otherwise:
void ptr, *other;
>>
>>51952685
var stack = makeNewStack();
>>
>>51952536
I think you're missing the most important part of programming: the human mind.

Nobody wants to write fork and join everywhere. This is the same reason why these ugly "safe C replacements" never go anywhere.
>>
>>51952676
which is correct, /g/?
void* ptr, ptr2, ptr3;
void * ptr, ptr2, ptr3;
void *ptr, *pt2, *ptr3;
>>
>>51952676
trick question. void pointers are evil
>>
>>51952736
that depends what you want
>>
>>51952686
Yeah, I found out about that recently, I finally understand why JSlint gets all anal about not having variables at the top of the scope.
>>
>>51952685
Legacy code. Specifically, dealing with return types from libraries that are not explicitly clear in the naming of the functions..
>>
>>51952719
You don't necessarily have to. It's like a formalization that's still part of the programming language itself, the "front end" of syntax could easily be designed so that fork, join and even delete could be inserted automatically, using a mechanism like RAII, just in a functional language.
>>
>>51952759
Void* is an essential part of any true c programming.
>>
Can someone explain to me what is actually different between VB.NET and C# apart from VB's awful syntax?
>>
>>51952711
Just a guess now anon, but I think stack will be of type Stack.
>>
>>51952808
C# and VB are different languages that interface with the same .NET.
>>
>>51952787
>dealing with return types from libraries that are not explicitly clear in the naming of the functions..
example? function names that don't make it clear what type they return are brutal in any language.
>>
>>51952804
Just as pooping is an essential part of life. I'm still not looking forward to it.
>>
>>51952808
I can't, because there is no other difference.
>>
What's some good projects to add to my github that'll look good on a resume?
I'm done with personal projects and want to work on my portfolio now.
>>
>>51952846
void pointers aren't even the worst of C.
Pooping isn't that bad either, depending on your diet of course.
>>
File: spoiler-alert-dw.jpg (22 KB, 514x360) Image search: [Google]
spoiler-alert-dw.jpg
22 KB, 514x360
>>51952808
the syntax _and_ the semantics
>>
Reading TAOCP Volume 1. Good god is MIX an unintuitive mess. What architectures is it most similar to?
>>
>>51952863
Write a personal project and get a few hundred people to use it.
>>
>>51952863
bump, I've been trying to come up with a project idea for a couple weeks too.
>>
>>51952828
There is no guarantee of that. In fact, there's no indication of what interface the returned object actually follows. Anyone new to this code will have to examine the function itself to have any clue.

If it's your own damn codebase then that's fine. IDEs also obliterate the problem.

But those arguments can be used to excuse literally any unobvious components of a codebases or language.
>>
>>51952870
>Pooping isn't that bad either
They're a huge inconvenience no matter what the situation
>>
>>51952846
>I fear defecating
LOL. Morbidly obese american detected with horrifying chronic digestive disorders brought on by years of eating a standard american diet.
>>
>>51952870
>aren't even the worst
>isn't that bad either

that seem to be on par for me :)
never said any of them are the "worst"
>>
>>51952902
But void pointers aren't an inconvenience. Pooping is good because it lets you get rid of waste. I'd rather be interrupted for a few minutes than defecate through my pores.
>>
>>51952901
>There is no guarantee of that.
There's no guarantee of it with type annotations either. It just won't compile if the annotation is wrong.
> there's no indication of what interface the returned object actually follows
It will follow the Stack interface anon. I hope you're learning something.
>>
>>51952904
I never said i fear void pointers boy.
Learn to comprehend
>>
>>51952942
Some time to think on the throne is always good.
>>
>>51952942
Oh I wasn't him who was arguing about void pointers, my bad for not mentioning. Just replying to the poop thing. Yes, it's necessary and good and I do it when I feel it, but it's not something I feel joyous about and excited to go and do.
>>
>>51952902
If you have a good diet, your shits will be hassle free and usually don't even require wiping.
If you live in a civilized country where people have bidets in every home, you don't even need to wipe, you get a little spritz to enliven the senses.
>>
File: 1445539908923.jpg (47 KB, 500x495) Image search: [Google]
1445539908923.jpg
47 KB, 500x495
>search for a way to implement something in c++
>500 identical forum posts
>'use the boost library ;)'
Every time.
>>
>>51952901
Just let him be. If he doesn't understand why more information might be useful to other people, he wont be able t use any information you give him.
Thread replies: 255
Thread images: 29

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.