[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: 24
File: 1422385664777_2.jpg (411 KB, 2500x1000) Image search: [Google]
1422385664777_2.jpg
411 KB, 2500x1000
Old /dpt/ at >>51358193

What are you working on?
>>
first for java
>>
First for OcaML
>>
>>51364248
ThirD
>>
I didn't understand programming at all until I started doing things in C.
>>
>>51364273
>second
>>
>>51364263
write a function in java that swaps the values of two integer variables being passed to it
>>
>>51364291
kek
>>
>>51364273
ocaml TOO SLOW
>>
First for Go.
>>
>>51364291
That's what the "Integer" class is for?
>>
File: javadead.png (28 KB, 191x240) Image search: [Google]
javadead.png
28 KB, 191x240
>>51364291
void swap(int a, int b) {
a += b;
b = a - b;
a -= b;
}
>>
>>51364291
D
import std.stdio;

void swap(ref int a, ref int b)
{
int tmp;
a = (tmp = b, b = a, tmp);
}

void main(string[] args)
{
int i = 2, j = 3;

writefln("%d, %d", i, j);

swap(i, j);

writefln("%d, %d", i, j);
}
>>
>>51364372
That doesn't work you idiot. Primitives in java are copied when passed into functions. You have to use the Integer class.
>>
File: problim.png (100 KB, 786x640) Image search: [Google]
problim.png
100 KB, 786x640
how do I do this
>>
>>51364291
PS I don't actually know Java
IPairAble.java
interface IPair<T,U> {
public T getFirst ();
public U getSecond ();
}

MyIntPair.java
public class MyIntPair implement IPair<Integer, Integer> {
private int _first;
private int _second;
public MyIntPair (int first, int second) {
this._first = first;
this._second = second;
}

///@Override
public Integer getFirst () {
return _first;
}

///@Override
public Integer getSecond () {
return _second;
}
}

// IntPairSwapper.java
public class IntPairSwapper {
public MyIntPair swap (IPair<Integer, Integer> input) {
int myFirst = input.getFirst();
int mySecond = input.getSecond();
return new MyIntPair(myFirst, mySecond);
}
}

// IntSwapDriver.java
public class IntSwapDriver {
public static void main (string[] args) {
int x = 4, y = 5;
System.out.println("x = " + x + ", y = " + y);
IntPairSwapper swapper;
MyIntPair pair = new MyIntPair(x, y);
pair = swapper.swap(pair);
x = pair.getFirst();
y = pair.getSecond();
System.out.println("x = " + x + ", y = " + y);
}
}
>>
>>51364291

void swap (ref int a, ref int b)


Oh, wait... :^^^^)
>>
>>51364335
You can change the Integer value by using reflection. This one is a nice example: http://codegolf.stackexchange.com/a/28818
>>
>>51364248
Build system in clojure
>>
>>51364283
I didn't understand C at all until I started programming.
>>
File: Capture3.png (193 KB, 1608x927) Image search: [Google]
Capture3.png
193 KB, 1608x927
Generating a star catalog for the attitude estimation system on the satellite I'm working on.
>>
I went to the grocery store just a moment ago.

I was wondering, how do you think they program the registers to manage multiple-item sales? At the one I go to it's a degenerate sale since "two for four" means "one for two"—they don't actually require you buy two. But I know some other grocery stores do have this requirement.

Do you think the registers simply look down the entire list of items already scanned to look for matches? Do you think they store matchable items in a separate structure for faster searching? Because there's no guarantee the retarded girl at the register (the girl in the other lane is always hotter and smarter) will scan sale items sequentially or the retarded customer will put sale items together on the conveyor.

How would you solve this problem, /dpt/?
>>
>>51364291
public class MyIntegerSwapper
{
class MySwappableIntegerPair
{
private int a;
private int b;

public MySwappableIntegerPair(int inA, int inB)
{
a = inA;
b = inB;
}

public void DoSwap()
{
int temp = a;
a = b;
b = temp;
}
public int GetSwappedIntegerA()
{
return a;
}
public int GetSwappedIntegerB()
{
return b;
}
}

public static void main String []args()
{
int a = 88;
int b = 42;

MyIntegerSwapper integerSwapper = new MyIntegerSwapper();
integerSwapper.MySwappableIntegerPair swappableIntegerPair = new integerSwapper.MySwappableIntegerPair(a, b);
swappableIntegerPair.DoSwap();

a = swappableIntegerPair.GetSwappedIntegerA();
b = swappableIntegerPair.GetSwappedIntegerB();
}
}
>>
>>51364291
C++
void swap(int &x, int &y)
{
int temp = x;
x = y;
y = temp;
}
>>
>>51364419
I'm pretty certain you don't need reflection though. It's been a while since I've used Java and I don't have it installed on my current computer, but Integer behaves sort of like pointers and can be reassigned to different objects, if I recall correctly. I think
void swap( Integer a, Integer b) {
int tmp = a;
b = a;
a = tmp;
return;
}

should work.
>>
>>51364502
It isn't like there are more than a 100 unique items on a list most of the time, so searching through the list doesn't have to optimized that well. I think you're overthinking this.
>>
>>51364514
>not making generic static swapper
>>
>>51364543
This. I literally wrote Bingo game software for a company that found winning cards by iterating over every single number on every single card, every time a new number was called. CPUs are so fast this was instantaneous, up until 250,000 cards, when it starts taking like half a second, which doesn't matter, since the program only had to operate on 1000 cards at a time.
>>
>>51364542
Sorry, but Integers are immutable. You are receiving a copy of the reference inside the function, and as you change that reference, you are changing only inside the function. Outside the function, the reference will stay the same.
>>
>>51364564
>what is job security
I'm literally creating jobs by making code less generic. I'm doing more for the economy than you.
>>
>>51364404
10/10 would hire
>>
>>51364581
What the fucking fuck is the point of the Integer class then? I thought the whole point was for there to be pointer functionality for integers. Do you seriously have to write a wrapper for that simple problem?
>>
>>51364404
That's disgusting
>>
>>51364677
The Integer class exists because Java isn't actually "OO" and because of their naive implementation of generics
>>
>>51364677
In Java, primitives and classes have different behaviour. You can't use a primitive in a generic for instance. So that's why they are boxed.
>>
>>51364401
halp
>>
how do I git gud at organizing code?

I feel like my code gets ugly and messy really fast once it's bigger than just a simple script or something

is this just something that comes with experience?
>>
>>51364744
Design patterns
>>
>>51364736
idk man draw pictures and plan it out or somethin how the fuck would i know i don't even code
>>
>>51364751
Literally the memiest answer. Thanks /memept/, you never disappoint.
>>
>>51364744
some languages have so little support for gradual abstraction that you just end up writing trash, can't be helped
>>
>>51364760
i know what im supposed to do, i just don't know how to do it
>>
>>51364764
Then what's the solution, smart guy
>>
>>51364791
Compression-oriented programming. Do everything you can to reduce your code to the smallest possible (semantic) size. This makes it easier to fit in your head, and therefore harder to misunderstand. See: http://mollyrocket.com/casey/stream_0019.html
>>
File: fgsfd.jpg (32 KB, 335x352) Image search: [Google]
fgsfd.jpg
32 KB, 335x352
anyone here have a job programming?
>what do you do?
>what language(s) do you use?
>>
>>51364788
Write a more detailed description of the problem. If you need to say, implement RSA, rather than just sitting down and writin' some code, plan ahead.

For example for RSA you'll need:
1. Operators and data formats for modulo arithmetic
2. Prime number generation
3. Key generation
4. Encryption
5. Decryption
6. A way to pass data from one thing to another.
>>
>>51364818
That sounds like something that could work up to a point, but once you go big it still becomes a mess having classes with too many private variables and methods and 25 different constructors.
>>
>>51364838
I had a internship on a Security team and did some scripting with Powershell
>>
>>51364859

Powershell is pretty good. Much better than fucking batch, that's for sure.
>>
>>51364851
Well, the solution is to not use private variables or constructors.

You want to write the bare minimum amount of code, that's ideally highly reusable. OOP doesn't let you do that.
>>
>>51364394
everything is copied when passed into functions idiot.
>>
>>51364401
I liked the problem, so I solved it using another language and another paradigm just because.

let AccountAdmin() =
let rec balance x =
let command = System.Console.ReadLine().ToLower().Split([|':'|])
match command with
|[|"deposit";value|] -> match System.Int32.TryParse(value) with (true, v) -> balance (x+v) |(false,_) -> printfn "%A" "Invalid command"; balance x
|[|"withdraw";value|] -> match System.Int32.TryParse(value) with (true, v) -> balance (x-v) |(false,_) -> printfn "%A" "Invalid command"; balance x
|[|"show"|] -> printfn "Balance is %A" x ; balance x
|[|"exit"|] -> ()
|_ -> printfn "%A" "Invalid command"; balance x
balance 0

AccountAdmin()
>>
>>51364838
>vidya dev
>c++
>>
Can you idiots stop posting your swaps in various languages? It's not dick waving contest and anyone can do it, it's just shitting on Java due to how it represents numbers.
>>
>>51364873
It is, and the IDE that comes with it is also fantastic. Plus I can also use Unix commands on it. God bless Powershell
>>
>>51364850
i need to be able to interpret four user commands
1. show: show the account balance
2. exit: exit the program
3. deposit: add a value to the account balance
4. withdraw: subtract a value from the account balance

i don't know the syntax to do any of this
>>
>>51364907
>>
>>51364838
>engineer
>racket+C
>>
>>51364907
>it's just shitting on Java due to how it represents numbers
how this is related to java's inability to pass by reference

and here in C++

void swap(int &a, int &b){
int temp = a;
a = b;
b = temp;
}
>>
>>51364897
is it really THAT bad anon
>>
>>51364945
>racket
That's a new one.
>>
>>51364838
I work in the defense industry. I write java shit, and begrudgingly, I sometimes work with C++. My job makes me want to kill myself. I want to leave and do something in the commercial sector.
>>
>>51364950
You're just swapping the addresses though m80, poor form
>>
>>51364838
>IT at gender reassignment clinic
>rust
>>
>>51364976
Can you get me a job if I claim to be a tranny?
>>
>>51364971
i can't think of a situation where it would matter if they're just integers
>>
>>51364971
That's how you pass by reference in C++
>>
>>51364955
it is pretty fun. I like C++
>>
>>51364971
Not really. It's swapping the contents, but using the original addresses for the inside variables.
>>
>>51364966
not really
>>
#define swap_int(x, y) do{int temp = x; x = y; y = temp; } while(0)


why java is so shit
>>
> It’s easy to fall into the habit of thinking of abstract things like whether code is “clean” or whether it is “elegant” or god forbid “exception safe” or whether it “obeys RAII” and all these other things you may have heard about or believe in. But in the end you have to remember that all of them are just concepts and guidelines that someone made up on the way to achieving a lower total cost for code.
How true is this, /dpt/?
>>
>>51365084
>not using the C preprocessor on java files
lel!
>>
What CS/programming book should I ask for for Christmas? I would ask for TAOCP but it's too rich for my parents' blood. I already have Godel, Escher, Bach.
>>
>>51365145
I would use C preprocessor for actual programming too! it is probably a better language than Java is
>>
>>51365152
>paying for overpriced CS books
>trying to learn from hard copy tutorials
>>
>>51365183
>not just copy pasting working code from stackoverflow
Top kek.
>>
>>51365152
i tried to teach myself from books when i was in highschool too. not worth it, i learned nothing. just don't be poor and take classes
>>
Trying to build a countdown clock in Javascript, but there's fuck-all in the way of quality tutorials on timers. I want to be able to set a duration in minutes, display that on screen, and then show that countdown second by second on-screen, until it triggers a function upon reaching 00:00
>>
>>51364248
who is this semen demon
>>
>>51365152
since HtDP2e and SICP are free, ask your parents for a dragon dildo
>>
>>51365084
>
do ... while(0)

Fuck is wrong with you? Just use {}. And auto instead of int so you can have a completely generic swap.

#define swap(x, y) { auto temp = x; x = y; y = temp; }
>>
>>51365229
at some point, even tutorials assume you know enough to do things on your own

what you describe isn't a tutorial but just working code doing what you want

kill yourself
>javascript
LITERALLY
>>
>>51365093
Completely. Time saved fixing broken/unstable shit is less money spent.
>>
>>51365243
https://stackoverflow.com/questions/923822/whats-the-use-of-do-while0-when-we-define-a-macro
>>
>>51364886
>another paradigm
uh... bro that's still imperative
>>
>>51365210
Taking classes is literally never worth it. Either they go at an ultra slow pace or the teacher skips over 99% and you're left self-studying anyway.

If you really want the degree, there's easier ways to do it. My local university offers "online classes" that count toward your first two years of a CS degree. You have to write physical exams to prove you actually know your shit, and then attend normal classes for year 3 and year 4, but the first two years can be done on your own time, at your leisure. I did them both in 6 months and officially enrolled in third year classes when I was 19, and I got my Bacehlor's in CS when I turned 20 last spring.
>>
>>51365243
>auto
>C
well actually there is auto, but it is not like in c++11

>wrong expansion in a few cases
>>
>>51365254
>being this protective of your language street cred

come at me nerd im ripped
>>
>>51365243
>C has an auto keyword
Huh
>>
>>51365327
local storage can be automatic or static
>>
>>51365327
it does actually
>>
>>51365243
>c
>auto meaning that
Also there's literally no reason to fuck up code with #define, when you can simply write a short function.
>>
>>51365229
Here anon, let me help you out:

1st: query user for time input
2nd: store that input in a variable like "duration"
3rd: query system for current time
4th: store that as your "start time"
5th: repeatedly query system for new time
6th: subtract new time from old time to figure out how much time has passed
7th: subtract time passed from "duration"
8th: when duration == 0, call function
>>
>>51365254
Why does everyone hate Javascript?
>>
>>51365271
>putting semicolons after macros
Stop making shit look like something it's not. Macros should be visibly macros, not pretend to be functions.

The only acceptable exception to that is shit like:
#ifdef MSVC
#define fileno _fileno
#endif
>>
>>51364248
Repeating fae last thread because there was a lot of interest.

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 'say-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))
>>
>>51365296
It's not that functional, but it's still at least as much as declarative.
>>
>>51365327
Auto if I recall is default behavior. Values of variables are lost when the program leaves scope. It's the opposite of static.
>>
>>51365343
it ensures inlining. it is closest thing to generics you can get in C, unless you are into void pointers
>>
>>51365358
its a meme
>>
>>51365379
Ah, I see
>>
>>51365388
Unless you're writing for an antique compiler, shouldn't the compiler be smarter than you about whether it is better to inline functions?
>>
>>51365379
ACHKSCHTUALLY *snorts*, according to the C11 standard *snorts*, in {OBSCURE, UNLIKELY AND IRRELEVANT SITUATION}, variables will not default to auto storage. If you want to ensure complete portability, {DICK-MEASURING CONTEST ENTRY PIECE OF CODE}. *snorts* *giggles*
>>
>>51365403
Well, it ensures it and that is a good thing. isn't it?

and your macro can expand something like a for_each loop, not my thing though. how are you gonna do it with a function?
>>
>>51365359
>stop using abstraction
>>
>>51365458
>{DICK-MEASURING CONTEST ENTRY PIECE OF CODE}
I'm kind of curious what such a piece of code looks like. Do you know of a situation when that wouldn't happen?

>>51365463
Using macros to implement new syntax? Get out of here! Macros are to be used with the sole intent of making C hell to read! If you aren't using macros to make C read like ALGOL then you aren't living correctly!
>>
>>51365477
>macros are abstraction
Kill yourself.
>>
>>51365631
Macros are abstraction. A for loop is just a macro of a while loop. A while loop is a macro of conditional branches.
>>
File: disgust.jpg (28 KB, 524x336) Image search: [Google]
disgust.jpg
28 KB, 524x336
> if err != nil {
> panic(err)
> }
>>
>>51365658
>syntactic sugar is macros
Right, I'm done arguing with you.
>>
File: screen.webm (309 KB, 1024x768) Image search: [Google]
screen.webm
309 KB, 1024x768
I wasn't satisfied with any of the existing tools for setting a background image in X11, since I tend to prefer tools that do a single job. I decided to make my own with Xlib and Imlib2.

There's still some memory leaks; the documentation for both libraries is pretty bad and doesn't specify cleanup functions.
>>
>>51364291
private void swap(int[] a)
{
if(a == null || a.length < 2)
return;
int i = a[0];
a[0] = a[1];
a[1] = i;
}

Did this shit all the time when I needed to modify strings being sent to methods. Bit of a hack but it works.
>>
Can anyone here that actually works with Java as their main job tell me this:

Do you even use CRC Cards for your projects, ever?

Do you even use UML Diagrams for your projects, ever?

Is Object Oriented Programming actually fucking used at all?
>>
>>51365829
>Do you even use CRC Cards for your projects, ever?

Not even know what it is, and therefore must not be relevant.

>Do you even use UML Diagrams for your projects, ever?

No.

>Is Object Oriented Programming actually fucking used at all?

Yes, quite heavily.
>>
>>51365631
Macros are a means of abstraction. Making function-like macro invocations behave as function calls is an additional layer of abstraction.
>>
>>51364744
As Bjarne said "keep simple things simple." Keep functions short and to the point. Also Bjarne "express ideas directly in code". If you mean a foot or an inch as a parameter, then use a foot or inch type--NOT a double. Well-named variables and functions can eliminate the need for the majority of comments. Make good use of encapsulation and class design. Understand what you're custom types are and should do, then focus specifically on having them do just that.
>>
>>51364897
having been there, you have my pity anon.
>>
>>51365761
man xsetroot
>>
File: 1439154685598.jpg (39 KB, 475x357) Image search: [Google]
1439154685598.jpg
39 KB, 475x357
I've been teaching myself Python.

Is it bad form to use the text editor in IDLE? I like that I can run my program by pressing f5.
>>
>>51365995
Perhaps you should read the manual for xsetroot. You'd discover that it only supports boolean bitmap images as described in bitmap(1).
>>
My Java project that's worth 30% is due in 8 hours, I've nothing done, can you do it for me /g/?
>>
>>51366091
What's the assignment?
>>
>>51365943
>Also Bjarne "express ideas directly in code". If you mean a foot or an inch as a parameter, then use a foot or inch type

class Inch;

class Foot
{
public:
Inch* ToInches() { return new Inch[12]; };
};

class Inch :public Foot
{
public:
Foot* ToFeet() { return new Foot[1/12]; };
}

void Func (Foot[] LengthFeet, Inch[] LengthInches)
{
int length = 12 * (sizeof(LengthFeet)/sizeof(Foot)) + (sizeof(LengthInches)/sizeof(Inch));
// do the calculation
}


Thank you Bjarne! It's all so clear now.
>>
>>51366089
So dither your color image into a bitmap. What's the problem here?
>>
>>51366176
But I don't want a dithered bitmap as my background, I want a color image.
>>
>>51366063
Not bad form. At least you aren't using Notepad or something.

If you ever want more functionality in your editor, try out PyCharm.
>>
>>51366128
"Your local charity shop has asked you to develop a software system to manage its intake and the sale/hire of the items it stocks. The system will be used by employees (shop assistants and managers) of the store.

An employee should initially be presented with a login message. The employee logs in as either a shop assistant or a manager.

After logging in, a shop assistant should be able to initiate a transaction by entering a list of codes for items and associated quantities. The system should check the stock to see if each item is in stock. If it is, then appropriate details with respect to the item and the quantity should be output to the screen. The total cost of the transaction should also be output. An option to purchase/hire items should also be presented. If the customer agrees to continue with the transaction, then an appropriate receipt including date and time of the transaction, item code/name, quantity, unit cost and total cost should be issued. The stock should be updated to reflect the transaction. The system should keep track of the items and quantities involved in each transaction. Additional charges should apply if items hired are not returned by the due date.
A manager in the store can retrieve the following information from the system:
• A summary of all items currently in stock
• Details related to specific items in stock
• A summary of all sales/hires over a chosen period of time (days/weeks/months/years)


The system should keep track of stock, sales and employee details. This information should be stored in external csv files. The names of these files should be supplied when the application is run.

A text based interface for the system is required."

Has to be in an Object Oriented Design. Other /g/uys said it's a 1 hour project, doesn't seem like it is.
>>
>>51366063
Do you have all the features you need? Then use IDLE? Is IDLE missing things you want? Don't use IDLE.
>>
>>51366091
The thing that I find nice in my college is that they don't teach languages, but concepts. If you want to you can do the assignment in C#, Java, C++, or even Smalltalk. As long you are using OOP concepts they don't care.
>>
>>51366146
versus C

typedef foot unsigned int;
typedef inches unsigned int;

unsigned int function(foot feet_length, inch inch_length) {
//calculate
}


>C++ tards really think their shitty language is better than this
C++ should have stayed a bunch of preprocessor macros
>>
>>51366211
You might find that you like the dithered image better.
>>
>>51366292
Type should be first, then alias.
>>
>>51366292
> implying you can't typedef in C++
>>
>>51366324
And function should accept something of type inches, not inch

But it's late and I'm tired, so cut me some slack my brother in C arms.
>>
>>51366146
This is a silly design. Why not just have a length class that has methods for getting the length in inches or feet?
>>
>>51366357
because you can't represent arbitrary numbers with infinite precision?
>>
>>51366379
>infinite precision for fucking inches and feet
-.- u ppl rly r tards...
>>
>>51366420
Everyone here is a retard
Except me of course
>>
File: 1447040980062.jpg (840 KB, 1921x1080) Image search: [Google]
1447040980062.jpg
840 KB, 1921x1080
Dear /dpt/,

I have this class called FcItem that contains information about a file/folder (like its name)
I'm storing these classes inside a List that I'm accessing like an array

Now I have the problem that I need to also be able to quickly access them by name
...without storing the name string twice inside the FcItem class and inside a Dictionary as key
...in C#

Any ideas how I could do that?
>>
>>51366420
class TenthOfInch :public Inch
{
public:
Inch* ToInch { return new Inch[1/10]; };
}

class HundredthOfInch :public TenthOfInch
{
public:
TenthOfInch* ToTenthOfInch { return new TenthOfInch[1/10]; };
}


... and so on.
>>
>>51366604
LINQ the fuck out of it.
>>
>>51366692
>LINQ
>quickly
>>
>>51365093
much of the time this kind of thinking is even damaging because they are based on decade+ old tooling
>>
>>51365238
this
>>
>>51366604
so if I understand you right, all you want to do is to not duplicate the string?
probably your only option is to make a class which wraps the string, and then use that as the key, and also a member of your class (so they are shared)
likely not efficient, but will save memory if you have strings longer than ~10 characters, I presume

>>51366712
linq is not slow
it really depends how you're using it
>>
>>51366712
Don't use always the query, it has even a ToDictionary method if you want to use it.
>>
What is OOP, /dpt/? If I write a function that takes a struct as an argument, is that OOP? What if it takes a struct and returns the same struct with the values modified? Are we OOPing now?
>>
>>51366604
>>51366747
or, getting into even more micro-optimisations, use String.Intern
then the dictionary's key and the class' member can use the same memory, i.e. no duplication
>>
>>51364526
>using a temp variable
>>
>>51366777
>I don’t consider object-oriented programming to have anything to do with whether or not there may or may not be things that look like objects existing in the code base. To me, that would be a very silly way to use that word, because that would imply that, for example, you were doing “functional programming” simply because your program happens to have some functions in it that don’t have side effects.

>Rather, when I say “object-oriented programming”, I mean literally that: you have oriented your programming around the objects. The objects are the important thing to you, and you are thinking in terms of the objects. It is the practice of thinking that objects are important (or that they’re even worth thinking about at all) that is wrong, and is best avoided. It is not objects themselves that are bad, because objects are really nothing more than some functions that happen to be strongly associated with some data. If you happen to end up with that in your programs, there’s nothing wrong with that. Sometimes some functions are very closely related to the data with which they operate, and that’s fine.
>>
>>51366747
Yes
Putting the string into a container class is a good idea
I will either do that or store them inside a StringBuilder / char[] tomorrow

>>51366778
Interesting
I didn't know about String.Intern yet
>>
>>51366899
..though on second thought string.Intern is probably the easiest to implement
>>
>>51366777
Your design is based around self-contained objects that communicate to one another by passing messages to one another. Some other things that objects do is inherit the functionality/data of a base class allowing you to reuse and extend objects into more specialized objects.
>>
>>51366785
How could this be done without one?
>>
>>51366994
>he doesn't know how to xor swap
>>
>>51366994
in a stupid way
>>
>>51367006
>>51366785
xor swap is slower than using a temp variable.
>>
Got a job interview tomorrow as a qa analyist for a fortune 10 company. Any advice?
>>
>>51366975
OK so let's say I had a main() which creates a few structs, and then I have functions which take those same structs as arguments. Now, if one of those functions takes two different types of structs as arguments and then does some manipulation between them, is that OOP, with the function doing the act of 'passing messages'?
>>
>>51366994
Like >>51367006, if you value /g/-credit over performance.
>>
>>51367041
Performance wasn't the question. He just asked if it was possible to do it, which it is. XOR swap is useful in a few circumstances so it's worth knowing about.
>>
>>51366994
In a way that fucks up if the combined value > MAX_INT
>>
File: 1447458587499.jpg (104 KB, 1000x1300) Image search: [Google]
1447458587499.jpg
104 KB, 1000x1300
>>51367006
In C# XOR swap is apparently slower than using a temp variable
>>
>>51367071
Of course it is. Usually the temp variable can be optimized away anyway. XOR swap is useful to know in a few situations, but it's a novelty, not a serious tool, and certainly not worth implementing unless you're seriously register or RAM constrained.
>>
What's better, C or C++?
>>
>>51367064
what circumstances ?
>>
>>51367122
C++. You can write 99% compliant C in C++ if you want, and then when you want templates or function overloading or operator overloading, you have them.
>>
>>51367006
xor swap needs a temp variable too.
No architecture I know of has mem to mem ALU operations.
>>
>>51364283
same here.
>>
>>51367165
VAX
>>
>>51366778
String.Intern doesn't look like it's actually working
I'm getting lower memory usage without it
>>
>>51367165
>xor swap needs a temp variable too
a = a^b
b = a^b
a = a^b

Find the temp variable
>>
>>51367285
don't hurt yourself kid
>>
>>51367285
That's not what he meant
>>
>>51367047
No. Objects in OOP are self-contained meaning that the object functions exist within the object and all the data members are hidden from direct access outside of the object. Structs in C are designed not to be hidden as any function that has access to the struct can get direct access to the internal data members. Another thing in C is that structs cannot be inherited like what happens in any OO language.
>>
>>51367315
Then what did he mean?
>>
>>51367356
the assembly output
>>
>>51367285
k tard
>>
>>51367285
You are the temporary variable
>>
>>51367372
movl -4(ebp), eax
movl -8(ebp), ebx
xorl ebx, eax
xorl eax, ebx
xorl ebx, eax
movl eax, -4(ebp)
movl ebx, -8(ebp)


Find the temp variable
>>
>>51367165
>No architecture I know of has mem to mem ALU operations.
Mine does.
>>
>>51367306
>>51367433
>>51367451
Nice name calling, fucktards

Where's the temp variable in >>51367455
>>
>>51367502
>movl -4(ebp), eax
>movl -8(ebp), ebx
>xorl ebx, eax
>xorl eax, ebx
>xorl ebx, eax
>movl eax, -4(ebp)
>movl ebx, -8(ebp)

lel, xor operations are totally useless here.

movl -4(ebp), eax
movl -8(ebp), ebx
movl ebx, -4(ebp)
movl eax, -8(ebp)
>>
Sorta almost done with game jam game. It's mostly playable but a little buggy. Also I found quite a few bugs in the library I was using (and the libraries it uses internally) which was really frustrating when I'm on a time limit and things break on me that should work.
>>
>>51367165
You typically load parameters in registers eitherway, senpai. It's like >>51367455 says.
>>
>>51367047
No. In OOP, the object is supposed to determine how it reacts to a message. OOP in C looks something like this:

struct my_object_operations;

struct my_object {
int data;
struct my_object_operations *op;
};

struct my_object_operations {
int (*foo)(struct my_object*);
int (*bar)(struct my_object*);
};

int baz(struct my_object *obj)
{
return obj->op->foo(obj) + obj->op->bar(obj);
}
>>
>>51367455
eax and ebx ? Here a a temp. var. less version which is not possible on x86.

xorl -8(ebp), -4(ebp)
xorl -4(ebp), -8(ebp)
xorl -8(ebp), -4(ebp)
>>
>>51367455
eax and ebx
>>
>>51367543
I could accept that I was wrong, or I could insult you for correcting me.

You fucking kike nigger jew, kill yourself.
>>
>>51364316
>ocaml
>too slow
Wew!
>>
>>51367579
>You typically load parameters in registers eitherway, senpai.
That's what I meant - you need temporary variables to do the operations.
>>
>>51367585
>he doesn't know the difference between a variable and a register!
>>
>>51367618
>you don't need a temporary variable
>that's what I meant, you need a temporary variable!
Cluck.
>>
File: BALT0No.webm (2 MB, 406x720) Image search: [Google]
BALT0No.webm
2 MB, 406x720
Ask your beloved programming literate anything.

>>51367047
No, that's what i call data type because it's like an abstract data type minus the said abstraction.

>>51364248
>What are you working on?
Guess what
>>
>>51367638
>you don't need a temporary variable
Except you do as demonstrated here: >>51367455
>>
>>51367627
A variable is a concept, a register is a specific storage location on the cpu.
A variable can be stored in a register, or it can be stored in ram, rom, etc.
>>
>Leaving my job to go back to school
>No projects to work on
>No daily challenges to engage with
>No real-world experiences, instead back to theory bullshit
How do I keep myself up to date and occupied, /g/
I'm scared
>>
>>51367662
>literally no temporary variable
>therefore there's a temporary variable
>>
>>51367662
A temporary varible normally refers to a variable with auto storage and local scope. asm makes no guarantees about storage or scope. Registers are a concept that exists in asm, not C (the language you're presumably referring to). Registers are not temproary variables.

q.e.d.
>>
>>51367696
>>literally no temporary variable
Two temporary variables are used - eax and ebx.
>>
>>51367688
Hence why there is no temporary variable unlike your claim.
>>
File: 161017757_44042348.jpg (67 KB, 590x632) Image search: [Google]
161017757_44042348.jpg
67 KB, 590x632
>>51367703
>c has a specific keyword for registers
>c has no concept of registers
please refrain from posting, it's painful.
>>
>>51367690
Your problem is that you wanted to go to codemonkey school but instead you registered for science class.
>>
File: 9e75WHU.png (271 KB, 1366x3361) Image search: [Google]
9e75WHU.png
271 KB, 1366x3361
>>51364248
Preparing a demo / release for my chatbot project that's been in development hell for years.

That and slowly rolling out and polishing up a browser-based management system born out of a handful of autistic productivity scripts I developed over this past year.
>>
>>51367725
"register" is a hint to make the compiler more likely to keep a variable in a register and not in memory.

Note the wording: "keep the variable IN a register".
>>
>>51367709
Yes there is.
This: >>51367585
would truly be a swap without any temporaries, but such addressing modes are not available on most architectures.
>>
>>51367707
>>51367725
Found the inbred.
>>
>>51367661
Why do you consider yourself beloved?
>>
>>51367725
Please refrain from posting on G its pathetic that you masquerade as someone who gives a shit about technology when in reality you're really just posting bullshit about anime girls. Stop masquerading it go back to /a/
>>
>>51367742
Are you retarded or just pretending?
>>
File: 1332719268857.jpg (2 KB, 126x126) Image search: [Google]
1332719268857.jpg
2 KB, 126x126
>>51367727
>I take compsci! I am big stem man! Me smart!
Compsci classes are a joke if you already have production experience.
>>
>>51367771
Is that why you're crying about it on /g/, rajeesh?
>>
>>51367725
Just because C has a keyword called "register" doesn't mean you can specify you want something to be stored in a register, my dear autistic anime posting cancerous fuck. It's just a tip to your compiler.
>>
>>51367725
C has a specific keyword called "volatile" so it must deal with spontaneously evaporating liquids.
>>
File: fedoratheist-nightmare.jpg (81 KB, 462x720) Image search: [Google]
fedoratheist-nightmare.jpg
81 KB, 462x720
>>51367785
>*tips compiler*
>>
File: tGKIDM8.jpg (115 KB, 650x650) Image search: [Google]
tGKIDM8.jpg
115 KB, 650x650
>>51367741
>>51367744
>>51367766
>>51367785
>>51367797
You just don't know what to say anymore.... that level of butt-hurt is delicious.
>>
>>51367703
What 'auto storage' actually is in practice is implementation defined in C.
>>
>>51367771
CompSci doesn't prepare you for the industry, except perhaps code monkey jobs you could imagine people doing in shops back in 2002.

It arguably prepares you reasonably well for CS academia though, which in turn prepares you for a career of research. Or a Google technical interview.
>>
@51367817
Here's your reply
>>
>>51366146
Bjarne wouldn't do it in C friend.
>>
it's not pretty, but it's a continuation of something I was working on yesterday and posted in a previous /dpt/
// menu
int slctn;
cout << "1. Translate an English word to Spanish." << endl;
cout << "2. Translate a Spanish word to English." << endl;
cin >> slctn;

if (slctn == 1){
// translate a word from english to spanish

string input_word1;
cout << "Input an English word to be translated: ";
cin >> input_word1;
count = 0;
while (count < ARRAY_SIZE && input_word1 != english[count])
count++;
cout << spanish[count] << endl;
}

// translate a word from spanish to english

else{
if (slctn == 2){
string input_word2;
cout << "Input a Spanish word to be translated: ";
cin >> input_word2;
count = 0;
while (count < ARRAY_SIZE && input_word2 != spanish[count])
count++;
cout << english[count] << endl;
}
else{
cout << "Invalid choice." << endl;
}
}
continue;
}
>>
>>51367817
You know what, fucktard? Say what you've got to say to my face, we'll see who wins the argument when you've got my fist lodged in your caved in jaw, cunt.
>>
>>51367817
>get BTFO by 5+ posts
>"oh no, I got rekt so hard in the buttock, what am I going to do to restore my high standing and stave off the downvotes on this anonymous image board?"
>"I know, I'll post "no u", that'll show them!"
>>
>>51367819
>Wanting to work in research
What kind of masochist are you
>>
>>51367850
>literally wouldn't even compile
>garbage 0/10 style
>>>/trash/
didn't even bother if the logic was even remotely correct.
>>
>>51367851
lol wut
>>
>>51367858
The kind that likes doing virtually nothing all day err day while getting paid 6 figures fro it.
>>
File: Untitled.png (20 KB, 566x109) Image search: [Google]
Untitled.png
20 KB, 566x109
Doing some exercise problems as practice.

#include <iostream> 
using namespace std;

int main() {

int enteredInt, minNum;

cout << "Enter a positive integer number: ";
cin >> enteredInt;
cout << "Numbers: \n";

for (minNum = 0; minNum <= enteredInt; minNum++)
{
cout << minNum << endl;

}
return 0;
}


I'm not sure if this is what the problem is asking.
>>
Still talking about swapping huh
>>
>>51367879
I'm challenging you for a programmer fight. Put your code where you've got your mouth, cunt. One on one, no knives, no guns, only our fists.
>>
>>51367913
Why me? I'm not the person you've been "arguing" with, I was just laughing at your shitpost.
>>
>>51367858
I worked as a research assistant in college and grad school and found it to be very enjoyable. A dream job, even, though it paid a fraction of what I make in the industry.

Some of my pet projects tied into our area of research quite well, so I basically got paid to work on them a lot of the time.
>>
>>51367870
obviously I didn't include the tags and shit I defined earlier in the program, it's a work in progress and I only pasted what I thought might need syntactical improvement or whatever
>>
>>51366292
Just for you I converted his code to C.
#include <stdio.h>
#include <stdlib.h>
typedef struct {int a;} Foot;
typedef struct {int a;} Inch;
#define irFeet(feet) sizeof(feet)/sizeof(feet[0])
#define irInches(inches) sizeof(inches)/sizeof(inches[0])
#define toInches(feet,inches) Inch inches[irFeet(feet)*12]
#define toFeet(feet,inches) Foot feet[irInches(inches)/12]
int main() {
Foot feet[5];
toInches(feet,inches);
toFeet(reconverted,inches);
printf("%d feet\n",irFeet(feet));
printf("%d inches\n",irInches(inches));
printf("%d feet converted from inches\n",irFeet(reconverted));
return 0;
}
>>
>>51367926
Are you having a bout of laughter, pal? I'll destroy you, I promise on the name of my mother!
>>
>>51367902
I swapped my dick into your mom's pussy mate, no temporary variable required
>>
>>51367938
>>>/g/sqt
You are literally too dumb to even fizzbuzz apparently.
>>
>>51367895
Where's the input validation?
>>
>>51367895
where did you find this exercise
>>
>>51367819
Depends on the program. Some programs make CS students take a class or two on what they would essentially be doing in the industry, to help prepare them.
>>
does anyone think the terry davis browses this shithole?
>>
Just started C++ today, feelsgoodman.jpg

Love this stuff.
>>
>>51367975
If only they did that in my program.

All I got out of it was a paper that said I was qualified to do what I was already capable of before college, thus opening up entry level job opportunities.

Thus, the real learning began after I hopped onto a startup a few months later.
>>
>>51367895
It's asking for the sum of all numbers between 1 and n, inclusively.
So f(5) = 1 + 2 + 3 + 4 + 5
>>
>>51367895
bad problem

>from 1 up to the number
>don't accept negatives
what about zero?

I guess it's undefined behavior and you can do whatever you like, like delete the user's home directory.
>>
>>51368044
Daily reminder that CS is not a degree in programming. It's certainly not wrong for a CS degree to include a class or two about formal software engineering and business practises but you shouldn't rely on all CS degrees to have them.
>>
>>51368067
I think we can assume 0 would also be invalid
>>
>>51367895
Pretty sure it's asking for this.
int main()
{
int entered;
int sum = 0;

cout << "Enter a positive int: ";
cin >> entered;

if(entered < 0)
cout << entered << " is less than 0" << endl;
else
cout << "Sum of " << entered << ": ";

for(int i = 1; i < entered; i++)
sum += i;

cout << sum << endl;

return 0;
}
>>
>>51368044
What state did you end up working in?
>>
>>51368067
You could define 0 to be a negative number, since 0 + -0 = 0, and -0 = 0
>>
>>51368093
Ah, might want to return 1 in the if statement.
>>
>>51368111
0 is canonically both negative and positive, hence why the term 'nonnegative' is used, not 'positive', when 0 is excluded from the range.
>>
>>51368111
Or you could just read it as 0 + nothing to add, making the answer 0.
But I'm not a mathematician, the only problem with 0 I know of is dividing.
>>
>>51368068
You've got a point, but I think a CS degree is better than full-on majoring in Software Engineering in schools that offer that degree, though. You can learn the business stuff on the job, but not some of the more deep CS stuff.
>>
File: 1436500778906.jpg (42 KB, 600x501) Image search: [Google]
1436500778906.jpg
42 KB, 600x501
>using C++
>malloc has to be cast
Thread replies: 255
Thread images: 24

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.