[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: 338
Thread images: 34

File: DPT.png (389KB, 934x1000px) Image search: [Google]
DPT.png
389KB, 934x1000px
Old Thread: >>56251748

What are you working on /g/?
>>
promise you wont laugh?
im making my own feed reader except it will only be the backend end and a few pages for auth n stuff. everything else will be done through API. I plan on supporting the fever and ttrss apis
>>
A small patch for an open source game in C++ while learning emacs.
>>
for i in range(4):
print(i)
else:
print("else")
# output:
# 0
# 1
# 2
# 3
# else


WHY.jpg
>>
>>56258397
Python is a good language
>>
>>56258397
yeah looks like python is at fault here
>>
>>56258397
Since it starts at zero, it's somewhat natural especially for powers of 2.
>>
>>56258361
Sounds cool, after looking at the alternatives I ended up replacing Google Reader with nothing. Now I just glance at HN once in a while.
>>
>>56258430
Was talking about the else thing
>>
>>56258397
ah yes the for ... else statement
>>
I'm currently writing a crawler that goes over newspaper sites (local ones without newsfeeds) every half an hour and stores new articles in separate files.
This works so far, but: Are there ressources about how to not fuck with the bandwidth/security/admins of the target sites, i.e. hide a little that I'm crawing? Current approach is to scramble the found urllists of the sites and get them a bit in a chaos, given enough sites it's pretty chaotic and takes time in between two consecutive accesses.

>>56258361
I don't laugh. Good luck.
>>
>>56258451
>using for else
>ever
>not using for else if
>>
>>56258460
>not using
until [..] when [..] given-that [..] ensure [..] unless [..] soþlice
>>
>>56258397
so that you don't have to do
broke_loop = False
for element in mylist:
if element:
broke_loop = True
break
if not broke_loop:
print "did not break"

you'd rather not have it? or pick a different keyword?
>>
>>56258452
fake your headers
create a random delay

oh also nobody gives a shit that you're crawling their site esp. at a rate of a half hour each
once you start downloading 15000 of their archived documents back-to-back then they have an issue
that was the only time I was banned for a scraper

oh also follow api rules or you'll get banned
>>
>>56258397
https://docs.python.org/2/tutorial/controlflow.html#break-and-continue-statements-and-else-clauses-on-loops
>>
File: Table and exercises.png (175KB, 1557x919px) Image search: [Google]
Table and exercises.png
175KB, 1557x919px
Hey guys,

I'm delving into some light SQL at the moment, and I'm wondering if I've understood this correctly? If not, could you provide me with a more precise understanding?

#Sample

SELECT *
FROM library.books; #Selects every column from table library.books and puts it inside a new table

#Exercises from .pdf

SELECT * #Selects every column
FROM library.books #from table library.books
WHERE PublishYear #where row value of column PublishYear
BETWEEN 2001 AND 2004; #is between 2001 exclusive and 2004 inclusive

SELECT AVG(PublishYear)
FROM library.books; #Sends column PublishYear to function AVG() which finds the average value of the column,
#and then selects the returned value of the function AVG()

SELECT * #Selects every column
FROM library.books #from library.books
WHERE PublishYear > ( #where PublishYear is greater than
SELECT AVG(PublishYear) #returned average from AVG(PublishYear) like last exercise
FROM library.books);

SELECT title, #Selects title
COUNT(title) AS DupeCount #and the count of each set of duplicate entries of the title column.
#Stores result of COUNT() in DupeCount column (generated by command)
FROM library.books
GROUP BY title #Groups rows by title
HAVING COUNT(title) > 1; #and only shows titles with COUNT greater than 1 (duplicates)

SELECT * #Selects every column
FROM library.books #from library.books
WHERE PublishYear = 2000; #where PublishYear is 2000

SELECT * #Selects every column
FROM library.books #from library.books
WHERE PublisherID = 12; #where PublisherID is 12


Thanks for any replies!
>>
>>56258397
for i in range(4):
if i == 3:
print(i)
break
print(i)
else:
print("else")
>>
>>56258452
Well, the only hint they'd have would be that the get and post were within seconds of each other so unless you want to sleep() between pages you could just use a few threads and have them wait on each other. But, really, some guy clicking between articles at a rate lower than probably ( minutes > 10 ) between get requests might raise a brow. Why not just have the botnet run it?
>>
>>56258525
>fake your headers
didn't come up with that, will look into it.
>create a random delay
already implemented that in the first version that only had one target site, might use it again a little more

>follow api rules
care to elaborate?

What I crawl is not that much per site.
>>
Hey dpt, I forgot how much I missed you guys.
>>
>>56258573
>could just use a few threads and have them wait on each other.
Not a bad idea.

>Why not just have the botnet run it?
Involving non-local machines doesn't really have an appeal to me - yet.
>>
C strings or std strings?
>>
>>56258452
Rotating headers such as user agent, using proxies, and randomizing delays between requests are all decent ways. If you are really determined you could use a lib like selenium to fake user actions during each request, although that would be a horribly inefficient approach. Like another anon said, sending 2 or 3 requests to a site every 30 min wont trigger any flags most likely.
>>
>>56258565
>puts it inside a new table
No, it just returns the results of the query. It's not in a "new table".

>between 2001 exclusive and 2004 inclusive
BETWEEN is inclusive. 2001 in this case is actually evaluating January 1st, 2001

Everything else looks fine.
>>
>>56258339
Please do not use an anime image next time
>>
should i apply to internships even if i don't meet all the requirements? i'm a csci major but some of the postings wants specific things like
>Ability to create layouts using advanced and semantic HTML5 and CSS3
>Knowledge of DOM scripting with native JavaScript and JS frameworks such as jQuery
which i don't know anything about. it's like this for most internship postings
>>
>>56258776
http://www.strawpoll.me/11076725
>>
>>56258776
std::strings are null terminated
>>
>>56258818
then learn those things
>>
>>56258818
Fuck, you just triggered my PTSD of trying to get an internship in college.

It's astounding how many of them require actual work experience.

What the fuck is their definition of an internship?

Either way, apparently you can still apply and have a good chance of getting the internship. It's like how business always list "3-5 years working with this" when they actually don't really care.
>>
>>56258830
Yes, but they are also length prefixed.
>>
>>56258841
>What the fuck is their definition of an internship?
The answer you search for is "really cheap employee"
>>
>>56258872
stfu indians are bro tier
>>
>>56258776
Depends, how much do you enjoy hammering nails under your toenails?
>>
File: 1425593845210.jpg (51KB, 473x555px) Image search: [Google]
1425593845210.jpg
51KB, 473x555px
Threadly reminder that lisp > hasklel

>yfw hasklel can't even treat code as data
>>
>>56258929
PROLOG or bust.
>>
>>56258929
Stop avatarfagging.
>>
front end dev: http://jobs.jobvite.com/zappos/job/osyA3fwn
iOS: http://jobs.jobvite.com/zappos/job/ojxA3fwd
information security: http://jobs.jobvite.com/zappos/job/oqfx3fwZ
software engineer: http://jobs.jobvite.com/zappos/job/oS3G3fwo
android dev: http://jobs.jobvite.com/zappos/job/onyA3fwi

it says "please limit to 2 applications" at the bottom of every page but not at the main internship page, so idk if that means you can apply twice to every internship or to only 2 internships. which 2 of these internships do you think's the best to apply for? fwiw i'm most experienced with java
>>
>>56258871
Bad news for you buddy
https://ideone.com/Tw405N
>>
>>56258981
It's two applications per job posting.
>>
>went to interview today
>spaghetti.jpeg
>run home
>house locked
JUST
>>
>>56258522
A different keyword would be wonderful. At first look, the else feels like it should execute if there was nothing in the list to loop over:

for element in mylist:
print(element)
else:
print("no elements to show")

instead of doing
if len(mylist) == 0: # doesn't even work with iterators
print("no elements to show")
else:
for element in mylist:
print(element)
>>
>>56259006
Gee, you sure are stupid. You still can't embed NULs, but length() is O(1) because they are length prefixed.
>>
>>56259071
Yeah my bad https://ideone.com/eGocn2
It didn't work the first time because constructor expects a c-string
>>
>>56259099
>constructor expects a c-string
I thought all string literals since C++11 where std::string? Or it is just trying to preserve back-compat semantics?
>>
>>56259064
>doesn't even work with iterators
looped = false
for element in mylist:
looped = true
print(element)

if not looped:
print("no elements to show")
>>
>>56259136
Backwards compatibility
>>
>>56258929
>>>/general/rules/13

>>56259145
Why not use something like isEmpty(mylist)
>>
File: 1464456858654.gif (880KB, 500x281px) Image search: [Google]
1464456858654.gif
880KB, 500x281px
I just got over 4000 failed SQL injection attempts on my CGI script written in C!
It's a comment board!

http://45.32.80.36/board.cgi
Please try it out and don't spam it pls.
>>
>>56259136
Well I think string literals are still const char[], not sure about it though.
>>
>>56259237
DELET THIS GIF
>>
>>56259189
Because
>doesn't even work with iterators

Iterators/Generators don't create lists in memory they just give the object for each iteration, so you can only loop once. No way to check the length without looping over them

a = [1, 2, 3, 4]
b = (i for i in a if i % 2 == 0)
len(a) # 4
len(b) # object of type 'generator' has no len()
>>
How accurate is CodeEval's Timing?
Is there a better rating than 1ms?

Also general experiences with codeEval? Is it worth my time or are there better alternatives for practicing/not getting rusty.
>>
>>56259189
>>>/global/rules/13
Oh that's neat. How do I link to specific board rules? >>>/g/rules/2
>>
>>56259136
They are forever const char*
>>
>>56259145
I feel mentally damaged now for programming in python.
>>
>>56259260
>warning: ISO C++ forbids converting a string constant to 'char*' [-Wpedantic]
In C++11 and C++14.
>warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
In C++98.
>>
is there a cleaner way to copy an array into a bigger one, with the empty spaces at the end being 0, other than creating a new one and iterating? this is in java
>>
>>56258397

So don't use an else statement on a for loop stupid
>>
>>56259354
Either use arraylist (which does precisely what you said), or copy it yourself.
>>
>>56259354
Like
>>56259397
said, use ArrayList. Or if this is for an assignment or something use System.arraycopy(). It functions like memmove() from C.
>>
>>56259440
i'll look into arraycopy because it's for an assignment. we're working with very large numbers in binary so i assumed the iteration method would be really slow but then i realized i'm retarded and it doesn't work like that so the questions kind of moot but still it might look cleaner
>>
>>56259330
Not like other programming languages have better ways to do that. The only thing I know that implements an else clause like that is the twig template engine
<ul>
{% for user in users %}
<li>{{ user.username|e }}</li>
{% else %}
<li><em>no user found</em></li>
{% endfor %}
</ul>
>>
>>56258800
Thank you very much!
Would +rep
>>
Do yu hev GeitHab?
I loeve GeitHab.
>>
>>56259350
const char* not char* dummass. They are still not stdstrings. However
"abc"s 
is a stdstring in C++11 if that's what you are confusing it with.
>>
File: 1456537049835.jpg (71KB, 394x394px) Image search: [Google]
1456537049835.jpg
71KB, 394x394px
>>56258339
>want to multiply a variable
>end up dereferencing it
wtf I hate C now
>>
File: roganmeme_2.jpg (183KB, 950x400px) Image search: [Google]
roganmeme_2.jpg
183KB, 950x400px
Will there an IDE like Visual Studio for Linux distros?

Is there one? Eclipse is almost on its level.

Text editors are edge lords' maymay.
>>
>>56259058
>went to interview
>seems good
>didn't get picked
it doesn't matter in the end
>>
>>56259666
Sup Satan. Once Lintards figure out how to get WPF working on Linux you'll be able to use VS with WINE or whatever the fuck.
>>
>>56259666
try QtCreator
>>
>>56259724
I use it to create python programs' GUI, I know about it, but it "only" supports C++.

I will only learn that when it needs to be used, but none currently. My internship is at Nokia (Szeged) and I asked arou nd the offices and they do not use it cause they want to build new system from scratch based on a different company's technology(guess which).

I will probably work for them after college, they hire all students immediately after the diploma, this is true to every company in the country.
>>
68th for Scala!
>>
>>56259933
>73 replies

sasuga scala
>>
Is it true that Haskell programmers are TOO SMART to be employed?
>>
>>56260077
no but it is true that haskell is a useless toy language
>>
File: IMG_0369.jpg (926KB, 2592x1728px) Image search: [Google]
IMG_0369.jpg
926KB, 2592x1728px
makin progress. gotta wire everything up and shorten the led strip and put everything so you can't see it and then done.
>>
File: IMG_0362.jpg (1MB, 2592x1728px) Image search: [Google]
IMG_0362.jpg
1MB, 2592x1728px
>>56260124
there is tiny oled display (which is way smaller than I thought - maybe buying a bigger oen) which should display room and outside temperature in the end
>>
>>56260077
Every thread anon

Every thread
>>
>somewhat offtopic

>want to find "trustable" programmers
>don't give a shit about their titles or prev experience

My problem is all I find is pedantic retards who don't know what their titles say they should, or poo in the loo tier programmers.

Last time I hired someone, I had to end up doing the work myself, paying him, and fixing that messy code...

Where the fuck do I find people who want to engage in interesting projects for money? this is not a stable job offer or anything like this, I just want someone to have for occasional jobs

Anyone have any idea where to find them? I'm lost
>>
>>56260416
Well, you can trust me.
>>
>>56260443
gimme your bank account number, I will pay you now in advance
>>
>>56260416
hire me too

I work on fun new projects all the time
>>
>>56260473
>>56260443
both of you are welcome aboard, any desired wage?
>>
>>56260416
All I want is a nice comfy part-time job writing C.
Nobody in my part of the world wants to hire me without a bachelors in computer science and 5+ years experience in a laundry list of technologies.
>>
>>56260513
All I want is someone who gets the job done, and can adapt to different jobs.

I'm looking for android dev now
>>
>>56259699
Already in the works
https://grokys.github.io/avalonia/avalonia-alpha4/
>>
>using a special encoder for calculators
>go to extreme lengths to input special characters needed like the left arrow, including hex editing input files and using special windows encodings on my input file
>turns out the person who programmed it (completely undocumented and closed-source, mind) mapped the -> command to the left arrow unicode character and didn't accept anything else

fucking hours wasted and there's not even anyone to be mad at
>>
>>56259666
Jetbrain's stuff or QtCreator
>>
What are the pros and cons of the various IDEs out there (for Windows)? I see most of you swear to eclipse, is this because it has features NetBeans do not offer? Is it habit?

I like NetBeans and can't seem to get comfy in Eclipse although I have tried a couple of times. Any reason not to stay in NetBeans?
>>
>>56258339
>What are you working on /g/?
Blockchain, on the cloud. Synergised and vertically integrated for streamlined UX.
>>
>>56260702
If you are in windows just go use Visual Studio.
>>
>>56260702
Use Visual Studio for everything but Java.

If you're working with Java, go with IntelliJ.
>>
In Java, what does

private foo(){ }


Create? Wtf is it, a class, a method, or what?
>>
>>56260758
A syntax error.
>>
>>56260773
I'm in Java lecture right now and it was on my instructors lecture slide, but she didn't explain it
>>
>>56260758
I guess it's the (private) constructor for a class named foo.
>>
>>56259311

I've had good experience with it. Helped get me a job after being neet for several years
>>
>>56260815
Oh, that's probably it.

Goes to show you that context is everything

I'm not sure why you would have a private constructor like that, though.
>>
>>56260815
Too bad J*va requires all classes to be in PascalCase.
>>
>>56260947
>implyingCamelCaseIsntTheBest
>>
>>56260947
>requires
You can use whatever case style you want.
>>
>they don't use Space Case
>>
>>56260947
No it doesn't
>>
>>56261083
That's not valid in most languages.
>>
>>56260873
So that default constructor doesn't get generated, or so the class can not be constructed.
>>
>>56261096
>or so the class can not be constructed
Just make the class static.
>>
>>56261096
It can still be constructed from a public static function
>>
>>56261104
AFAIK only nested classes can be static
>>
>>56261104
Why can't you just have a free function?

>>56261087
Actually, it's valid in almost every language, including Latin, English, Arabic, German, Sanskrit
>>
Camel_snakeKebab-case
>>
>>56259666
Clion is like my fav right now but Qt is still better regarding performance, mainly because everything with jetbrains logo is made in fucking java
>>
>>56261127
>Why can't you just have a free function?
Because java is a retarded language.
>>
>>56261283
>>56261127
Functions need a return type.

It's a guarantee to the caller that they will receive information in a particular way.
>>
>>56261310
anon wasn't asking about void functions they were asking about non-member functions
>>
Be serious, is SICP even useful if I am a non CS related STEM student who wants to either make basic vidya or web related shit?

I am nearing the end of chapter 2. I am liking it but there are still 400 pages of the book left. Should I just ignore it for a while and do something practical? I already went through Think Java so I am not someone who has only used a meme language like scheme. SICP throughout chapter 1 and 2 has gone from feeling like a book of riddles to standard problems, made slightly more of a pain in the ass due to the functional style and usage of car / cdr / lists instead of lists and indexes

Various questions:

I think chapter 3 and 4 will be the main parts of SICP. Can you spoil them for me and summarise what the magic is that theyre revealing?

What is the point of this functional style where everything has to be returning something. You have to use "let" just to set variables.

Will practical programming be mostly googling?
>>
>>56261536
>is SICP even useful
Nope.

It's a meme, and a massive waste of time compared to many other resources.
>>
>>56260758
It's so that you can't create an object of that class, probably because it only contains static methods
>>
>>56261536
>web related shit
We call those people "webshits," they have their own containment general at >>>/g/wdg/
You don't even need a STEM degree to pick up web languages, but it comes at a cost and general excommunication from any part of /g/, professional or hobbyist.

Sure there are plenty of other books that generally do the same thing, but SICP is not just a meme here if you plan to take this even somewhat seriously.

>basic vidya
"basic" video games require the fusion of lots of intermediate programming and mathematical concepts. Also, kill yourself.
>>
File: Capture.png (37KB, 1064x600px) Image search: [Google]
Capture.png
37KB, 1064x600px
style configurator is aids to work with in notepad++
you can't even use regex
>>
>>56261664
Notepad++ is misleadingly named

or so I thought
but then I realised it was based on C++'s name
and now it makes sense

it's notepad but shit
>>
>>56261635
suck my dick
>>
>>56261664
Do it with a Sublime Text plugin, nerd.
>>
>>56261704
kek'd
>>
Can you be a good programmer without calculus?
>>
>>56261734
It makes you a better all-around programmer to NOT know calculus.
>>
>>56261745

here's your reply
>>
>>56261635
http://www.composingprograms.com/ is really good if you're into sicp, although it's python
>>
>>56261664
>notepad++
kys
>>
>>56261745

nice meme
>>
File: 1472152730299.png (178KB, 3952x3720px) Image search: [Google]
1472152730299.png
178KB, 3952x3720px
>>56262083
>>
>>56262302
shart in mart
>>
>>56262379
dumb frogposter
>>
File: Capture.png (73KB, 916x675px) Image search: [Google]
Capture.png
73KB, 916x675px
>http://jlord.us/essential-electron/#why-is-this-important-
The horror.
These are the kinds of people we share a planet with.
>>
>>56262553
Doesn't Windows mostly use C++ for userspace?
>>
>>56262553
Doesn't Windows mostly use OCaml for userspace?
>>
File: 325372578923759#.png (384KB, 1024x768px) Image search: [Google]
325372578923759#.png
384KB, 1024x768px
>>56262553
b-but senpai

Web languages a shit
>>
>>56259495
But there it makes sense
>>
>>56262553
>Native os languages
>Languages that operating systems 'use'
>web languages

literally what?

I don't think these people have written a single line of actual native code.
>>
If I know C is it going to be hard learning JavaScript to an INTERMEDIATE standard?
>>
>>56262573
Yes and that's what his pic literally says.
>>
>>56258339
I wanna start writing some personal articles about software and programming, what's the best way to create a blog? I don't wanna spend money on a server and a domain name, therefore github pages would be a nice option? Maybe later when I have the money I could migrate it to a proper blog system.
>>56262767
Dunno, never learned JS, if you want it you could try it. The syntax for the functions seems messy tho, too much lambdas and callbacks.
>>
>>56262767
A five year old could learn Javascript
>>
>>56262809
The pic is saying the OS itself is mainly in C++
>>
>>56262840
It's more the syntax I'm concerned about. I could, and have written your average web2.0 app, but I'm not sure what industry considers 'standard'
>>
>>56259629
nice bullshit
>>
>>56262866
It says what the systems are written in but it doesn't explicitly says the kernels so it's somewhat indirectly implying it means a system as a whole (including userspace) in which case, imo, C++ is the major part that makes up Windows. Just sayan though.
>>
>>56262904
Windows userspace is mostly C# these days as working with the C/C++ APIs is like trying to kill yourself with a banana.
>>
>>56262927
I really doubt that MS went an extra mile to convert all old userspace stuff so it's probably only true for new stuff but I'd say it's still mostly C++ (think of all the programs in CP, AD administration tools and shit, there's a fuckload of them).
>>
>>56262951
What i'm saying is that no sane person would use the C++ API today. And C# is as portable as ever with Xamarin.
Besides saying that if your program is written in C++ it will only work on windows is just plain wrong.

That article is written by absolute retards for absolute retards.
>>
>>56261566
>languages where "classes" are both classes and modules
>>
>>56263001
That I do agree with.
>>
Really sick of all the Rust shills in this thread today.
>>
Hey guys I'm digging into clojure and I got one of those programming marathons exercises, but I'm kinda stuck here, how can I transform this list:
'((A B) (A C) (C D) (B D) (D E) (D F))
Into something like
'(A (B (nil)) (C (D ((F (nil)) (E (nil))))))
Or whatever list best represent the tree:

A
/ \
B C
|
D
/ \
E F

As C was the first to claim D as its child, the (B D) didn't add the D as the child of B.
>>
>>56261019
I can smell the curry and shit from here.
>>
>>56258929
Free Monad + Interpreter is one way.
>>
>>56263203
You're the first person to mention Rust, though.
>>
>>56263273
I'm counting previous threads
>>
I think every Programmer has a Problem when you open ( a bracked somewhere in a sentence but do not close it.
>>
>>56263242
That's not a tree, that's a DAG. But for trees, what I would do is recurse on the root of the tree, find all the children of the root and recursively calculate the branches for each children. Maybe you could even represent general DAGs by having multiple links to the same object through memoization, storing each tree calculated by a recursive call and only calculating the tree unless it has not been before.
>>
>>56260141
>>>/diy/ohm might be more interested.
>>
>not representing DAGs using lambda calculus

The example in >>56263242 would be:
(λx. A (B x) (C x)) (D E F)
>>
>>56263283
No other thread today has mentioned Rust either
>>
File: 1436289836011.jpg (106KB, 680x680px) Image search: [Google]
1436289836011.jpg
106KB, 680x680px
>spend the whole day debugging a program
>doesn't make sense, I double-check to make sure examples are being given valid inputs bu they still generate invalid or non-existent output
>hash everything out on paper, it all works
>spend hours trying to figure it out
>later on realize I mistyped the order of two arguments
>>
>>56263538
I'm counting previous days.
>>
>>56263543
dumbass
>>
>>56258339
A game engine for Ludum Dare at the weekend!
>>
>>56263394
>>56263538
Thanks for the directions, gonna code again to see where I get
>>
>>56263445
How about this?
#1=(A #2=(B #1# #3=(C #1# #2# #4=(D #1# #2# #3#)) #4#) #3# #4#)
>>
>>56263594
Clearly that's worse.
>>
File: le horrified mickey.jpg (114KB, 615x1279px) Image search: [Google]
le horrified mickey.jpg
114KB, 615x1279px
>>56263594
>>
>>56263445
>(λx. A (B x) (C x)) (D E F)
Beta-reduces to
A (B (D E F)) (C (D E F))
I don't see this representing the given DAG in any way. (And I suppose A B C D E F are givens that don't have a binding in this scope.) Care to explain? I normally understand λcalculus but rn it seems not to add up...

>>56263594
Why does it have to be cyclic?
>>
>>56263562
Don't you ever say something rude like that again, Anonymous, otherwise I'll be forced to bully you and report you to my friend Hiroshimoot, who will make sure you never post in DPT threads again, punk.
>>
>>56263614
It's the complete graph with 4 vertices. Could it be represented in lambda calculus?
>>
>>56262553

This is why the future of a simple fart app will be 100s of MBs large because people are too retarded to write in something that would yield an executable a magnitude smaller.

And they expect magically somehow, Moore's law won't end and we'll be able to have 100 MB of L2 cache or something somehow.
>>
>>56263633
Who said anything about beta-reduction? Lambda calculi are a general thing, I don't just mean *the untyped lambda calculus*.

>>56263654
>DAG
>>
>>56263633
>(C D) (B D)
Pls disregard, I got it now.
>>
File: Stormweenie.jpg (67KB, 476x717px) Image search: [Google]
Stormweenie.jpg
67KB, 476x717px
>>56263622
Oh boy, it's the poltard with "le" filenames again.
>>
File: WYxOXjD - Imgur.jpg (661KB, 1706x2064px) Image search: [Google]
WYxOXjD - Imgur.jpg
661KB, 1706x2064px
>>56263622
>le
Hey poltard, go back to your containment board
>>/pol/
>>
File: QE6IQS0 - Imgur.png (247KB, 999x1200px) Image search: [Google]
QE6IQS0 - Imgur.png
247KB, 999x1200px
>>56263622
Kill yourself stormtard.
>>
>>56263668
And the very existence of the website you're shitposting on would be an affront to anyone involved in network programming 20 years ago. I don't use Electron, but who gives a shit?
>>
>>56263668
Well, ideally it wouldn't be a HUGE problem because the "apps" would dynamically link to the runtime and libraries.
>>
>>56263729

4chan actually had pretty solid networking compared to other sites in the early 00's. Yes, the code for the website is probably spaghetti but we never have to see it even if it would benefit the site greatly to have it open sourced and fixed up.

The problem with Electron isn't the fact that you or I aren't using it, it's the fact that it's available to have a subset of people who don't understand the domain space they are programming in to be able to program in it at huge cost to the user and other programmers in that area.

Yes, it's not good right now but there are quite some applications that already just it that have a large audience like Atom and Discord.

>>56263754

Dynamic linking has its own problems with versioning and changes and in practice, doesn't work that much better than if you just do static linking other than the size argument. Which if Electron catches on would still be horrid.
>>
>>56263445
>>56263672
The calculus has to be strongly normalizing.

If you can write a fix point combinator, you can encode cycles.
>>
>>56263831
What I was getting across was that using that networking to deliver pictures of transvestites and cats would have been seen as offensively wasteful. Just like we think using a web browser shell to render a GUI is.
>>
>>56263883
They're not remotely comparable.
>>
>>56263925
If you say so.
>>
File: 4thEnglish.jpg (50KB, 591x722px) Image search: [Google]
4thEnglish.jpg
50KB, 591x722px
How is this book?
I'm scrolling through a pdf, and noticed it doesn't have any exercises at the end of the chapters. I know problem sets don't make a good book, but I like having little exercises to make sure I understood what I'm reading.
>>
is a text editor a good project? it would be in C. you can open a text file. create one. save it.

when one is open you can type in commands like

[operation] [line #] [text]

so like "write 1 hello"

so line 1 becomes hello.

this worth doing?
>>
>>56264041
No, because you're clearly dumbing it down to fit your comfort level.
>>
>>56258929
>he's never heard of templatehaskell
lisp fags btfo
>>
>>56264048

so you think it needs to be more challenging? how would you add to it to do that?
>>
>>56264115
Make it a proper editor with a display and cursor.
>>
>>56259071
worst of both worlds (^:
>>
>>56264080
sucks compared to lisp metaprogramming though

>>56263256
still an interpreter rather than embedding a language via the lisp compiler
>>
>>56259071
The time complexity of length() doesn't matter. UTF-8 (the encoding you should ALWAYS use) is O(n) length and indexing. You can always cache the length if for some reason the performance of your application depends on getting the length of a particular string over and over.
The real benefit to std::string is that you can hold null bytes, and that the memory for the string can be resized and reused. Also you get all the benefits of RAII and std::move() that would be a nightmare if trying to pass char* everywhere.
>>
>>56261564
shitposter

>>56261536
it's good if you want to know how a lot of stuff works that you wouldn't otherwise

> I think chapter 3 and 4 will be the main parts of SICP. Can you spoil them for me and summarise what the magic is that theyre revealing?

interpreters, compilers, lazy evaluation, backtracking and nondeterminism, logic programming, etc.

basically if you want to become a wizard read sicp
>>
>>56259006
Bad news to you buddy, it seems that you do not know C++.

https://ideone.com/dw9YlJ
>>
>>56264041
Kind of like ed, the ancestor of vi and vim 30something years ago, except it had a better designed command set. Either go for >>56264126's suggestion, or implement an ed clone from scratch. It's a nice medium-level problem that can make you learn some things that can't be in exercises, and you've judged yourself that it was appropriate for your level. (that's a reword of >>56264048) a vi-like editor is probably a bit harder but more satisfying. Pick one.
>>
ok, so I have int i
and i have
[/code]
for (i=n-2; i<=1; i-=2) {
for(i=0; i<p; i++)
blah blah
}
[/code]

will the inside for loop mess with the outer i?
>>
>>56264362
in c yes
>>
>>56258432
>Not migrating your google reader data over to feedly
>>
>>56264362
Yes. Make the inner loop variable 'j' instead of 'i'. That's the convention.
There are particular ways in which you can have a nested loop with the same named variable as the outer loop but without affecting the outer loop, however you _shouln't_ do that as it makes the code really unclear about which 'i' you're referring to any point in time.
>>
Can someone explain me purpose of using getters and setters if they don't provide any logic? Why not just public fields? Accesors are just crap and boilerplate, the final effect is the same as making everything public.

Ofcourse I'm talking about fields with both setters and getters. I've seen classes with hundreds of lines of just fields and their accessors
>>
>>56264584
So that you can add logic in the future without breaking the API.

C# solved this problem pretty neatly, for instance.
>>
>>56264584
Extensibility, if you later need to add constaints, say a field (int) must be less than 100, if you'd just modify a public field you would have to go through your whole codebase and change every line that modifies that field.
Having a setter, you just have to add the constraint there and are done.
>>
>>56264584
It's how OOP languages hedge their bets regarding forward compatibility. The idea is, if you have to introduce logic in the getters/setters later on, you'll break client code by making the field private. So just go ahead and keep it private to begin with.

Of course, everything breaks regardless. The OOP people meant well...
>>
>>56264584
Methods can be virtual but fields cannot. Java does it in a really shitty way, though. More modern OO languages like D/Ceylon/C# don't need setters/getters because they have features that make a virtual function call identical to field access.

Example:

class Parent
{
string name;
}

class Child: Parent
{
string name() { return "child name"; }
}

void main()
{
auto p = new Parent("John");
writeln(p.name); //Prints "John"

p = new Child();
writeln(p.name); //Prints "child name"
}
>>
>encapsulation through getters and setters
>not using proofs to maintain invariants
>>
How do you guys keep your skills current and learn about the newest technologies?
>>
>>56264647
>>56264648
>>56264660
is that really worth hundreds of additional lines that do pretty much nothing instead of making fields public and validating values later?
>>
>>56264698
Proofs are just a poor man's enterprise bean XML interface schema factory factory.
>>
>>56264736
It is when you've farmed out development to Pajeet and his friends in India. They need all the help they can get to just produce something that runs.
>>
>>56264736
No, it's not worth it. It's just the price you pay for doing Java.
>>
Why do we allow software to be created with a proof to accompany it? Why aren't we pushing the creation of bug-free software through functional languages which enforce programs to be, themselves, proofs?
>>
finally finished my c cross program
any way to make it better & more consise?
#include <stdio.h>

void padding(int k) {
for(int j=0; j<k; j++) putchar(' ');
}

void cross(int i, int p, char arr[]) {
padding(p); putchar('*'); printf("%.*s", i, arr); puts("*");
}

int main() {
int n; scanf("%d", &n); n=n|1;
char padd[n-2]; int p=0, i, j;

for(i=0; i<n; i++) padd[i] = ' ';

puts("");
for (i=n-2; i>=1; i-=2,p++) cross(i, p, padd);

padding(p); puts("*"); --p;

for(i=1; i<=n-2; i+=2,p--) cross(i, p, padd);
return 0;
}
>>
>>56264736
i mean i've met people who stick to this like fanatics, and when they saw i used public fields for stupid stuff only my method used, that has almost zero chance to change in future they totally lost their shit
>>
>>56264836
Because it's unironically too hard for most people to comprehend.
>>
>>56264836
Software is whatever you make it. A lot of shit is the way it is just because its popular or no one bothered to do anything about it.
>>
>>56264849
Those people are OOP cultists. Force feed them some Haskell to deprogram them.
>>
>>56264836
Despite what functional shitters try to tell you, any program in any language is a proof.
>>
File: asdasd.png (2KB, 402x258px) Image search: [Google]
asdasd.png
2KB, 402x258px
>>56264841
now with a frame included
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, char** argv)
{
int size = atoi(argv[1]);
char buffer[size+1];
buffer[size] = '\0';
buffer[0] = buffer[size-1] = '#';
size_t i;
for (i = 0; i < size; ++i){
if (i == 0 || i == size-1)
memset(&buffer[1], '#', size-2);

else {
memset(&buffer[1], ' ', size-2);
buffer[i] = buffer[size-1-i] = '#';
}
puts(buffer);
}
return 0;
}
>>
>>56264841
>any way to make it better & more consise?

what's the point?

a program this simple is used to learn about functions, printing shit and for loops

move on to bigger and better things
>>
>>56264880
>It is a generalization of a syntactic analogy between systems of formal logic and computational calculi that was first discovered by the American mathematician Haskell Curry and logician William Alvin Howard.
No.
>>
>>56264841
Yeah sure remove even more newlines.
>>
>>56264914
but it will be unreadable
>>
It has been over a decade now, where widgets have been mainstream.
Why haven't developers understood what they are yet?
I mean one of the oldest widget is a clock. If you have a time widget on your desktop or in your panel, you wouldn't get a tiny representation of an analog clock.
You either get a giant analog clock or just the numbers.
This is probably because this is a very old widget and text was easy to implement, so let's look at the second most used widget today: the battery widget.
Here nobody seems to understand how to make a good battery widget.
IOS, android, windows, osx, KDE, gnome, mate, all fail this basic concept.
Why the hell would anyone think people wanted a picture of an AAA battery with bars inside?
What the hell does that even mean?
Some places you can get to see the percentage, but why is that not the obvious thing to start with?
On android, I can set it to show the percentage unless I am low on battery, then I get the AAA with a ! on it.
Like I am too stupid to know that 3% is bad or red means low, I get a fucking useless icon of a battery that doesn't even work for any android phone.
Who would be so idiotic?
Wouldn't a low battery situation be a good time to be specific whether you have 5, 10 or 20 minutes left?
The different between 95 and 93 means jack shit, but 5 and 3 means the world.
And on the desktop, isn't laptops an old enough concept so people who would design something like that would be aware that a battery widget might be a lot more useful if you could see the numbers rather than a picture of a battery?

It is so stupid it hurts my head.
How can i3 be better at design than gnome?
>>
>>56264901
>Haskell Curry
>Curry
POO
IN
THE
FUCKING
LOO
PAJEET
>>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main (int argc, char** argv)
{
int i, n = strtol(argv[1], NULL, 0);
char buffer[n+1];
for (i = 0; i < n; i++)
{
memset(buffer, ' ', n);
buffer[i] = '*';
buffer[n-i-1] = '*';
buffer[n] = '\0';
puts(buffer);
}
return 0;
}
>>
>>56264859

I was memeing. I'm not smart enough for moe-nads.
>>
>>56264880
>>56264901
I mean, C programs could be proofs if their types were accurate.

A C procedure returning an int is not a member of the function space Unit -> Integer. It's got a ton of potential side effects tacked on, and all these effects don't mesh well with Curry-Howard.
>>
>>56264917
Sounds like something up your valley.
>>
how do I access a c functions manpage from withing vim again?
>>
>>56264991
:!man func
?
>>
>>56265005
what about the hotkey where it manpages the function under the cursor
>>
>>56264964
 int n = atoi(argv[1]); 

other than that pretty good
>>
>>56264964
wtf, thats so concise
so good too
>>
>>56265016
dunno then I don't use vim
>>
>>56265025
>removing functionality for no reason
What's your reasoning?
>>
>>56264964
>char buffer[n+1]

What if I type in 2 147 483 647 ?


Also
>uses C99
>doesn't declare int i in the for loop

4 / 10 see me after class
>>
>>56265045
?
>>
>>56264964
how do I get this good lol
>>
>>56265067
strtol(argv[1], NULL, 0) supports multiple bases and does error checking, whereas atoi does not.
>>
>>56265066
>What if I type in 2 147 483 647 ?
I tried that in >>56264841 's example and got a segfault.

>>doesn't declare int i in the for loop
habit

>>56265067
atoi() doesn't support hex prefix (0x), strtol does and optionally returns the end of the integer part of the string.
>>
>>56265099
top kek
>a simple cross program
>wants to do all kinds of checkings
>the diagonal is given by the user
>the user will input a integer

you should be worried about that in more complex programs, not this dogshit
>>
>>56265131
>okay it's better but lalalala it doesn't matter lala :)
>>
>>56265140
d:)
>>
>>56265083
>>56265038
Samefag

>>56264964
buffer[n] = '\0' and memset(buffer, ' ', n) are redundant to have inside the loop

memset(buffer, ' ', n - 1);
buffer[n] = '\0';
for (i = 0; i < n; i++)
{
buffer[i] = '*';
buffer[n - i - 1] = '*';
puts(buffer);
buffer[i] = buffer[n - i - 1] = ' ';
}



>>56265131
>lalalalalalala
>>
File: te1zrah.gif (214KB, 640x480px) Image search: [Google]
te1zrah.gif
214KB, 640x480px
I recently open sourced pic related. The gif doesn't do it justice, the scene changes with the time of day. It's like f.lux meets pixel art. You can download the project here:

https://github.com/JustinMBrown/Living-Worlds

it's just html 5 and js
>>
>>56265162
>ive open sourced someone elses code

what
>>
>>56265158
>buffer[n] = '\0' and memset(buffer, ' ', n) are redundant to have inside the loop
True about the null terminator but it's easy to put the memset() in the loop to automatically clear the old asterisks. I think it's more elegant this way.
>>
>>56265140
>>56265158
>pass no args
>segfault
>input the number 465465465654646465465
>nothing happens

lol
>>
I don't think I have EVER had a program work on the first try
>>
>>56265162
what exaclty did you do?

i dont understand
>>
>>56265180
>segfault
Would happen with atoi all the same.

>nothing happens
If you don't handle the error.
>>
>>56265162
i'm trying to access you mac computer, but something is happened...

could you allow ssh users?
>>
>>56265173
Of course, this is nitpicking, but without any compiler optimisations and a hypothetical lousy implementation of memset (as in, a for-loop), you'll end up doing having O(n * n) run-time performance for no good reason other than "it's more elegant"
>>
>>56264919

The problem is precision. Not even the OS knows if you are at exactly 3% or 1% because batteries are different depending on how well they've been taken care of. The only thing the OS knows for sure is that the battery can die at any moment.

My samsung shows all the way down to 0%, but can still function for a bit. It's fairly precise, but it's shut down at 2% before.
>>
>>56264964

Recursive printf version:
void print_cross(int size, int padding) {
if (size == 1) {
printf("%*c\n", padding + 1, '*');
return;
}
printf("%*c%*c\n", padding + 1, '*', size - 1, '*');
print_cross(size - 2, padding + 1);
printf("%*c%*c\n", padding + 1, '*', size - 1, '*');
}

int main() {
int n; scanf("%d", &n); n=n|1;
print_cross(n, 0);
return 0;
}
>>
>>56265219
Elegance is better than unneeded efficiency.
>>
>>56265232
Why are you using C?
>>
>>56265232
Elegance is a subjective opinion. I find efficient algorithms to be elegant, while I find minimalistic code (as in writing as compact as possible for the sake of writing compact code) inelegant.
>>
>>56265172

I like to think of it as a rescue. It was still "useable" in the wayback machine. I just took it and made it run without the server side components. Also he released the source under the LGPL.
>>
>>56265230
>n=n|1;

n |= 1;
>>
>>56265301
Or even:
print_cross(n|1, 0);
>>
>>56265326
Indeed
>>
>>56265326
That's a copy paste from the OP's main.
n should be unsigned int, and scanf return value should be checked.
>>
>>56258397
>>56258397

Omfg...
Here
http://pythoncentral.io/pythons-range-function-explained/

Read first
Try
Read again
Ask later
>>
>tfw work at a small business doing embedded dev
>products used by tons of companies, including some big names
>I'm the only programmer and no one reviews my code
>live in constant fear that one day my shit is going to fail spectacularly

I test my shit really thoroughly, but I just know that I'm going to miss something and it's going to fuck everything up.

At least I'm getting overpaid, I guess.
>>
>>56265375
Prove that your program is correct.
>>
Rate my recursive string reversal function

size_t reverse(const char* input, char* output)
{
if (*input != '\0')
{
size_t n = reverse(input + 1, output);
output[n] = *input;
return n + 1;
}

return 0;
}
>>
>>56265162

gfycat /ColorfulFewBluebottlejellyfish

Here's the project running on a pi. I use it as a desk accessory. When you get up in the morning you see the light striking the top of the mountain, and right now near dusk the sky is a nice shade of pink/purple. And since the photos are 600x480 and the 7in touch screen is 800x480, every pixel is crisp.
>>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>

#define VERSION "1.0.0"
#define COPYRIGHT \
"Copyright (C) 2015 Free Software Foundation, Inc.\n" \
"This is free software; see the source for copying conditions. There is NO\n" \
"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"

static int usage (char* prgm)
{
printf("usage: %s [OPTIONS] NUMBER\n"
"creates an ASCII star diagram, with NUMBER lines\n"
"\n"
"options:\n"
" -h, --help show usage text\n"
" -v, --version display version info\n"
" -c, --char CHAR character to use, default: '*'\n",
prgm);
return EXIT_SUCCESS;
}

static int version (char* prgm)
{
printf("%s " VERSION "\n" COPYRIGHT, prgm);
return 0;
}

int main (int argc, char** argv)
{
char ch = '*';
int count = 0;
bool count_defined = false;

char* prgm = argv[0];
for (int i = 1; i < argc; i++) {
#define OPT(a,b,c) (!(strcmp(a,b) && strcmp(a,c)))
if (OPT(argv[i], "-h", "--help")) {
return usage(prgm);
}
else if (OPT(argv[i], "-v", "--version")) {
return version(prgm);
}
else if (OPT(argv[i], "-c", "--char")) {
if (i == argc - 1) {
fprintf(stderr, "%s: no argument supplied for %s\n", prgm, argv[i]);
return EXIT_FAILURE;
}
else {
ch = argv[++i][0];
}
}
else if (argv[i][0] == '-') {
fprintf(stderr, "%s: invalid option: %s\n", prgm, argv[i]);
return EXIT_FAILURE;
}
else {
count = strtol(argv[i], NULL, 0);
count_defined = true;
}
}

if (!count_defined) {
return usage(prgm);
}
else if (count == 0) {
fprintf(stderr, "%s: invalid dimensions\n", prgm);
return EXIT_FAILURE;
}

char* buffer = malloc((count + 1) * sizeof(char));
buffer[count] = '\0';

for (int i = 0, j = count - 1; i < count; i++, j--) {
memset(buffer, ' ', count);
buffer[i] = ch;
buffer[j] = ch;
printf("%s\n", buffer);
}

free(buffer);
return EXIT_SUCCESS;
}
>>
>>56265232
elegance is just a way of saying circles over squares. It makes for a more endearing compromise.
>>
>>56265375

Don't worry. Mistakes happen and if your company owns up to them quick and you have a good product, people will forgive you unless it's a spectacular failure in terms of business breaking losses. Those usually don't happen. Also >>56265393 has it right.

Proving your programs correct is the only way to make sure your program won't get owned. You use Haskell + Isabelle to do this, for instance. Look at seL4.

https://sel4.systems/
>>
File: 1406803019377.jpg (103KB, 1280x720px) Image search: [Google]
1406803019377.jpg
103KB, 1280x720px
>All of these people using buffers for printing crosses
You guys suck.
>>
>>56265511
what r buffers
>>
I'm building a network stack in Python for shits and giggles.
It can reply to ARP and ICMP echo requests.
I still have to implement better ICMP and IP encoding and decoding, but it's pretty fun so far.
Having it respond to a normal ping is awesome.
The response times aren't that great though.

user@kiwi:~$ ping 10.3.1.254
PING 10.3.1.254 (10.3.1.254) 56(84) bytes of data.
66 bytes from 10.3.1.254: icmp_req=1 ttl=64 time=1.77 ms
66 bytes from 10.3.1.254: icmp_req=2 ttl=64 time=1.64 ms
66 bytes from 10.3.1.254: icmp_req=3 ttl=64 time=1.11 ms
reening@kiwi:~$ ip n s 10.3.1.254
10.3.1.254 dev switch0.301 lladdr 00:0c:29:aa:bb:cc STALE
>>
>>56265643
What's the performance difference against something like PyPy?
>>
>>56265224
So the measurements are imprecise.
That's a hardware problem.
But it is not like you jump from 5% to 20% to 2%.
The easy thing to implement is to just read the battery file and print the number.
If you want to get fancy, you make the text appear inside a battery icon, but why would anyone spend their time making the graphical solution and not make a useable one?
The user of the laptop will know that 100-20 is plenty of battery, but less than that is spent in minutes. But when you have to click on the icon or hover over it to see how much there is left, the programmer who made it is a failure as a programmer, a failure as a user of any computer application and a failure as a human being.
And the thing that bugs me is it is not isolated. It is the fucking norm to not make a good battery widget.
How many years did it take before you could get the text icon without rooting the phone? It is fucking embarrassing.
No programmer can ever do a half decent job as long as these untrained monkeys are kept around. A child who is new to programming would do a better job.
>>
>>56265465
>printf("%s\n", buffer);
>not puts(buffer)

lol
>>
>>56265693
PyPy doesn't do raw sockets unfortunately
>>
>>56265529

memory chunks used for storing characters before printing them.

Contrary to what >>56265511 says, it's the right thing to do, as each "print" would do a round-trip to the kernel.
Printing each character one by one would be inefficient as fuck.
>>
>>56265853
>as each "print" would do a round-trip to the kernel
No it's not. stdio file are buffered.
There is only a syscall when the buffers are flushed, which would only happen when you print a newline.
>>
>>56265016
K
>>
File: serveimage.jpg (61KB, 640x480px) Image search: [Google]
serveimage.jpg
61KB, 640x480px
>>56264841
>maga
Go back to your containment board Drumpftard.
>>
>>56266027
go back to rêddit cuck
>>
File: cuk.png (247KB, 283x427px) Image search: [Google]
cuk.png
247KB, 283x427px
>>56266056
You first poltard.
>>
File: serveimage-2.jpg (81KB, 850x400px) Image search: [Google]
serveimage-2.jpg
81KB, 850x400px
>>56266077
Dubs confirm.

Drumpfags >>/out/
>>
>>56266077
i don't even go to /pol/, redditor
>>
File: serveimage-1.jpg (35KB, 640x530px) Image search: [Google]
serveimage-1.jpg
35KB, 640x530px
>>56266092
Yes you do >>/v/edditor
>>
>>56265265
So where's the license, because I'm looking at the page and there doesn't seem to be one. By not including the LGPL with the original source and a LGPL-compatible license with your own changes, you are violating the LGPL.
>>
>>56266027
>what is rule 3
>>
File: serveimage-3.jpg (41KB, 640x426px) Image search: [Google]
serveimage-3.jpg
41KB, 640x426px
>>56266133
Yes, the rule that says racist Drumpftards aren't allowed here.
>>
>>56266118
Not an argument.
>>
File: le jew trump.jpg (624KB, 836x933px) Image search: [Google]
le jew trump.jpg
624KB, 836x933px
>>56266152
>trusting a jew with his money
baka desu
>>
>>56266152
what's wrong with any of the quotes in that pic, you faggot?
>>
File: inoperable reddit cancer.png (53KB, 571x618px) Image search: [Google]
inoperable reddit cancer.png
53KB, 571x618px
>>56266172
>le
>>>/reddit/
>>
>>56259666
Emacs or Vim are perfect for Satan
>>
>>56265394
Rewrite for TCO. Otherwise it's garbage.
>>
Can somebody help me out with some hw?

I need to write a program that prints out numbers in english, using recursion.
The problem is with zero. I can't get it to print out without fucking up my do while loop. Adding it to the array doesn't work either.


[CODE]#include <stdio.h>

int countDigits(int value);
void convert(int number);

char *ones[]={"", "one", "two", "three", "four", "five",
"six", "seven", "eight", "nine","ten", "eleven",
"twelve", "thirteen", "fourteen", "fifteen", "sixteen",
"seventeen", "eighteen", "nineteen"};

char *tens[10]={"", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy",
"eighty", "ninety"};


int main(void)
{
int inputNum;
printf("Enter numbers in figures; use a negative value to stop..\n");
// continue running loop until a negative # is entered
do{
printf("\nNumber: ");
scanf("%d", &inputNum);
//special case for zero
/*if(inputNum==0){
printf("zero");
} */
//check if user entered over 999999.
if(inputNum>999999)
{
printf("Only numbers less than 999999.\n");
continue;
}

// call function to convert to english text
convert(inputNum);

}while(inputNum >0);
printf("\n");

}


void convert(int number)
{

if (number > 0 && number < 20){
printf(" %s ",ones[number]);

}else if (number / 1000 > 0) {
convert(number / 1000);
printf(" thousand ");
convert(number % 1000);

}else if (number / 100 > 0) {
convert(number / 100);
printf(" hundred ");
convert(number % 100);
}else if (number / 10 >= 2) {
printf(" %s ", tens[number / 10]);
convert(number % 10);
}

}
[/CODE]
>>
Why is compiling Android from scratch overly complicated?
>>
>>56258397
>using else after a for loop

What's the fucking purpose of this? It's hard to understand and it's useless.
>>
>>56266404
fuck
[CODE]#include <stdio.h>

int countDigits(int value);
void convert(int number);

char *ones[]={"", "one", "two", "three", "four", "five",
"six", "seven", "eight", "nine","ten", "eleven",
"twelve", "thirteen", "fourteen", "fifteen", "sixteen",
"seventeen", "eighteen", "nineteen"};

char *tens[10]={"", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy",
"eighty", "ninety"};


int main(void)
{
int inputNum;
printf("Enter numbers in figures; use a negative value to stop..\n");
// continue running loop until a negative # is entered
do{
printf("\nNumber: ");
scanf("%d", &inputNum);
//special case for zero
/*if(inputNum==0){
printf("zero");
} */
//check if user entered over 999999.
if(inputNum>999999)
{
printf("Only numbers less than 999999.\n");
continue;
}

// call function to convert to english text
convert(inputNum);

}while(inputNum >0);
printf("\n");

}


void convert(int number)
{

if (number > 0 && number < 20){
printf(" %s ",ones[number]);

}else if (number / 1000 > 0) {
convert(number / 1000);
printf(" thousand ");
convert(number % 1000);

}else if (number / 100 > 0) {
convert(number / 100);
printf(" hundred ");
convert(number % 100);
}else if (number / 10 >= 2) {
printf(" %s ", tens[number / 10]);
convert(number % 10);
}

}[/CODE]
>>
>>56266454
LOWECASE CODE TAGS
>>
>>56266454
that you thought it was the newlines is funny
>>
>>56266454
the code tags are lowercase, dummy
>>
>>56266461
>
#include <stdio.h>
>int countDigits(int value);
>void convert(int number);
>char *ones[]={"", "one", "two", "three", "four", "five",
>"six", "seven", "eight", "nine","ten", "eleven",
>"twelve", "thirteen", "fourteen", "fifteen", "sixteen",
>"seventeen", "eighteen", "nineteen"};
>char *tens[10]={"", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy",
>"eighty", "ninety"};
>int main(void)
>{
>int inputNum;
>printf("Enter numbers in figures; use a negative value to stop..\n");
>// continue running loop until a negative # is entered
>do{
>printf("\nNumber: ");
>scanf("%d", &inputNum);
>//special case for zero
>/*if(inputNum==0){
>printf("zero");
>} */
>//check if user entered over 999999.
>if(inputNum>999999)
>{
>printf("Only numbers less than 999999.\n");
>continue;
>}
>// call function to convert to english text
>convert(inputNum);
>}while(inputNum >0);
>printf("\n");
>}
>void convert(int number)
>{
>if (number > 0 && number < 20){
>printf(" %s ",ones[number]);
>}else if (number / 1000 > 0) {
>convert(number / 1000);
>printf(" thousand ");
>convert(number % 1000);
>}else if (number / 100 > 0) {
>convert(number / 100);
>printf(" hundred ");
>convert(number % 100);
>}else if (number / 10 >= 2) {
>printf(" %s ", tens[number / 10]);
>convert(number % 10);
>}
>}
>>
>>56266466
>>56266471
wtf i just wanted to make games. Nobody told me CS would be so hard.
>>
>>56266476
This next post is going to be bump limit, and I' mgoing to tell you, stop fucking up.
>>
>>56260416
Hey, I don't know if you're still there, but you described the perfect job opportunity for me. If you reply I can give you a contact medium.
>>
NEW THREAD!!

>>56266496
>>
>>56265465
>option parsing
What hell. Why not use getopt and getopt_long? You are on a GNU compatible system, no?
>>
>>56260873
To make a Singleton.
>>
>>56258452
>reads "news" from newspapers

LOL
>>
>>56266372
>do something that isn't possible otherwise it's garbage
>>
>>56266673
You can rewrite it so it uses TCO. If you really can't, you're honestly retarded. Usually calling the function recursively on the return signals the compiler to use TCO. Usually the compiler has to be O1 or greater.
>>
>>56258802
What beef do people have with anime images?
>>
>>56258818
Dude I'm a fucking English major and I do those things for a living. Grow a pair will you?
>>
>>56266694
You need to calculate the position. How do you do that in a TCO manner?

Prove that you're not retarded then, come on. I'm waiting.
>>
>>56259263
I like it
>>
>>56259237
You got a bug. I wrote "ur a fagget" and it appeared three times.
>>
>>56266796
Maybe he's just that much of a faggot.
>>
>>56266730
>>56266694
Guess he couldn't do it.
>>
File: jon_blow.jpg (49KB, 615x347px) Image search: [Google]
jon_blow.jpg
49KB, 615x347px
any thoughts on jai?
>>
>>56266673
>>56266730
not the other guy but it's pretty easy actually


// pass in the end of the output string, before the NULL terminator
void reverse_string(char* in, char* out) {
if(*in != 0) {
*out = *in;
reverse_string(in+1, out-1);
}
}
>>
>>56267154
So you'd have to do a strlen first then?

That's retarded
>>
>>56267193
how else do you allocate enough space for the out pointer in the first place?
your routine would have required it, no?
>>
>>56267211
>your routine would have required it, no?
It can be arbitrarily big, as long as it is big enough.

Your function requires either the start offset to be known (so you have to return the start pointer, which is okay I guess) or that the size is known.
>>
>>56267248
so what you mean is that your routine accepts a guess that might not be correct

to be correct, you HAVE to do strlen, or the equivalent

or you only accept strings of a certain length or shorter
>>
>>56267248
>>56267315
>so what you mean is that your routine accepts a guess that might not be correct
Are you new to C or something? Try passing a non-null terminated string to strlen.

char* your_reverse(const char* in, char* out)
{
if (*in != '\0')
{
*out = *in;
return your_reverse(in + 1, out - 1);
}
return out;
}

size_t my_reverse(const char* in, char* out)
{
if (*in != '\0')
{
size_t n = my_reverse(in + 1, out);
out[n] = *in;
return n + 1;
}
return 0;
}

int main()
{
char buffer[0x1000];

// places the reversed string in start of buffer
size_t n = my_reverse("reverse this", buffer);
printf("'%s' is %zu chars\n", buffer, n);

// places the reversed string in end of buffer
char* pos = your_reverse("reverse this", buffer + sizeof(buffer) - 2);
buffer[sizeof(buffer) - 1] = '\0';
printf("'%s' is %zu chars\n", pos, buffer + sizeof(buffer) - pos);


}
>>
>>56267359
Should be return out + 1;
>>
>>56267359
i'm pretty tired and maybe i'm not just understanding what you're getting at.

yeah your version allows using a constant N-length buffer, but that's only useful when you know a string is going to be less than N characters in length, right?

The whole problem you have with mine is just an artifact of not having length-prefixed strings and goes away with those.
>>
>>56267422
I'm not really "getting" at anything, just pointing out differences. In my experience with C you generally need to make sure that buffers are large enough, whether you use strcpy, memcpy or whatever. Yes, if you know the length of the string in advance, then there is no problem. My code originally came from another /dpt/ where the task was to do it recursively without calculating the length of the string first.

https://archive.rebeccablacktech.com/g/thread/S55699322#p55700574
>>
>>56267504
> In my experience with C you generally need to make sure that buffers are large enough
I guess that's true
you can always realloc though
>>
>>56266119

The license is here at the bottom of this now non existent website:

https://web.archive.org/web/20160419082955/http://www.effectgames.com/effect/article.psp.html/joe/Old_School_Color_Cycling_with_HTML5

I'll add that license if the creator complains I guess.
>>
>>56267154
The other guy, this is exactly what I would have written. Busy with gf.

>>56266730
Your code is retarded because of what the other guy said, you need to allocate the output buffer of a particular size, so doing a strlen is eventually necessary. Using large arbitrary length static or stack memory is not as common of a usage as being run on malloc'd memory, so that point is null. And you are using three areas of memory (source, stack, and dest.) instead of two. Additionally, a strlen would bring the entire source string into the cache, so my guess is your version would be 50% slower or so.
Thread posts: 338
Thread images: 34


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