[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 | Free Show | 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.

Thread replies: 317
Thread images: 24

File: anime.png (786KB, 1000x1300px) Image search: [Google]
anime.png
786KB, 1000x1300px
Previous Thread: >>56496465

What are you working on, /g/?
>>
>>56502171
D
>>
D2
>>
File: youknowtheone.png (369KB, 768x300px) Image search: [Google]
youknowtheone.png
369KB, 768x300px
>Dependent Haskell
>ETA 2018
>earliest
>>
COBOL?
>>
File: anal beads.png (296KB, 597x763px) Image search: [Google]
anal beads.png
296KB, 597x763px
>>56502171
>What are you working on, /g/?
Fooling around with making a Discord bot in C#.

Right now it just does some basic things, like serves up music and images from my machine if I'm online, dicerolls, and tells you it loves you if you're feeling lonely.

If they release a Tay API, I'll hook it up to that so any Discord server can have their own literal Hitler.
>>
finna write the world's most vulnerable telnet server in C, for a half-baked MUD that nobody will play and which I will abandon in about a week
>>
File: anal beads.png (21KB, 546x420px) Image search: [Google]
anal beads.png
21KB, 546x420px
>>56502234
Syntax is pretty simple, too.

It also will just swallow fuckups and log errors instead of breaking if you want it to, which makes it "just werk" when people try to break it.

https://github.com/RogueException/Discord.Net
>>
>>56502224
Just use Idris.
>>
File: 71.jpg (23KB, 300x100px) Image search: [Google]
71.jpg
23KB, 300x100px
>>56502366
>Vectors are linked lists
>>
If you want to find out what arguments you can pass into Scapy functions, you can use the function ls(), to provide you with that information.

Does anyone know if there is a ls() equivalent for generic Python? Pycharm is pretty useful at telling you what arguments can be passed in?

Anyone?
>>
>>56502399
Implement your own contiguous vector if you don't like it.
>>
File: 4459353701_826a3c120d.jpg (126KB, 489x400px) Image search: [Google]
4459353701_826a3c120d.jpg
126KB, 489x400px
>Actually C++ is more type safe then Java and C# because of const correctness.
>>
>>56502441
>Actually C++ is more type safe then Java and C# because of const correctness.
What the fuck.

Link to the poster of this so I can laugh at their expense.
>>
>>56502493
>>56502158
>>
>>56502441
no one actually says that tho
>>
>>56502507
kek
>>
>>56502509
>>56502158
>>
How did you guys memorize all of the built-in functions of Haskell? I find myself rewriting them sometimes because I forget it already exists. Should I literally just use flash cards etc?
>>
>>56502796
regular use + auto complete
>>
File: compare.jpg (692KB, 1920x1972px) Image search: [Google]
compare.jpg
692KB, 1920x1972px
Which style of editing would you prefer?

>top
When you click the edit button, the editable elements are replaced with text boxes. A submit/cancel button appears at the bottom of the side-bar.

>bottom
When you click the edit button, an overlay appears containing text boxes and submit/cancel buttons.
>>
>>56502796
I just hoogle the type signature of any function that I think should already have been written
>>
>>56502796
Hoogle is a good help. You enter a type signature and it finds functions that fit a similar signature.
>>
>using auto-complete
>>
>>56502849
>>56502861
That sounds pretty smart, thanks
>>
>>56502869
>using a text editor
>not using punch cards with a hole punch to program
>>
File: 1420085336513.jpg (29KB, 240x320px) Image search: [Google]
1420085336513.jpg
29KB, 240x320px
>>56502849
>the occasional time when a function doesn't already exist

Maybe I'm blind, but I can't find a function that removes all instances of an element from a list. They all seem to only remove the first occurrence.
>>
>>56502861
I thought you were trolling based on an apparent typo.

Didn't realize "hoogle" was a thing.
>>
>>56502895
use filter
>>
>>56502895
removeAll :: Eq a => a -> [a] -> [a]
removeAll a = filter (/= a)
>>
import Control.Concurrent
import System.Directory (doesFileExist, getAppUserDataDirectory,
removeFile)
import System.IO (withFile, Handle, IOMode(WriteMode), hPutStr)

oneInstance :: IO ()
oneInstance = do
-- check if file "$HOME/.myapp.lock" exists
user <- getAppUserDataDirectory "myapp.lock"
locked <- doesFileExist user
if locked
then print "There is already one instance of this program running."
else do
t <- myThreadId
-- this is the entry point to the main program:
-- withFile creates a file, then calls a function,
-- then closes the file
withFile user WriteMode (do_program t)
-- remove the lock when we're done
removeFile user

do_program :: ThreadId -> Handle -> IO ()
do_program t h = do
let s = "Locked by thread: " ++ show t
-- print what thread has acquired the lock
putStrLn s
-- write the same message to the file, to show that the
-- thread "owns" the file
hPutStr h s
-- wait for one second
threadDelay 1000000

main :: IO ()
main = do
-- launch the first thread, which will create the lock file
forkIO oneInstance
-- wait for half a second
threadDelay 500000
-- launch the second thread, which will find the lock file and
-- thus will exit immediately
forkIO oneInstance
return ()
>>
>>56502171
>What are you working on, /g/?

I'm trying to learn a bit more about bash, so I've been making random scrapers with it. I wanted to do something simple so I decided to make a script that goes through a board on here and downloads all the images in every thread.

So far all I've done is wrote a function to download every image from a thread, but I still need a way to get all current thread links (or numbers), but I'm not too sure how to get them. Can anyone point me to the right track here?
>>
>>56502922
>>56502914
It's not hard to implement, but I dislike having to make a Data.List.Extended module and then import that everywhere
>>
>>56502953
just use filter (/=x) inline
>>
>>56502796
as we established in the last thread, having more features = simpler, so don't worry about it
>>
>>56502953
Or just write
filter (/= x)
, it's not hard. If you want it as a combinator, you can write
filter . (/=)
>>
I changed two raw pointers to std::unique_ptrs and my applications load time increased by 3 seconds. I-Is that supposed to happen?
>>
>>56503296
Did you post this in the right thread?
>>
>>56502270
sounds like a good time to me
>>
>>56502324
>new Random().Next(images.Length)

I don't like this at all.
>>
File: 1462831258139.png (665KB, 744x1052px) Image search: [Google]
1462831258139.png
665KB, 744x1052px
How do you feel about chaining several C preprocessor macros together to avoid using magic numbers?
>>
What programming language should a geologist/geophysicist learn?

I've had two courses in matlab...
>>
>>56503742
coq and agda
>>
>>56503742
game maker
>>
>>56503742
Python probably. Best libs for you.
>>
>>56503737
Sounds silly, but I guess that's the """right""" way to do it
>>
I wish people would stop recommending Python to people
>>
>>56503762
What is coq I'm just getting pictures of chickens.
>>
>>56503737
how do you expect anyone to know what you're talking about if you don't provide an example
>>
>>56503992
i'm talking about using something like
&str[i + max(dbl(len(a)), dbl(len(b)))]
instead of
&str[i+8]
>>
>>56504064
>&str[
>>
plz help

I have some JS that needs to store a two strings, and an int for some number of entities. I was storing everything in one object with an array for each field. The example seen later stores it as an array of separate objects. Is one of these more correct than the other? What's the difference?

>What I did
var data = {
string1 : ["entry1a", "entry2a", ... "entryna"],
string2 : ["entry1b", "entry2b, ... "entrynb"],
int : [], // gets initialized to zero to match other arrays elsewhere
current : 0


>Example
var data = {
current = 0,
entity : [
{
string1: "entry1a",
string2: "entry2b",
int : 0
},
....
{
string1: "entryna",
string2: "entrynb",
int : 0
},
>>
>>56502366
>dependent types
>some kind of proof/functional/autist/I've-never-written-good-software language
Why? Why can't I have a normal imperative language which does dependent types?
>>
>>56504064
The former statement seems much more robust but is considerably less readable.
I'd be more likely to assign that value to a local variable and comment as appropriate.
>>
>>56504199
>I want dependent types
>but I don't want a proof/autist language

u wot m8
>>
>>56504199
>Dependent Haskell
>imperative
In any case, dependent types don't play nicely with informal mutation (so, without linear types, monads, etc.)
>>
>>56502882
>tfw mom started there
[spoiler]she's not what you'd consider a 'good programmer' but she is and has been writing software that's praised in her industry for never failing and being top of the line[/spoiler]
Conflicted if I want to be like her or if I want to be someone who never gets that kind of amazing reputation yet produces large masses of usable software.
>>
>>56504199
>full dependent types in an imperative language
that sounds awful
>>
>>56504064
double longestLength = max(dbl(len(a)), dbl(len(b)));
&str[i + longestLength]
>>
>>56504249
>inb4 it's the next OOP-tier plague
>>
>>56504199
Seems less useful.

>I proved that this function returns a sorted list
>but it also might do literally anything else, too
>>
>>56503737
Standard. It's another fault of the language. It'd be nice if you collected them rather than spreading them all over the place like tons of API I use.

Just write them as you would knowing there's a 'go to definition' function.
>>
>>56504259
Dependent types are considerably harder to delude yourself into understanding, so I doubt it.
>>
>>56504259
>multiple virtual inheritance _at runtime_
>>
>>56504299
Few people know and understand OOP. Doesn't stop them from thinking they do and writing their 'safe' code using their 'OOP'.
>>
>>56502823
Top, no question, but the submit and cancel buttons ought to be in the same place as your edit button.
>>
>>56502943

WGET is the right path, I actually did a scraper for a startup there this summer that worked really well.

There's other software out there but honestly WGET makes things very simple and efficient
>>
>>56504322
They believe that they understand it, though.
>>
>>56504237
>implying any programming language isn't imperative
>do
>>
>>56504336
You sure? What's the advantage of using wget here instead of doing a curl | grep line?
>>
File: meh heh.jpg (13KB, 339x302px) Image search: [Google]
meh heh.jpg
13KB, 339x302px
>>56502399
>hasklel
>strings are linked lists of chars
>>
>>56504299
>>56504322
>>56504343
We're both reiterating the same thing. My point is that I don't think it's possible for Mount Stupid to apply with dependent types. I mean, people could say stupid things about them, sure, but you have to really understand them to use them, unlike objects.

>>56504360
Well, I suppose when you declare what happens after something else, that's imperative programming. You know what we both meant, though.
>>
>>56503742
Common Lisp or Racket
>>
>>56504086
I want the address of the 9th character in a char array.
>>
>>56504316
m8 that's already around with CLOS
>>
>>56504372
lazy immutable potentially optimised linked lists
what else should they be?
>>
>>56504372
linked lists are elegant, if not fast
>>
>>56504393
str+9
>>
>>56504386
Well the same could be said about OOP if there were enforced capsulation and all that. It'd be a mystery to people if that was enforced.

Same with dependent types, if you're allowed to do iterative nonsense and simply claim things are proven all the time you'd have a very similar situation to what we have with OOP imo.
>>
>>56504421
that's not nearly as clear tho
>>
>>56504393
&str[x] == str + x
>>
>>56503742
MUMPS
>>
>>56504432
That's a good point. I suppose there are still lots of ways to lower the bar.
>>
>>56504398
Linked lists are significantly slower than arrays.
They have terrible locality of reference.
>>
>>56504398
arrays are elegant, linked lists are filthy pig disgusting
>>
>>56504398
(puke)
Wrong on both accounts.
>>56504438
I disagree. Also if you have a reason to use a 9, specify why rather than hiding your reasons behind large amounts of macros that don't really give the full picture for the specific instance.
>>
File: muh linked list.png (51KB, 971x644px) Image search: [Google]
muh linked list.png
51KB, 971x644px
>>56504398
lol no
>>
>>56504458
Linked lists can kind of work in Haskell since they lend themselves well to lazy evaluation.
>>
>>56504476
This is a proper answer.
>>
>>56504476
I suppose that's a good reason.
It's still pretty shitty though.
>>
>>56504476
Yes, since lazy evaluation already slows things down with runtime allocation, linked lists wouldn't make much of a difference.
>>
>>56504445
My statements often look like &str[i+j].
str+i+j looks stupid
>>
>>56504476
Never thought of it like that. If you use vectors, you need to actually hold the real list in its entirety, etc.
>>
>>56503742
Python.
>>
>UNIRONICALLY using haskell
KILL yourselvles
>>
>>56504255
But then you're storing the result an intermediate calculation that you only need once, and then retrieving that same result from memory after storing it. We must optimize every CPU cycle!!1one
>>
>>56504499
>Mine looks like x, and I'm not stupid, so x isn't stupid
>>
>>56504438
yes it is
>>
>>56504499
>I can't wrap my mind around the concept of pointers or iterators, so they must be stupid
>>
>>56504499
>i+j
What does this usually signify? A number of elements after another element? That seems fine.
If it's just a pitch and a stride that's usually:
ptr+j*stride+i
Just don't bake the stride into the index.
>>
>>56504507
Even the simplest optimiser would remove that unnecessary variable.
>>
fn main() {
println!("{}", std::cmp::max(1.0, 2.0));
}

BRAVO RUST
>>
File: sepples.png (72KB, 1016x98px) Image search: [Google]
sepples.png
72KB, 1016x98px
>>56504525
>iterators
kill yourself sepples trash
>>
>>56504507
At least we're not in the stone age of last year when this would be a valid opinion and /g/ unironically advocated ++i instead of i++ for all the wrong reasons.
I'm almost happy those C++ programmer left.
>>
>>56504470
>>56504458
did you misread my post?
>>
>>56504557
I wonder if the code I use is compiling in over 30 seconds because of BS like this or if it's just normal C++ compile times.
>>
>>56504560
++i should be used for style reasons whenever i++ doesn't have a different result, i++ fags can fuck off
>>
>>56504554
I really wish they hadn't taken syntax design from C++.
It's a much uglier language that it needed to be.
>>
>>56504504
You forgot to call it Hasklel
>>
if your language has iteration constructs, it's shit. if you're about to belligerently reply to this about "how else would you do iteration?!?!" then you deserve to use that language
>>
>tfw no HaskFM
>>
>>56504576
>X is A, if not B
Usually (from my perspective as a non native speaker) this way of phrasing yourself means you're stating strongly that X has the property of being A and B, but B has been thrown into doubt by the person you're speaking and is secondary to the discussion.
>>
>>56504599
don't you have some monads to go suck?
>>
>>56504592
Blame C++ monkeys for deriding anything that doesn't look exactly like C.
>>
>>56504624
Modern C++ doesn't look anything like C.
I personally think C looks file for the most part.
I'm specifically referring to the colon cancer.
>>
>>56504599
Sure, try implementing a graph algorithm like Dijkstra's algorithm, Floyd-Warshall, A*, etc. using recursion instead of iteration.

>>56504624
Are you serious? They deride anything more closely resembling C than this >>56504557 as "C with classes".
>>
>>56504599
You can encode each in terms of the other.
>>
>>56504599
So good programmers just write their iteration over and over directly where they use it?
>>
>>56504592
I should have been more clear, the example there doesn't compile. Even c++ std::max works with floats
>>
>>56504554
>println!
What does the ! do?
>>
>>56504644
>>56504652
You're right. I should've just said C++
>>
>>56504716
it's a reminder to shove your dragon dildo up your ass
>>
>>56504716
It denotes a macro as opposed to a normal function.
>>
How come I get segmentation faults? The printf after the first add is what causes it.
#include<stdio.h>
#include<stdlib.h>

struct listnode
{
int data;
struct listnode *next;
};

void add(struct listnode *head, int num );

void printList(struct listnode *head);

int main(){
struct listnode *head;
add(head,4);
printf("2 %d",head->data);
add(head,7);
add(head,3);
add(head,1);
add(head,2);
add(head,6);
add(head,0);
add(head,5);
printList(head);
int Nth=4;

}

void add(struct listnode *head, int num )
{
struct listnode *temp;
temp=(struct listnode *)malloc(sizeof(struct listnode));
temp->data=num;
if (head== NULL)
{
head=temp;
printf("1 %d",head->data);
head->next=NULL;
}
else
{
temp->next=head;
head=temp;
printf(" %d",head->data);

}
}


void printList(struct listnode *head)
{
while(head!=NULL){
printf(" %d",head->data);
head=head->next;
}
printf("\n");
}
>>
>>56504716
Trigger warning for macros
>>
>>56504738
macros should just be in upper case
>>
>>56504683
For some odd reason, f32/64 don't implement the Ord trait, only ParialOrd.
I think it's about NaN not comparing well, or some shit.

>>56504716
! means a macro call.
So it calls the println macro.
>>
>>56504766
IEEE floats aren't totally ordered
>>
>eat meal
>drink coffee
>waste time on 4chan and youtube
>drink coffee
>waste time on 4chan and youtube
>ok now i can get started with programming... oh wait it's time to make another meal first
JUST
>>
>>56504762
Only problem with that is that you could name a normal function in all upper case and it would become indistinguishable. At least the ! leaves no question about it.
>>
>>56504762
What's the fucking difference?
>>
>>56504752
What does `head` point to? (Protip: nothing.)
>>
>>56504752
C is pass by value.
When you're changing the value of 'head' inside of 'add', it has no effect on the value of 'head' inside of main.
Also, you're passing in an uninitialized value of head into add.
You're either going to have to change it to
struct listnode *add(struct listnode *head, int num)
{
// ...
return temp;
}

head = add(NULL, 4);

or
void add(struct listnode **head, int num)
{
// ...
*head = temp;
}

add(&head, 4);
>>
>>56504801
>have to make hard design decision
>think about it for a bit
>I need to clear my head
>fap
>don't go back to the problem until later
>repeat
>>
>>56504752
The function add() does not set the value of the variable head in main(). The pointer is passed by value, so head stays NULL after add() is called.
>>
>>56504752
$ clang++ retard.cpp -o retard -Weverything
retard.cpp:26:7: warning: unused variable 'Nth' [-Wunused-variable]
int Nth=4;
^
retard.cpp:16:7: warning: variable 'head' is uninitialized when used here [-Wuninitialized]
add(head,4);
^~~~
retard.cpp:15:24: note: initialize the variable 'head' to silence this warning
struct listnode *head;
^
= NULL
retard.cpp:7:20: warning: padding struct 'listnode' with 4 bytes to align 'next' [-Wpadded]
struct listnode *next;
^
retard.cpp:33:8: warning: use of old-style cast [-Wold-style-cast]
temp=(struct listnode *)malloc(sizeof(struct listnode));
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4 warnings generated.
>>
>>56504752
Here's how you learn:
Step through the code and see where it fails. See if it's doing just what you're expecting.
If it works just the way you think it should and you get a segmentation fault still.
Question your assumptions about how things should be.
But here it looks like maybe you should initialize head to null.
>>
>>56504844
>clang++
>++
You're a fucking idiot.
>>
>>56504825
Thanks I had a total brain fart on that one.
>>
>>56504810
>you could name a normal function in all upper case
you would never do that with any decent style guidelines, you could even enforce it language-wide instead of having the !
>>
>>56504679
>if you're about to belligerently reply to this about "how else would you do iteration?!?!" then you deserve to use that language
>>
>>56504873
Having the ! denote macros seems less strange than forcing capitalization.
>>
>>56504924
a ! at the end of the name is unreadable as shit, it could easily go unnoticed when skimming through the code
>>
>>56504955
Which is a problem why? Macros should be distinguishable from functions for various reasons, but it doesn't matter from a readability standpoint. In fact, the ALL_CAPS style hurts readability as it draws attention where it isn't needed.
>>
Supposedly, with Church encoding of data
Nat : Type
Nat = (X : Type) => X => (X => X) => X

zero : Nat
zero X z s = z

succ : Nat => Nat
succ m X z s = s (m X z s)

it's possible to derive induction
ind : (X : Nat => Type) => X zero => ((m : Nat) => X m => X (succ m)) => (m : Nat) => X m

using the free theorem of the data type.

Trying to figure out how the fuck this parametricity voodoo works.
>>
File: 523671234.png (170KB, 768x432px) Image search: [Google]
523671234.png
170KB, 768x432px
>>56505044
> => for function types
>>
>>56505069
It's so that I can use -> for lambdas, which mirrors <- for my "generalized do notation". Originally, I had => for lambdas, but realized if I tried to use <= for do notation it would conflict with "less than or equal to".
>>
>use reader monad in home project
>tfw have to use shitty dependency injection frameworks at work

Why do pragmatic languages make writing code so hard?
>>
>>56505124
>monad
>not algebraic effect
Step up.
>>
>>56504978
macros can be utter magic, they should stick out like a sore thumb so that you know that there could be magic going on. macros shouldn't be treated as casually as a normal function with just an exclamation mark appended to it
>>
>>56505160
tell me more
>>
>>56505181
Rust has hygienic macros.
>>
>>56505193
They can still be magic in the sense that they can affect control flow in unexpected ways. Try!, for example.
>>
>>56505193
what's the point of them then vs using normal functions
>>
>>56505207
Actually, I agree with that. try! is a hack. I still don't think that macros should use ALL_CAPS instead of a measly ! at the end.

>>56505209
Doesn't mean they can't do special things, but the special things aren't so special that they need to really stand out and be terrifying.
>>
>>56505190
https://hackage.haskell.org/package/extensible-effects
>>
>>56505181
>>56505193
>distinguishing macros from normal functions
>hygienic macros
>not using macros to the fullest extent to operate on code as data
step up nigras

(defmacro aif (test-form then-form &optional else-form)
`(let ((it ,test-form))
(if it ,then-form ,else-form)))

(aif (+ 2 7)
(format nil "~A does not equal NIL." it)
(format nil "~A does equal NIL." it))
;; ⇒ "9 does not equal NIL."
>>
When I get to a programming project in my programming book that I can't figure out, should I just look it up to learn how to do it, or try and keep thinking about it until I figure it out somehow?
>>
>>56505507
Keep thinking about it.
You're basically just asking us if you should give up right now.
>>
>>56505507
you don't learn anything by doing nothing. take action, but use any resources you find to learn and improve, rather than copying code verbatim.
reading code is an excellent way to learn
>>
I have a block of C that looks like this. My main question is the use of return correct? Does return exit the funct function? Or just that block of if/else if/else. This is all probably very bad form but I'm too deep in that I can't change it in time. Nesting this heavily without functions is not good I think. From what I've seen this is working, I just want to know of the right way to exit/end a if/else block without completely ending the current function, because there will be code after level 3.

main () {

while(condition){
funct();
}
}

funct2() {
//more stuff
}

funct () {

if () {
//STUFF
}
else if () {
//STUFF
}
else if () {
//STUFF
}
else if () {
//STUFF

if () {
//STUFF
}

else if () {
//STUFF
}

if (level == 3) {

int now = (min * 60) + sec;

//does nothing if
if(now <= time+4) {
return;
}

else if (star->is_visible == false && now >= time+5) {
star->is_visible = true;
}

else if (star->is_visible == true && timer_expired( gT )){
accelGrav();
}
}
}
}
>>
>>56505601
return always returns from the function
also exit() (stdlib.h) always exits the program
>>
    
,>,< [ > [ >+ >+ << -] >> [- << + >>] <<< -] >>
>>
>>56505661
why
>>
>>56505601
why do you need an if statement that does nothing? just let the function exit on its own
>>
>>56505678
The esoteric gets me wet.
>>
>>56505682
>>56505654

Thanks, so just make it:

if(now <= time+4) {
;
}
>>
>>56505687
use Piet then
>>
>>56505718
There is no reason to write code this shitty.
>>
>>56505719
Piet is a slow shitty language. Brainfuck has been pretty fast.

i need something functional and esoteric.
>>
>>56505739

I'm bad, I know. We're not taught conventions in this manner. It's basic examples where they outline in the comments what to do (to get their pre-made functions/tests to work), then you're let loose on assignments.

And yes, we've had examples of an if where we wanted a 'do nothing' result.
>>
File: vomit.jpg (90KB, 650x650px) Image search: [Google]
vomit.jpg
90KB, 650x650px
>>56505601
>implicit int
Please don't do this.
>>
File: 1446422086306.jpg (221KB, 600x830px) Image search: [Google]
1446422086306.jpg
221KB, 600x830px
I feel like this is a retarded question.

If you have a function that iterates through a nested loop and is O(n^2), but the function also has a loop outside of the nested ones, does that outside loop effect the time complexity of the entire function? Or do you just look at the most complex aspect of the function?
>>
>>56505914

It's like we've gotten in a time machine!
>>
>>56505934
A function with a runtime of n^2 + n is O(n^2)
i.e. yes it's the worst one
>>
>>56505744
>i need something functional and esoteric.
haskell
>>
>>56505914

Yea, that's the thing. I don't know what implicit int means, something I now have to go look up.
>>
>>56505975
It's a "feature" of C89 and pre-standard C.
If something is specified without a type, it defaults to an int.
myfn()
{
return 0;
}

static i = 1;

etc.
>>
>>56505994

Ah, for the sake of making it fit in the post I didn't bother with copying everything. Those variables are all initialized else where. Didn't know it would default in that manner as forgetting even the (int i) in a loop spits out an error. Clearly new to C, there's aspects we're not taught, conventions you only learn from community and experience.
>>
>>56506059
>Those variables are all initialized else where
It's about the type you declare them as, not whether you initialise them or not.
>there's aspects we're not taught, conventions you only learn from community and experience
The feature was removed from later C standards, probably for the sake of consistency and the fact that it's an ancient and dumb way of doing things.
Unfortunately, most C literature still talks about C89 only, so that feature might be glossed over or never discussed. It's one of the things that bothers me slightly about otherwise excellent books like K&R, but it was correct when they wrote it, so you can't fault them for it.
I wish universities and other C literature would move onto the later C standards.
>>
>>56505994
>"feature"
It lets you completely bypass the type system, what's not to like?
You can even do something stupid like main(d,i,c,k) and use all those variables as uninitialized ints.
>>
File: ag.jpg (17KB, 649x463px) Image search: [Google]
ag.jpg
17KB, 649x463px
Anybody else /cs50/ here?

Had next to no programming experience before I started and now I feel almost mediocre (the course makes me feel pretty god damn stupid most of the time)
>>
>>56506153
Nobody wants to move on past C89 because ISO fucking sucks.
They made too many mistakes with C99, and in an extremely uncharacteristic move, they actually repeal features from C99 and then add features that go against the spirit of C, like bounds checking.
No compiler dev has implemented Annex K of C11, as far as I know.
>>
>>56506188
Information Systems, but I study CS topics on my own
>>
>>56506213
No m8, cs50; as in Harvard's introduction to Computer Science class.
https://www.edx.org/course/introduction-computer-science-harvardx-cs50x
>>
>>56506234
>CS
>harvard
so it's basically a meme class?
>>
>>56506194
>Nobody wants to move on past C89 because ISO fucking sucks.
You know that both clang and gcc default to C11, right?
>they actually repeal features from C99
They just made VLAs and Complex numbers optional, because embedded vendors complained that they're difficult to implement and they don't need them.
>like bounds checking.
>No compiler dev has implemented Annex K of C11, as far as I know.
Yes, Annex K is fucking stupid. It's an optional feature though. It's probably going to be removed or changed significantly in C2X.

Excluding a few minor fuckups, overall there is a lot of extremely useful things added to C99 and C11.
>
my_fn();
int a = 10;

>is invalid C89.
>>
>>56504396
Vectors, fucking idiot.
>>
>>56506279
But it's fine, GNU C always supported mixed declarations and code and that got added to the standard.
>>
>>56506318
We're not talking about GNU C, you fucking idiot.
We're talking about standard C.
>>
>>56506327
Find me a compiler that rejects mixed declarations and code when compiling in -std=c90
>>
don't get how people could stick to C or another language their whole life.
>>
>>56506349
C is comfy, that's why.
>>
>>56506349
>being mediocre at 15 languages
>>
Hi so I'm just learning C and I have a random question.

I read that you can assign a char pointer to a string literal, i.e.
char * s;
s="hello"

however, the value of *s isn't "hello", when I test it,

(*s == 'h')

returns true.

So whats the point in making a char * able to be assigned a string literal?
>>
I have no idea what to do for a first pyhton project.

I don't have files to sort.

I don't have a desire to scrape data.

Creating a sjw shitposting bot for tumblr has lost its appeal due to some being banned for just being a bot.


Any ideas?
>>
>>56506349
I think I could program solely in Racket for the rest of my life. It's not that difficult to fathom if you enjoy what you do.
>>
>>56506260
What are implying? It's an introduction to computer science course, not a think tank of people with doctorates in CS trying to solve Computer Science's most perplexing problems; and it's taught by highly articulate and articulate professors at an esteemed university using C as the language of choice.

If that makes it a meme class then yes, it's a fucking meme class.
>>
>>56506361
>Ah yes, if i don't want to stick to one it means i want to learn 50
>>
>>56506388
highly articulate and charismatic professors*
>>
>>56506374
char arrays and char pointers to strings are the same thing. *s == 'h' because s[0] == 'h'
>>
>>56506339
Talking about non-standard shit completely defeats the entire purpose of the argument.
I could create a compiler with every feature imaginable (as long as it doesn't invalidate standard code), and then claim that C has every imaginable feature.

Also, I've had to use the Amsterdam Compiler Kit before, and I believe it didn't support mixed declarations.
>>
>>56506401
So then how do I access the rest of the string literal? How can I use the *s to access the 'e'?
>>
>>56506424
*(s + 1)
or s[1].
>>
>>56505601
If the IF statement conditions are true, the two other else ifs won't trigger. Given that there's no more code, there's no need for the 'return'. It'll exit anyway.
>>
>tfw cat jumps on keyboard, messes your code and saves it too.

jesus fuck
>>
File: hereyougo.gif (88KB, 10000x10000px) Image search: [Google]
hereyougo.gif
88KB, 10000x10000px
>>56506380
Well, seeing as python is only good for files, data scraping and web bots, sounds like you need to use a new language.
>>
>>56506514

ctrl+z
>>
>>56506557

Why won't it freeze or break me?
>>
>>56506380

>due to some being banned for just being a bot.
Make a bot that makes new accounts once it's banned, uses Tor to switch IP addresses, etc...
>>
>>56506623
Or do what any sane person would do and spend a few days getting a botnet rolling.
>>
>>56506606
didn't work for some reason lmao.
>>
>>56506557
I saved this image because I wanted to use it for later but it ended up crashing my browser when I accidentally selected it in the upload dialog.
Fuck you.
>>
What functions can I add to this to show people the fun things you can do with python. The functions already demonstrate the web interaction capabilities and the file manipulating and shit like that. What other things is python good for?
http://pastebin.com/LqBwd0ag
>>
>>56506646
Botnets aren't exactly the most simple things to program, Anon, although they would make a shitposting bot much more effective. They most certainly take a bit more than a couple of days to build though.

>>56506648
Clearly you still have work to do in designing your bot.
>>
>>56506702
>fun
>python

wew
>>
>>56506780
I looked into Python briefly, but the whole 2 vs 3 thing really bugged me for some reason. I need something with a gold standard -- or at least something near it
>>
>>56506729
import botnet
>>
>>56506890
python is all-around trash
>>
>>56506890
Just use C, it'll be around forever.
>>
File: 1413785384311.jpg (19KB, 320x240px) Image search: [Google]
1413785384311.jpg
19KB, 320x240px
>mfw all these babbies getting butthurt that they have to learn Lisp this semester
>>
Not sure if it already exists, but its a program that scans your downloads folder repeatedly and sorts new downloads into folders based on file type. Also sends all images to your pictures folder. Anyone want it? Any suggestions for it?
>>
>>56507004
Pretty nifty Chris, what's it in?
>>
>>56507004
Funny, I use a similar script at work to stage inbound files from ftp servers
>>
>>56506890
C is the first language you should learn and the last one you'll ever need to learn. It will last your entire life, guaranteed. Only other useful thing out there is assembly.
>>
>>56507024
Java
>>
>>56506975
CL or Scheme? Also, which university still teaches Lisp?
>>
What is your take on each language and what they do, /dpt/?
>>
>>56507041
>>56506944
Different newbie asking, just getting started with C and trying to get some good resources for learning. I had Zed Shaw's book recommended to me by a couple of people, but then I've also heard to avoid him at all costs.
Got a .pdf of his book anyway, not touched it yet, along with K&R2, C: A Reference Manual, C Traps and Pitfalls, C99 ISO draft, /dpt/ and stackoverflow bookmarked. Had a quick look at cs50 seeing it recommended earlier in the thread, looks promising for a beginner.
Any other recommendations to get or avoid?
>>
>>56507194
Good languages:
>C++
>Scheme
>Haskell + GHC extensions
>Idris

Terrible languages:
>D
>Go
>Java
>Python
>Ruby
>PHP
>C#
>OCaml
>JavaScript
>>
>>56507230
Yeah, nah
>>
File: 1458780478501.jpg (2MB, 2100x1400px)
1458780478501.jpg
2MB, 2100x1400px
>>56507194
>>
>>56507230
can someone explain what's bad about java? i've used it for years and never really had a problem with it.
>>
>>56507254
overengineering
>>
>>56507254
POO
>>
>>56507230
more like

Good languages:
>C++
>Java

Almost tolerable languages:
>C
>C#
>D

Terrible languages:
>Haskell
>Python
>Scheme
>Idris
>Go
>Rust
>Ruby
>PHP
>OCaml
>JavaScript
>>
>>56507254
It's both widely-used and practical, that's what's fucking wrong with it you fuck
>>
What C++ books are there if i want to know how to make programmes that can react to user or other application input (like keyloggers or memory modifiers)
>>
>>56507254
You cannot write reusable, generic code with it. It supports only extremely basic abstractions.
>>
>>56507254
it's just a shitty outdated meme

java is actually a god tier programming language

inb4 dank (You)s
>>
>>56507263
Yes Pajeet, I know you only know Java, and you can kinda get something working in C++ (just don't think too hard about anything C++ does differently or you might realize that you don't know C++), but that doesn't mean that they're good languages.

Now, C++ is a good language, but that's quite independent from you being able to hack something together in it that will sort of work as long as it never has to deal with any error conditions ever, or be performant.
>>
>>56507276
god tier is taking it too far, but it is fast and portable
>>
ERPing with a pretty feminine boy on tinder
Fuck work
>>
>>56507267
>widely-used
Appeal to popularity

>practical
I strongly disagree. Its limited type system makes it extremely impractical.
>>
>>56507302
Have you ever considered suicide?
>>
>>56507290
Wrong. C is fast and portable. You can find a C compiler for a lot more architectures than you can find a JVM for.
>>
Once again /dpt/ shows that its views on programming languages are about as useful as a soiled diaper.
>>
>>56507316
Sure, and I found out there's pleasures and joys in life that make it worth it :3
>>
>>56507304
What is a more practical alternative for Java for the business cases in which it is currently used?
>>
>>56507252
Swap Java and Assembly and that's accurate.
>>
>>56507345
If you have to use the JVM, then Scala or Frege or Clojure.

Otherwise, Haskell or Scheme. We've already established that you don't need performance better than what they can provide since you're satisfied with Java.
>>
>>56507304
>Appeal to popularity
you got me there; i'm certain that there can be absolutely no good reason for Java's popularity
>>
>>56507345
C#
>>
>>56507371
Because it was shilled hard by Sun and then Oracle, and businesses got suckered into using it, and colleges started teaching it because businesses wanted it?
>>
>>56507376
It's just Microsoft Java.
>>
File: mainstream.jpg (39KB, 400x291px)
mainstream.jpg
39KB, 400x291px
>>56507304
>Appeal to popularity
>>
>>56507254
It's not Java specifically. It's the "everything is an object and your main tool is inheritance" mentality, which dictated much of Java's design, notably its cumbersome standard library. The culture around Java has always been a huge pain in the ass, full of complicated rituals that accomplish precisely nothing.
>>
>>56507367
no LMFAO

>>56507376
only for windows GUI and CRUD
>>
>>56507367
I really do wonder what the world would look like if businesses ran on Scheme
>>
>>56507402
>only for windows GUI and CRUD
What does Java do that C# apparently can't
>>
>>56507417
java is a lot cleaner and better suited for large scale applications where many programmers work together on the same project
>>
>>56507423
are you for real?
>>
>>56507409
It would be wonderful.

>>56507391
Not a valid refutation of my dismissal of the argument.

>>56507402
Have you ever used Haskell or Scheme?
>>
>>56507417
Well, it does a better job of attracting third-worlders. This is definitely a perk as far as costs are concerned
>>
>>56507439
oh look, it's this meme again
>>
what do hasklel coders look like?
>>
>>56507447
java is more popular in general. third-worlders use C# too.
>>
>>56507423
'no'
>>
File: neckbeard.jpg (292KB, 1423x2136px)
neckbeard.jpg
292KB, 1423x2136px
>>56507457
>>
I'm not very experienced with GPU programming.
How can I optimize this fragment shader?
http://pastebin.com/js6EDaWW
>>
>>56507492
>dist = length(dir);
>pow(dist, 2)
lad...
>>
>>56507506
What's wrong?
>>
>>56507512
length takes the square root but you're not even using it, you're using the squared distance. just do dot(dir,dir)
>>
>>56507512
and pow(dist, 2) is far less efficient than dist * dist, don't count on the shader compiler to catch things like that
>>
C++ feels rant

do a code at home 100% functional everything works. time for a c++ test at college; shitty ide(DevC++) nothing works, code ignores my conditions and such; have to google every single line. this language is tiring me tbbh
>>
>>56506606
>ctlr-z
>not using vim and doing u
>>
>using hasklel
i hope you boys like doing math homework
>>
Is there anything so extremely abstracted it seems like magic? An example for me would be importing __future__ in memethon
>>
i discovered code snippets in visual studio
>>
>>56507492
also
>abs(length(dir.xy)) < 0.02
length is always positive so you don't need abs, and you can compare the squared distance instead which is also positive like dot(dist.xy, dist.xy) < 0.004
>>
>>56507536
always know the compiler you're expected to use for demonstration and develop for that or at least test compile
>>
>>56503742
Python.

NumPy is essentially Matlab in Python. It works a bit differently under the hood though.

If you want the exact same performance as Matlab, you have to keep in mind that Python's extensions are written in C, and it will deal with things differently.
>>
>>56507613
thats kinda dumb. i expected c++ to be easily portable like the languages i know of. like python and java
>>
>>56507786
>i expected c++ to be easily portable
you fell for the meme
>>
>>56507230
>>C++
It's bad, turd

>OCaml
What is bad with it?

>>56507263
Tard
>>
>>56507525
>>56507611
Didn't realize that dot(V, V) was the same as |V|^2, thanks for that.
Although I applied all your optimizations, it hardly improved performance.

>dot(dist.xy, dist.xy)
Did you mean dot(dir.xy, dir.xy) ? dist is a float.
Also, how did you get 0.004 from 0.02? it's slightly bigger than before too.

>>56507531
Yeah I just relied on the compiler to optimize that, pow(dist, 2) looked more clear.
>>
>>56507786

If one compiler is bitching at you where another is not, you are using undefined behavior. To write truly portable code, just use gcc or clang with the -std=c++14 -Wall -Wpedantic -Werror flags.
>>
>>56506975
>your uni will never be as cool

>>56506279
Don't reply to that faggot, he kept making bullshit claims a few weeks ago and went into full damage control.
>>
>>56507457
Off the top of my head: Simon Peyton Jones, Phillip Wadler, Edward Kmett, Don Stewart, Erik Meijer
>>
>>56506279
>because embedded vendors complained that they're difficult to implement
They should have made VLAs optional ONLY for freestanding environments. Normal compilers could replace it with a malloc call.
>>
guys teach me delphi
>>
>>56507823
>-Werror
Retarded

Also, post your gcc arguments anons
$ cat ~/bin/c
#!/bin/sh
gcc -Wsizeof-array-argument -fdiagnostics-color=always -g -gdwarf-4 -Og -Wall --std=c11 \
-Wpedantic -fno-diagnostics-show-caret -fsanitize=undefined \
-fsanitize=address -fno-omit-frame-pointer -fcilkplus -pthread \
-lm -D_FORTIFY_SOURCE=1 -D_XOPEN_SOURCE=700 -I ~/include/ \
-L ~/lib/ "$@" -Wno-maybe-uninitialized
>>
>>56507811
>Didn't realize that dot(V, V) was the same as |V|^2, thanks for that.
I learned that in Calc 3
>>
>>56507870
Why would you want to learn a shitty dead pascal-like language with no free implementations?
>>
>>56507893
I taught myself linear algebra, I never went to any classes.
I still have a shitty understanding of it.
>>
>>56507899
i want to learn shitty languages with you guys
>>
>>56507823
thing is i have to code with the ide at my school and on windows only. so i guess ill just have go use that garbage ide at home as well. looks like ure telling me my code will be more portable if coded on linux.
>>
File: 1464061169625.jpg (18KB, 400x300px)
1464061169625.jpg
18KB, 400x300px
>>56507928
Then fuck delphi. Learn fortran with me. This shit is ridiculous.
>>
>>56507811
>Did you mean dot(dir.xy, dir.xy) ?
yeah

>Also, how did you get 0.004 from 0.02?
whoops, meant 0.0004, 0.02 squared

>Although I applied all your optimizations, it hardly improved performance.
1000 lights is crazy for a naive implementation, start with one light or a few, and then you could try deferred shading or something
>>
>>56507886

>retarded
If your code compiles with warnings, your code is wrong.

>>56507936
GCC and Clang work on Windows just as they do on Linux. Dev-C++ and Code::Blocks both use GCC under the hood. I'm telling you to do your testing on GCC and to use -Werror to force yourself to use code that doesn't invoke undefined behavior, or at least minimizes its use.
>>
i'm working on some shitty c# gui program and hopefully someone here is nice enough to help

i have a bunch of radio selections and a submit button, instead of doing the OnClick for the submit button having like 13 if elses checking if each radio is selected and looking stupid as fuck, what's a good way to go through and get the correct selection possibly outside of the windows class itself
>>
>>56508002
>If your code compiles with warnings, your code is wrong.
this
>>
>>56507985
>1000 lights is crazy for a naive implementation
That's just the upper bound because UBO's can't do variable length arrays.
the n_lights uniform controls how many lights are actually iterated over, which is usually around 5 to 15 lights.
>>
>>56507955
You jest, but Fortran is still in heavy use to this day esp in sci labs because of all the math libraries that are around for it that are free, and it can be fast as fuck with lot's of optimization tweaks.
>>
>built a python program that deletes system32 folder
>tested it in a non VM workspace

I done diddly fucked up.
>>
>>56508143
Good joke my dude
>>
>>56508089
maybe the bottleneck is somewhere else. what kind of frame rate are you getting and what hardware and resolution is this running on?
>>
>>56507400
It was designed to replace C++ as their attempt to make C "enterprise ready" (read: low wages for programmers) failed when pajeets could still fuck up C++.

SUN also wanted a VM language that could be run on every platform, in that sense it was a success but Oracle shilled it as "enterprise ready" (again, low wages) which it really took off.

There's still tons, and tons of major projects out there in Java like Elastic Search.
>>
What is the question mark and colon meant to do in this code (Java)

int step = (prev == null) ? 0 : trace(prev) + 1;
>>
>>56508218
FPS falls below 60 at around 20 lights.
Hardware is Intel sandybridge mobile integrated graphics (on x220) with xf86-video-intel and mesa driver, resolution is 800x800.
I think the bottleneck is the iteration, since apparently iteration is pretty expensive in shaders. Although it is a pretty shitty GPU.
>>
>>56508324
http://java.about.com/od/t/g/ternaryoperator.htm
>>
File: Lanka 8.png (26KB, 152x211px)
Lanka 8.png
26KB, 152x211px
--NEW THREAD--

>>56508350
>>56508350
>>56508350

>>56508324
Ternary operator, google it
>>
>>56508360
>>56508366
thonks <3
>>
>>56508329
maybe you shouldn't expect much more performance than that from your gpu. you could try rendering each light in a bounding shape so you don't apply each light to each pixel
>>
>>56504864
>>56506301
posts like these are ad hominems and they're logical fallacies. You should try your best to avoid them.
>>
>>56508659
He's right about vectors though.
>>
>>56502366
Stop this meme, Idris is buggy af.
Thread posts: 317
Thread images: 24


[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]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
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 RandomArchive shows their content, archived.
If you need information for a Poster - contact them.