[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
Daily Programming Thread
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 255
Thread images: 28
File: languages.png (81 KB, 537x574) Image search: [Google]
languages.png
81 KB, 537x574
Old /dpt/ at >>51369628

What are you working on?
If programming languages were religions, what would they be and why?
What's better - Smalltalk or Objective-C?
Answer these and other questions here.
>>
>>51381637

I'm working on a programming language. It's called Valutron.

Valutron is a Lisp. It has two key differences to many other Lisps: it has actual syntax instead of S-expressions all the way down, and I place emphasis on the dynamic Object-Oriented system that is available.

Here is a code example:

// let's define a 'get-hello-world' generic
defgeneric get-hello-world (object some-object) => string;

// let's define a 'hello' class
defclass hello (object)
{
slot string hello : initarg hello:;
slot string world : accessor getWorld, initarg world:;
}

defmethod get-hello-world (hello some-object) => string
{
let result = copy(some-object.hello);
append(to: result, some-object.getWorld);
result
}

let aHello = make-instance (hello: "hello", world: "world");
// the arrow -> is an alternative form of method dispatch syntax
print(stdio, aHello->get-hello-world());



Here's the same expressed in CL with CLOS:

(defgeneric get-hello-world ((some-object object)))

(defclass hello (object)
((hello :initarg :hello)
(world :initarg :world
:accessor getworld)
)

(defmethod get-hello-world ((some-object hello))
(setq result (copy (hello some-object)))
(append :to result (getWorld some-object))
(result)
)

(setq aHello (make-instance 'hello :hello 'hello :world 'world))

(print stdio (get-hello-world aHello))
>>
File: 1442803817321.jpg (18 KB, 218x213) Image search: [Google]
1442803817321.jpg
18 KB, 218x213
>>51381637
I've decided to learn C++.
What would happen if i was to do:
double arr[3] = {3.14, 22.7, 6.9};
int *arrp = arr;
arrp += 4; // more elements than there are in the array!
>>
>>51381851
shit, that points to the wrong type. oh well.
>>
>>51381851
It would point to an area in memory beyond the end of the array. It would be dangerous to manipulate that memory.
>>
File: file.png (226 KB, 316x475) Image search: [Google]
file.png
226 KB, 316x475
Are this and the C programming language book actually worth reading? And at what point should you read them? I'm only in my first semester of CS and have only used python.
>>
>>51381637
>>>51369628 → →
>→
NICE FUCKING COPY PASTE FUCKING RETARD

DON'T POST ITT FAGGOTS

THIS IS THE REAL THREAD: >>51377307

SAGE
>>
>>51382105
Nigger, both threads are pretty full
>>
File: vfs.jpg (62 KB, 635x744) Image search: [Google]
vfs.jpg
62 KB, 635x744
>>51381637
A VFS with built in security. Well... A mock up of it at least.
>>
File: sicpIsEveryoneReady?.png (2 MB, 1920x1080) Image search: [Google]
sicpIsEveryoneReady?.png
2 MB, 1920x1080
>>51382050
I am reading SICP right now and it is pretty interesting so far. It is an intro programming book, so you can start whenever.
>>
>1st year engineering student
>have to do all these other modules when I just want to spend all my time learning how to code

Fuck this shit bruh. I have 6 weeks off at christmas, how can i become as proficient as possible at java in that period of time? Willing to spend 10 - 12 hours a day at it
>>
>>51382187
Alright, I may jump into it once the semester is over, thanks.
>>
>>51382140
>258 posts
>at this time of the day
>full
piss off newfag
>>
File: in.jpg (42 KB, 1600x734) Image search: [Google]
in.jpg
42 KB, 1600x734
>>51382189
Learn Python then Haskell. You will thank me later.
Actually, just skip Python and go straight to Haskell. You will thank me even more.
>>
File: 1432841575850.jpg (72 KB, 400x579) Image search: [Google]
1432841575850.jpg
72 KB, 400x579
>>51382200
just be sure to do as many exercises as you can.
>>
Problem 7 in Project Euler. I'm using a sieve to generate primes:
https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes

Question: how do I create an array starting at index 2 instead of 0 as described in the pseudo-code in the article? Or am I approaching this problem completely wrong?
>>
Guys, what was that website that had guides/tutorials for programming languages? It was red if I remember correctly. Sumimasen for being slightly off topic
>>
>>51382262
sure is new in here
>>
>>51382189
>spending all six weeks training on being a code monkey
You're only half correct.
The thing about programming is that understanding your programming language at a base level is almost as important as understanding algorithms.

In short: If you spend your entire break solving these problems you'll probably become a god among men. They require an understanding of mathematical concepts, algorithms as well as basic logic, and how your programming language works. https://icpc.baylor.edu/worldfinals/problems
>>
>>51382273
;____;
b-but
>>
>>51382189
if you're new
https://docs.oracle.com/javase/tutorial/

don't listen to rotten neckbeard kids telling you to use fucking scripting and 'muh functional' languages
>>
>>51382262
Why do you need an array to start at index 2?
>>
>>51382279
make a normal array and just don't use the first two indices

or if you're using a language with pointers then you could have a pointer to the array - 2
>>
>>51381637
oi, is there any way to write a google images scraper?
it looks like they don't actually provide the link to the full image, just a thumbnail <img> and an <a> linking to the source page
>>
>>51382276
Not fully sure what you mean, i meant learning java in a general sense. So doing whatever it takes to become as proficient as possible. Whether thats spending hours reading and trying to understand it or hours practicing problems. Whatever will make me as good as I can be at it.
>>
>>51382309
Input: an integer n > 1

Let A be an array of Boolean values, indexed by integers 2 to n,
initially all set to true.

for i = 2, 3, 4, ..., not exceeding √n:
if A[i] is true:
for j = i2, i2+i, i2+2i, i2+3i, ..., not exceeding n:
A[j] := false

Output: all i such that A[i] is true.

>Let A be an array of Boolean values, indexed by integers 2 to n

>>51382311
So for example, in a for loop I would just
A = [1,2,3,4]
for (i = 2; i < A.length; i++){
print(A[i]);
}

instead of starting i at 0?
>>
>>51382288
Thanks man, im not completely new but the course is moving at a very fast pace so i feel like im regurgitating previous examples in my work rather than having a comprehensive understanding of what exactly im doing. Going to use that resource for sure
>>
>>51382357
yes, except that arrays in most languages are 0-based so you'd have A = [0,1,2 etc]
>>
>>51382343
You're not going to know that you're proficient at a language until you stop doing stupid shit like "do this just because, I don't know if it will work or not"
The best way to challenge your understanding of a language is to force you to implement a varied number of topics.
>>
>>51382288
Negro, I have only encountered one other language more unpleasant than java, and that was c++.
>>
>>51382382
Okay thank you anon. I thought it would be simple like that.
>>
>>51382384
Having said that, the fastest way to learn a language is to already know another, and then read a book on syntax and features.
A good example of one (for C# anyway) is C# In Depth.
>>
>>51382406
if there is a language better than java it is C++
>>
>>51382430
"Better", in the sense of more efficient, and better designed, sure. But writing in it makes me want to hit myself in the head with a brick.
>>
>>51382465
You're probably just doing dumb crap like losing track of memory after tossing pointers around. Try smart pointers and more C++11/14.
>>
>>51382516
what's the difference between a smart pointer and a normal pointer
>>
>>51383341

Smart pointers are objects that hold pointers, and free them when they go out of scope (using RAII). They may store a reference count, and instead free them when the reference count hits 0. In this case, they are called shared pointers.
>>
>>51381824
>get-hello-world
>-
Stop that.
>>
I've never used python before but have medium experience with C#. Is making a script which asks for a password and then bruteforces it a viable first project or is that too complicated in python.
>>
>>51381851
you could have segmentation faults and access restricted memory.

For that you should allocate memory dynamically. using new and delete.
>>
File: 1378062513008.jpg (23 KB, 250x250) Image search: [Google]
1378062513008.jpg
23 KB, 250x250
>hi = new JButton("Random button here just for decoration.~ :D");
>>
>>51383714
Why would you ask for a password then bruteforce it?
And anyway, there's multiple ways to bruteforce them and python probably isn't the best language for it if you're not just doing it for experience.
>>
>>51383586
Why?
>>
>>51383838
Because using an operator in naming is fucking retarded.
>>
>>51383869
Good thing it's not an operator. It's a dash. ;-)
>>
>>51383765
Just for fun and learning. Thanks.
>>
>>51382272
codeacademy
>>
>>51383898
>m-muh semantics!!
new-var=my-var-other-var;

Is that:
>my-var - other-var
>my - var - other - var
>my-var - other - var
>my - var - other-var

It's none of the above, it's my-var-other-var.
>>
>>51383986
Normally a language that allows hyphens in symbols requires whitespace around operators.
Your example would become
new-var = my-var-other-var

or
new-var = my-var - other-var

Of course, anyone who names something "my-var and/or other-var" is fucking retarded anyway.
>>
I must be a retard somehow, because I'm delving into C++ (i got bored with python quickly and wanted something more challenging,), and even though my code is correct I can't get a simple "hello world" or ANYTHING to display in a console window. Google isn't helping me at all. It just opens a blank cmd prompt even though there aren't any errors with my code. What the fuck am I doing wrong? Has anyone else ever had this problem before?
>>
>>51384017
Anyone who names variables with hyphens is fucking retarded anyway.
>>
>>51384045
When you can, they're the best and most readable way.
myvarothervar
my_var_other_var
myVarOtherVar
MyVarOtherVar
MYVAROTHERVAR
MY_VAR_OTHER_VAR

weird, gross, and hard to read.
my-var-other-var is your solution.
>>
>>51384061
>my_var_other_var
>weird, gross, and hard to read

What am I reading?
>>
>>51383986
(define new-var=my-var-other-var 5)
new-var=my-var-other-var
;Value: 5

Your whole line is a single variable with a line comment starting at the end. It's not ambiguous.
>>
>>51383986
NONE of the above, it should literally be an identifier called:
new-var=my-var-other-var;
: 7 ." jelly?" ;  ok
7 jelly? ok

even pure numbers should be able to name variables or procedures.
>>
>>51384081
its weird and unnatural. you never see words separated by underscores. hyphenated words are very common tho.
>>
Hi, I have no idea how to program. I want a resource I can get started on tonight which I won't have to access the internet at all to use. (a book and a compiler I guess) I was going to do Eclipse and Heads First Java, but AGDG, the amateur videogame development group, told me to do a "non-OOP" programming language first. Should I do that or go with Java? If not Java, which language and what compiler and what book?
>>
>>51384045
Nice argument.
I'm personally a fan of hyphens-in-identifiers but very little languages support it so I don't really worry about it.

>>51383916
Try this:
#!/usr/bin/python3
def code_char (c, k):
""" encrypts/decrypts a single character 'c' using the key character 'k'.
note: code_char(code_char(C, K), K) = C for all chars C, K
"""
return chr(ord(c) ^ ord(k)) # XOR encrypt

def code (text, key):
""" encrypts/decrypts an entire string 'text' using the key string 'key'
note: code(code(S, K), K) = S for all strings S, K
"""
key_len = len(key)
result = ""

for i in range(len(text)):
c = text[i] # get character from text
k = key[i % key_len] # loop the key over the text
result += code_char(c, k) # encode it

# e.g. text="hello this is input text", key="key"
# hello this is input text
# keykeykeykeykeykeykeykey
# ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ code each pair

return result

def break_code (input):
""" decrypts an encoded string 'input' and returns the key used to decrypt it """
#
#
# ... implement this ...
#
#
return key


def code_example ():
""" shows example encrypting/decrypting """
secret = "hello this is input text"
key = "key"

encoded = code(secret, key)
print("[example] encoded: ", repr(encoded)) # repr() to escape special characters

secret = "" # destroy the secret message 'just in case'

decoded = code(encoded, key)
print("[example] decoded: ", repr(decoded))


def break_code_example ():
encoded = '\x03\x00\x15\x07\nY\x1f\r\x10\x18E\x10\x18E\x10\x05\x15\x0c\x1fE\r\x0e\x1d\r' # an encoded string
key = break_code(encoded)

# get the secret (not anymore!) string
secret = code(encoded, key)

print("key: ", key)
print("message: ", secret)

# run examples
code_example()
break_code_example()
>>
>>51384061
Camel case is only ever hard to read when you insert acronyms.
>myGUIBase
for example.
Underscores are hard to write, easy to read.
All caps is const only, don't be a shitter and use them for non-const.
Your hyphen method is difficult to read when any math is involved.
>>
>>51384140
>you never see words separated by underscores

I don't think that's a valid criticism considering most programming language syntax is made up of things that aren't exactly natural.
>>
>>51384108
Now:
yet-another-var=my-var-other-var-new-var;
>>
>>51384045
>>51384061
>>51384173
>>51384175
>>51384017
>arguing over pointless opinions
Never stop bikeshedding, /g/
>>
>>51384175
a lot of programming languages are made up of things that make sense. like semicolons ending statements in c and its derivatives, or strings being surrounded by double-quotes.

>>51384173
just fucking insert whitespace around operators. it really isnt that difficult. i dont know why you wouldnt do that in the first place, anyway.
>>
>he uses nose
>>
>>51384111
And this shit is why you keep operators out of variable names.

>>51384199
You do realize that doesn't make it much easier to read, right?
>>
>>51384152
I definitely wouldn't recommend Java (as a first language or at all).
Python with thinkpython is alright and easy to get into and install, and it starts off procedural before going into OOP later.
>>
>>51384212
i think it helps.
variable=this-that-bam
variable = this - that - bam

obviously you can still tell what it's doing but it declutters a lot. clutter is annoying.
>>
>>51384199
>semicolons ending statements in c and its derivatives

This seems natural because we've been doing it for so long, but semi-colons don't end statements in natural language. They just join two independent clauses.

But again, it doesn't matter because, as noted, we've been doing it for so long.
>>
>>51384188
(define yet-another-var=my-var-other-var-new-var 50000)
yet-another-var=my-var-other-var-new-var;
;Value: 50000
>>
>>51381637
>What are you working on?
The official /dpt/ C toolkit: a FOSS, state of art, general utility C library.
>>
>>51384265
When are you actually gonna do something?
>>
File: umaru.jpg (282 KB, 640x961) Image search: [Google]
umaru.jpg
282 KB, 640x961
>>51384272
well, i made a repository which is already something, no ?
>>
>>51384251
for(;yet-another-var=my-var-other-var-new-var > 0; yet-another-var=my-var-other-var-new-var--)
print("help\n");
>>
>>51384272

The source is out there: https://bitbucket.org/Tetsumi/cdptlib/

It's a bit hectic compared to much simpler implementations like kvec.h and so forth.
>>
>>51384036
Post a minimal snippet to reproduce
>>
>>51384036
Are you running the code after compiling it?
>>
>>51384326
mirror: http://neetco.de/CodeArtisan/cdptlib
>>
>>51382326
pls respond
>>
>>51384265
>FOSS
>doesn't provide source when asked
>>
>>51384326
kvec.h has no type safety, the provided example doesn't work at all, you can not pass a vector as an argument without a warning.
>>
>>51384036
If the console window opens and then closes immediately, then try running the code from a console window. I.e. open a terminal, cd directory/containing/compiled/code, ./program_to_run.
>>
>>51384439
>kvec.h has no type safety

Meh
>>
>>51384045
RSI sufferer here. Lower case with hyphens is the comfiest naming scheme. Anything that requires the use of the shift key is shit.
>>
File: 6487.jpg (857 KB, 1178x833) Image search: [Google]
6487.jpg
857 KB, 1178x833
>>51384457
This is the problem with C macros: they are not typed contrary to c++ templates. A solution is to have macros that generate inline procedures. An inline procedure is like a typed macro except when you need a lvalue. for example,

#define foo(x) ( (x)->y )


you can use this as a lvalue

foo(bar) = 8;


this is not possible with a inline procedure.
inline int foo(Foo *f) 
{
return f->y
};

foo(bar) = 8; // invalid
>>
>>51384326
>base.h
Hello fucking shit that is code monkey tier.
>typedef char Char;
>typedef void Void;
>typedef bool Boolean;
>#define DEFINE_TYPEDEFS(Type)
People who do things like this should be killed.

I hope this is just troll code.
>>
>>51384557
it's not, kill me.
>>
>>51384191
syntax is not bikeshedding, there are a lot of languages that are ruined by bad syntax, the longevity of C has a lot to do with its syntax

Also there is really no major ideas in programming language design. Picking a language now has more to do with finding the right style and features that suit you. Pretty much every 'new' idea you can think of has already been implemented by some language
>>
>>51384557
This is what happens when you let Javafags write C code.
>>
i know jack shit about programming

I want to dick around with javascript or rust, anyone know any good resources?
>>
>>51384631
code.org
>>
>>51384631
Go read a book
>>
>>51384631

w3schools of course
>>
>>51384536

C macros are shit, but it's too late to do anything about it. That's the bottom line.
>>
>>51384643
kek

>>51384641
i would love to, any recommendations? eich's books?

>>51384637
would prefer to not need to sign up for shit
>>
>>51384631
>>51384667
>i know jackshit about programming
Before you learn a language just for the hell of it, ask yourself why you want to learn how to program and how it will benefit you.
>>
>>51384631
http://ddili.org/ders/d.en/index.html
>>
>>51384685
> D

:^)

>>51384677
I would like to contribute to a few projects that use said languages

I guess I should mention i know a bit more than "jack shit", I've written incredibly retarded python scripts
>>
need some help on a small assignment in Python that I thought I solved but keep getting fucked up on.

I need to write a function that erases extra spaces and leaves only single spaces WITHOUT the split method or any built in functions.

for example it would take "hey what's up"
and change it to "hey what's up"
>>
File: umarusee.jpg (113 KB, 1280x720) Image search: [Google]
umarusee.jpg
113 KB, 1280x720
>>51384598
explain. If you are referring to the style, it's not really like java. I can't consider myself a javafags since have programmed little in java though i fairly know the standard (even found a major flaw). I also have written C code that is more "conventional":

http://neetco.de/CodeArtisan/winc11threads
http://neetco.de/CodeArtisan/oglicdloader

tests/benchmarks of
http://neetco.de/CodeArtisan/tetsumirc4x64
http://neetco.de/CodeArtisan/tlthreadx64
http://neetco.de/CodeArtisan/tmsgx64

>>51384646
That's why there GNU C.
>>
>>51384712
tmp = ""
for i in range(len(s)):
if s[i] == " " and s[i+1] == " ":
pass
return tmp

figger it out
>>
>>51384744
that's what I thought but not working
>>
>>51384785
idk i havent written python since 2.8 came out
>>
>>51384744
wouldn't that raise an exception? Would probably better to try to start from the second character and go from there.

def rm_spaces(s):
if len(s) == 0:
return s
aux = s[0]
for i in xrange(1,len(s)):
if s[i] == ' ' and s[i-1] == ' ':
continue
aux += s[i]
return aux
>>
>>51384892
yeah just do his homework for him thats cool
>>
>>51384897
Just helping him become the next billy gates ;)
>>
>>51384785
Strings are immutable in python. You have to write a new one.

def clean(s):
strList = []
for a in range(len(s)):
if s[a] == " " and s[a+1] == " ":
pass
else:
strList.append(s[a])
myStr = ''
for b in range(len(strList)):
myStr += strList[b]
return myStr


depending on what your prof means by "built-in functions" you could use join to accomplish it a little faster:

def clean(s):
strList = []
myStr = ''
for a in range(len(s)):
if s[a] == " " and s[a+1] == " ":
pass
else:
strList.append(s[a])
return myStr.join(strList)
>>
File: functinoalprgrammer.png (771 KB, 862x812) Image search: [Google]
functinoalprgrammer.png
771 KB, 862x812
>>>51385065

Been told to cross-post this here.

For those who don't know, Haskell is this programming language that comprises the veritable freaks of nature of the programming ecosystem.

They will threaten you if you point out their language is a fraud.

https://en.wikipedia.org/wiki/Argumentum_ad_populum
https://en.wikipedia.org/wiki/Solipsism
https://en.wikipedia.org/wiki/Illusory_superiority
https://en.wikipedia.org/wiki/In-group_favoritism
https://en.wikipedia.org/wiki/Asch_conformity_experiments
https://en.wikipedia.org/wiki/The_Emperor%27s_New_Clothes
>>
>>51384326
You're missing the point.
Why try to emulate generics in C when other languages actually have them in the language?
C programmers aren't going to want to use your shitty verbose library, even if it somehow has a 1 ms time improvement. Anyone would rather C++, or D, or Rust or Go if they wanted a fast, strictly typed language with generics.
C is for bare metal shit where you probably don't need generics. And if you REALLY MUST HAVE THEM then you use C++.
>>
List<Long> myList = new ArrayList<Long>(someHashMap.values());


Does anyone know if this will do a full copy or just contain references in Java?
>>
>>51384719
>one function per file
>copyrights are longer than the functions themselves
Ok you have got to be a troll.
>>
>>51382229

https://storify.com/realtalktech/why-functional-programming-sucks
>>
>>51385089
>>51385156
Do you really have nothing better to do with your time than piss of function programmers?
>>
>>51385151
those are procedures, not functions.

it's one procedure per file because you can then compile them independently and have an object file (.o) for each one. you then pack all object files into a library so later when you need to link only one procedure, you just link its object file, not the whole lib. anyone who implemented a library know that. also, code navigation is easier.
>>
>>51385099

It's not my library, so I have no way to gauge the motivations.
>>
>>51385224
Modern linkers don't remove dead code?
If so, I'd personally rather link one object for the whole library.
>>
>>51382229
Learning Haskell first won't help you learn a single other language. Did you learn Haskell first?
>>
>>51385224
Most of those functions cannot be used independently, it's retarded to split them, and it makes navigation harder because you have to skip around in multiple files.
>>
Is using indices in python to access elements of a list not pythonic enough?
>>
>>51385332
no?
>>
>>51385344
I mean, is there a cleaner way of accessing specific elements of a tuple in a list than list[a][b]
>>
>>51385332
Why wouldn't it be?
>>
>>51385332
You should try to use iterators whenever you can for maximum pythonicity

>>51385352
If you just mean grabbing element n of a list, then that's the best way.

Also tuples are cool.
>>
>>51385352
Well instead of "x=a[0]; y=a[1]" you should use "x,y = a"
But if the index is variable, or if the length is variable, then just use [] indexing. It exists for a reason (so you can use it)

To programmers trying to write "pythonic" Python or "conventional" C/C++ or "well designed" Java: Shut up, calm down, write code. Write clear, concise and simple code, but stop worrying about every single line being how somebody else would want you to write it.
>>
F# is the most painful shit in the world, yet it's kinda nice. Just posting some major gotchas I've experience this week
>if list can't be inferred in a Linq query then it won't compile for lists. however, if it can be inferred it will work, since queries work on both IQueryable objects and also a few edge cases built into the language (lists included)
>commas missing from a tuple declaration over multiple lines simply cause the tuple to reset. for example:
("thing",
"other"
"stuff",
"...")

is equivalent to
("stuff", "...") 

>tuples as args evaluate before the function call in subsequent expressions, unless there is no space in between
therefore
doSomething ()
is not the same as
doSomething()
, since piping the first would pipe in the () but piping the second would pipe in the result of doSomething()
>putting an infix operator at the beginning of a line is not allowed.
>there is no clear rule about when triple quoted strings remove significant whitespace (but it happens about 30% of the time)
>exceptions raised indirectly by functions like failWith cannot be returned in certain situations where exceptions raised manually are allowed
>when declaring arrays the compiler warns that the expressions may be out of place if they're not indented /into/ the array, but the same does not apply to lists or structs:
let x = [|
1; // warning, should move past the " [|"
2
|]
// but not
let x = [
1;
2
]
// or
let x = {
a = b;
c = d
}
>>
>>51385383
muh BDFL
muh pep 8
>>
I fucking wish Memedows had valgrind.
>>
>>51385383
thanks, I appreciate the insight. my prof is strict about it but it seems a little too much and he's old
>>
When reading data separated by newlines, would it be stupid or inefficient to jump around with fseek and scan for the number of characters before it hits a newline and then mallocing an exact fit or should i just do something like buffer[1000] and hope i never run out of space?
>>
>>51381637
>If programming languages were religions
>If
they are religions

>>51381824
>actual syntax
dropped, I'll make my own syntax when I need it for the problem thank you very much
>>
File: 1446944462618.jpg (47 KB, 600x450) Image search: [Google]
1446944462618.jpg
47 KB, 600x450
>>51385252
I first tried java, then I tried c, I failed miserably at learning both, python was the first language I had success with, Haskell the second. I mainly write Haskell now.
>>
>>51385252
>>51385598
Also, I wouldn't say that Python helped me much with Haskell as I never used the functional features of the language, and abused globals quite a lot.
>>
>>51385479
It's probably fine in terms of performance. File streams are typically buffered, so when you fseek backwards to read the data, libc is likely just decrementing a pointer/index internally rather than going to the OS.

That said, it's probably simpler to just realloc your buffer whenever it fills up.
>>
>>51385479
What do you expect the data to be?
Average line length?
Is refusing pathological input acceptable?

Let the data inform your implementation choice, then you measure, and then you modify or adjust your algorithms.
>>
>>51385625
python is actively hostile to functional programming, I'd rather write FP in C++ than python

python is so fucking bad, but then, it is a perl upgrade so
>>
>>51384036
The cycle finished before you looked at the console.
>>
Why are programmers so fucking annoying?
>>
>>51385755
because they're better than you
>>
>>51385332
index should only be used to access a specific element or for slicing. otherwise, you have iterators, map(), itertools, ...
>>
make a blind prediction for me, what kind of job am i getting after graduating with a cs degree
>>
>>51385801
Java brodown
>>
>>51385801
if you don't lower your standards, an unpaid internship to a company that's a 3 hour drive away, both ways.
if you actually want to make money to start paying off your loans, mcdonalds
>>
>>51385810
>unpaid internship

What shithole do you live in where this is a thing?
>>
>>51385810

>if you want to pay off loans, mcdonalds

lol wut
>>
I have a question about an app I'm working on. Basically if a user is a guest and applies for x job, the recruiter account within the app doesn't get a notification. But if the user makes an account and then applies, the recruiter gets a notification. How do I get the notification to work when a guest applies? I know it's pretty vague but a step in the right direction would be helpful.
>>
>>51385888
you should look up functions and code reuse
they're really helpful
>>
>>51385921

i didnt start it from scratch im helping some people out. It looks they did use some type of template or software that did all the tough stuff for you. I guess they forgot to make it send a notification from a guest?
>>
>>51384172
>#!/usr/bin/python3
disgusting
>>
>>51384152
Definitely C.
>>
>reading through k&r
>word count program
>copy code to the letter
>compile and run
>the word count of "Hello world": 1360415665
the fuck?
>>
>>51385089
trying too hard.
>>
>>51386043
either you fucked up printf formatting or there's a memory issue
>>
>>51386043
>>51386108
if the program gives non-deterministic results it's almost always the latter
>>
>>51386043
#include <stdio.h>

#define IN 1
#define OUT 0

main()
{
int c, nl, nw, nc, state;

state = OUT;
nl = nw = nc = 0;
while ((c = getchar()) != EOF) {
++nc;
if (c == '\n')
++nl;
if (c == ' ' || c == '\n' || c == '\t')
state = OUT;
else if (state == OUT) {
state = IN;
++nw;
}
}

printf("%d %d %d\n", nl, nw, nc);
}

werks for me

You must have made an error in copying it.
>>
>>51382189
Just learn C.
>>
What in the fuck is going on? Every base 64 decoder complains the "leaf_input" is not valid.

curl "ct.googleapis.com/aviator/ct/v1/get-entries?start=11&end=11" > cert.b64
>>
File: ylfz2.png (48 KB, 1463x287) Image search: [Google]
ylfz2.png
48 KB, 1463x287
>>51386150
>every
>>
>>51386150
probably because cert.b64 isn't expecting JSON.
>>
>>51384017
If whitespace is syntax in your language, hang yourself
>>
>>51386272
whitespace is syntax in every language
>>
File: sc738.png (28 KB, 1097x295) Image search: [Google]
sc738.png
28 KB, 1097x295
>>51386150
to add another opinion to >>51386238,
use jq, which is a commandline json parser/transformer:
curl -s "ct.googleapis.com/aviator/ct/v1/get-entries?start=11&end=11" | jq -r .entries[0].leaf_input | base64 --decode
>>
>>51386043
>copy code to the letter
Nope
>>
File: ykc9n.png (91 KB, 1074x919) Image search: [Google]
ykc9n.png
91 KB, 1074x919
trying to make some sort of 'trending' thing for 4chan using the API
running into a problem of filtering out boring words
excluding the top 2000 words (according to some source), seen on the rightmost console window yields a better but still ultimately shit result

anyone have any ideas as to how I should filter them?
source is on sjwhub if you're so inclined: zebracanevra/4chan-trends-data
>>
>>51386843
One thing I don't usually see done is chaining the uninteresting words. Sure, "the" is going to be common, but 'the' what?

I don't know what these sort of things usually exclude but if you're just fucking around, I'd take some poet's works and do some word-searching on them. Poets are masters of economy of expression so most words wouldn't be wasted. Any overlap in frequency between poems and normal text is surely to indicate words with little meaning.
>>
>>51386880
chaining would be extremely good, but alas I have no idea how to code that
there are definitely algorithms that I should use to get the stems of words, like bombing -> bomb
>Any overlap in frequency between poems and normal text is surely to indicate words with little meaning.
that's a good idea, I'll see if I can find some plain-text archives of poems.
>if you're just fucking around
I plan to make it get the top words (or chains, tbd) every 5 minutes across all 4chan boards, then publish it in a github repository.
Any service (I will make one myself) can then take that data and draw graphs from it.
I thought of this after the recent France attacks - it'd be cool to see how the post traffic increases and contents of those posts when events like that occur
>>
>>51386933
>chaining would be extremely good, but alas I have no idea how to code that
'markov chain' is the term of interest, you're basically forming a tree with linked words and then assigning them weights based on followup frequency
>>
Can someone explain this whole shit for me?
It's a project from automate the boring stuff.
Multiclipboard from chapter 8. Python btw.

if len(sys.argv) == 3 and sys.argv[1].lower() == 'save':
mcbShelf[sys.argv[2]] = pyperclip.paste()
>>
>>51387077
what is there to explain?
if the first arg to the program is save, it pastes the current text in the clipboard into mcbShelf, using the second arg as a key
>>
>>51387133
So len(sys.argv) is to check the length of arguments right and if there is 3 it will save what it is? Otherwise I don't know.
>>
File: k8ic5.png (4 KB, 122x316) Image search: [Google]
k8ic5.png
4 KB, 122x316
>>51386966
it's almost legible!

>>51387159
sys.argv is an array of args
e.g.
argv[0] = name of script.py
argv[1] = save
argv[2] = foo

thus, len(sys.argv) is 3
sys.argv[1] is save,
so it gets the value of the clipboard, and copies it into a dict named mcbShelf, using foo as a key.
I don't know what mcbShelf represents, so I can't help you further.
>>
>>51387159
If there are 3 command line arguments, and the first command line argument converted to lowercase is "save", then it puts the value of pyperclip.paste() into mcbShelf's position denoted by the second command line argument.

mcbShelf and pyperclip are not standard Python keywords, and I don't care enough to Google what they are, so can't tell exactly what they do.
>>
Thanks for clearing up about the args, wasn't really explained too indepth.
>>
File: 1334323104542_0.png (402 KB, 937x2862) Image search: [Google]
1334323104542_0.png
402 KB, 937x2862
>>51381637
>>
How to figure out the algorithms from assembly code alone?
>>
>>51387711
same way you figure out algorithms from anything else
>>
>>51387711
the same way you'd figure out algorithms from high level language's code, only with more effort
>>
>>51387731
>>51387733
my post wasn't open source, give me your money
>>
>>51387731
>>51387733
Are there any guides?
>>
>>51387746
lol
>>
File: how-to-hang-yourself.jpg (234 KB, 608x1070) Image search: [Google]
how-to-hang-yourself.jpg
234 KB, 608x1070
>>51387749
here's a guide
>>
>>51387749
beginners.re
>>
>>51387758
not that guy but this infographic is really useful thanks, will tell you if it works
>>
>>51385390
>commas missing from a tuple declaration over multiple lines simply cause the tuple to reset.
Shiiiiit, that should definitely be a compiler error.
>>
>>51387758

awesome thanks
this will come in handy soon
>>
JavaScript question: What's the best/cleanest way to convert this:
{
12: {"Foo": "Bar", "A": "B"},
42: {"Foo": "Baz", "A": "C"},
}

into
[
{"Foo": "Bar", "A": "B"},
{"Foo": "Baz", "A": "C"}
]

?

(Those integer keys aren't meaningful)
>>
>>51387856
>>>/g/wdg
>>
>>51387856
Object.values() IIRC
>>
>>51387874
that's mean
>>51387856
what version of javascript?
in es5, this works fine
var arr = Object.keys(your_object).map(function(key) { return your_object[key] })

in es6 you could use:
var arr = Object.keys(your_object).map(k => your_object[k])

or, if you didn't want to use map or Object.keys:
var arr = []
for(var key in your_object)
arr.push(your_object[key])

>>51387894
js has no Object.values.
>>
how do i git gud at reversing?
i've tried to get into it so many times but i never know where the fuck to start, it just seems so massive and time consuming
>>
>>51387907
turn 360 degrees and walk
>>
>>51387907
It's NP-hard.
>>
>>51387915
fuck i laughed
>>
>>51387907
-> >>51387766
>>
>>51387905
Thanks anon!
>>
Current script to find this thread

"""
Find the /dpt/ thread
"""

import requests

for page in xrange(10):
url = "http://boards.4chan.org/g/"
if page != 0:
url += str(page)+"/"
contents = requests.get(url).content
if "/dpt/" in contents:
print "/dpt/ found at ", url
>>
>>51388222
use json
https://github.com/4chan/4chan-API
>>
>>51381851
>>51381862
>>51381884
>>51383743
Anything can happen.
>>
can someone explain to me about this haskell hype?
>>
>>51388289
meme
>>
>>51388289
I would but I don't want to cause any side effects
>>
How's my tree inversion in Haskell?

data Tree a = Tree a [Tree a]
deriving Show

invert :: Tree a -> Tree a
invert (Tree x []) = Tree x []
invert (Tree x ys) = Tree x (map invert (reverse ys))
>>
>>51388385
slow
>>
>>51388385
All Haskell code has side effects on registers, memory and potentially stack
>>
>>51388406
Would that be because reversing the list of children iterates over the entire list, and map iterates over it again?

Is there some function that combines reverse and map?
>>
>>51388428
that would be because conceptually the language is shit
>>
>>51388428
Because it's Haskell
>>
>>51388445
>>51388447
Very funny. I'm not a Haskell memer, you know, I just want to learn it because it's the biggest meme language right now.
>>
>>51388455
No, it is legitemately slow
>>
>>51387711
Assembly code contains the algorithms :) how else would it compute anything :)
>>
>>51388455
>I'm not a Haskell memer
>want to learn it because it's the biggest meme
/g/ in a nutshell
>>
>>51388461
I'm aware, and I use C when I need performance. I'm learning Haskell because it looks good on a resume and it's sort of fun to write code with it.

>>51388466
So you've never learned a language because it was a "hot" language and thought it would look good to know it?
>>
>>51388479
>because it was a "hot" language
>it would look good
no, I'm not brain damaged
>>
>>51388492
It's brain damaged to pad your resume?
>>
>>51388503
>pad your resume
yes
>>
I need help anons. I'm pretty experienced with programming local apps for Android, but now I want to do something else.

I have this little player with KitKat, hooked up to my tv via hdmi and to router via etherned. I want to write an app for this player, which only purpose would be to receive links to streams from my PC, hooked up to the same router(via some simple webpage, let's say with only one field for link, and "send" button) and open them in VLC.

I have completely no idea where to start. Opening received urls in VLC would be trivial, but how do I send them? How do I listen for them?
>>
>>51388527
if you want padding for your resume go to >>>/g/wdg
this thread is reserved for shouting about which programming langauge is the best (C++)
>>
>>51388541
Why are you quoting the guy that agrees with you? Are you this dumb?
>>
>>51388541
I actually came to this thread to see if my tree/invert implementation was retarded or not. I've done too much web development already and don't want to do any more because I don't want a job in wev development.
>>
>>51388455
>>51388479
lol wut

suit yourself if you want to learn that terrible language. btw haskell only looks good to literal transsexuals
>>
>>51388676
>6 continents
>insects have 3 legs
>america
what the fuck is this bullshit
>>
>>51388676
even though you deleted your thread anon, the error occurs because 'html' is a global variable
move the 'var html = ""; ' to the first line of the quizDisplay function and your error goes away
>>
Hey /g/ is there a reason we shouldn't just rewrite all core system utilities in Go? The safety boost would be huge! Is there any already started project to do this?
>>
>>51388803
We really need more safe spaces in our operating systems
>>
>>51388803
Rewriting code doesn't make it more safe, no matter the language. You'll only introduce more security hazards.
>>
>>51388803
rust did that
>>
>>51384438
>>51384272
>>51384265
https://bitbucket.org/Tetsumi/cdptlib

Daily reminder this benchmark faggot should off himself.
>>
>>51388913
>bitbucket
Didn't click lol.
>>
>>51388921
>hurr durr lol
sjwhub shill
>>
>>51388921
http://neetco.de/CodeArtisan/cdptlib
>>
>>51388984
That's some ugly shit m8.
>>
File: 1418963909734.jpg (62 KB, 1280x720) Image search: [Google]
1418963909734.jpg
62 KB, 1280x720
How would you handle unary operators in a parse tree?
For example the expression to align to a 64 bit boundary:
x & ~63

What would the NOT operator (~) look like in the parse tree?
>>
File: tegaki.png (3 KB, 400x400) Image search: [Google]
tegaki.png
3 KB, 400x400
>>51389065
>>
>>51388803
interface{}
>>
File: 1417929650028.png (3 KB, 400x400) Image search: [Google]
1417929650028.png
3 KB, 400x400
>>51389089
Okay, and what about this situation? would this be correct?
x & ~63 + 5 - 3 * 6
>>
>>51389065
(& x (~ 63))
>>
>>51389187
If & binds tighter than +, sure.
>>
>>51389203
Is there some method of determining operator priority without making a mess of a parser?
>>
>>51389228
Pratt parsing is pretty clean. It even works with mixfix and partial orderings.
>>
>>51389187
Paint has a text option.
>>
>>51389272
That is tegaki, not paint.
>>
>>51389287
Then use paint.
>>
>>51389298
no
>>
Is there any reason I should use this

typedef struct point_t {
double x;
double y;
} point;


over this?

typedef struct {
double x;
double y;
} point;
>>
>>51389325
4chan makes the point_t purple, so it looks way cooler than the 2nd
>>
>>51389325
One works in standard C pre-11 and one doesn't.
>>
>>51389325
Maybe some ancient C can't handle the 2nd.
>>
>>51389313
literally being this much of a nigger
>>
>>51389363
How much?
>>
>there are people itt who use templates for metaprogramming
>>
>>51389382
>there are people ITT who use languages where type level programming exists only in a different syntactic domain
>>
File: nigger.jpg (30 KB, 353x360) Image search: [Google]
nigger.jpg
30 KB, 353x360
>>51389376
this much
>>
Can I write Rust for my arduino? Would it be recommended?
>>
>>51389412
>egyptians
>black
kek
>>
>>51389431
They're still shitskins.
>>
>>51389435
Do you consider every non-white race a shitskin?
>>
>>51389457
>Do you consider...
Only shitskins don't.
>>
>>51389457
If your nipples aren't pink, you aren't white. Sorry.
Thread replies: 255
Thread images: 28

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.