• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Programming |OT| C is better than C++! No, C++ is better than C

When you need to use an object for an indefinite amount of time, you need to allocate memory for it on the heap.

When you don't need it anymore, you need to free up that memory.

In C++, destructors are what's used to free that memory. Without them, memory would remain allocated to unused objects until the program is terminated, aka, a memory leak.

Hate to be pedantic, but this is not quite right. The destructor does not free the memory, the delete operator invokes the destrctor and then, after the destrctor is complete, the memory is freed by the delete operator.

The destrctor is just a function that gets run before the memory is freed. If your class allocated other memory during its life, then the destrctor *can* free that memory (by calling delete),
 
Just gonna dump my current code here since I have just a bunch of questions and this will make it easier.

Code:
weaknesses = [[1.0, 0.5], [2.0,1.0]] 

#just doing two types for now 
Fire = 0
Water = 1 

#gets the damage multiplier of an attack. Not really sure where to put this function. 
def get_damage_multiplier(x,y):
	multiplier = weaknesses[x][y] 
	return multiplier
	
class Pokemon(object):
	def __init__(self, name, hp, type1, type2, move1, move2, move3, move4):
		self.name = name 
		self.hp = hp
		self.type1 = type1
		self.type2 = type2 
		self.max_hp = hp
		self.move1 = move1
		self.move2 = move2 
		self.move3 = move3
		self.move4 = move4 




class Move(object):
	def __init__(self, name, damage, type):
		self.name = name
		self.damage = damage
		self.type = type 
		
	def info(move):
		print move.info 
		

	
class Ember(Move): 
	def __init__(self):
		Ember.name = "Ember" 
		Ember.damage = 3
		Ember.type = Fire
		Ember.info = "A basic fire attack. Not very strong." 
		
class Flamethrower(Move):
	def __init__(self):
		Flamethrower.name = "Flamethrower"
		Flamethrower.damage = 6 
		Flamethrower.type = Fire  
		Flamethrower.info = "A fairly powerful fire attack." 
class FireBlast(Move):
	def __init__(self):
		FireBlast.name = "Fire Blast" 
		FireBlast.damage = 10
		FireBlast.type = Fire 
		
class Bubblebeam(Move):
	def __init__(self):
		Bubblebeam.name = "Bubblebeam"
		Bubblebeam.damage = 8
		Bubblebeam.type = Water 
	
	
class Charizard(Pokemon):
	def __init__(self):
		Charizard.name = "Charizard" 
		Charizard.hp = 30
		Charizard.type1 = Fire 
		Charizard.type2 = "Flying" 
		Charizard.move1 = Ember()
		Charizard.move2 = Flamethrower()
		Charizard.move3 = FireBlast() 
		
class Blastoise(Pokemon): 
	def __init__(self):
		Blastoise.name = "Blastoise"
		Blastoise.hp = 35
		Blastoise.type1 = Water
		Blastoise.move1 = Bubblebeam()

1)

The weakness matrix allows me to get a damage multiplier pretty easily. Unfortunately if I try to allow a user to view the type1 of Blastoise or Charizard they get an integer. I'm unaware of a way to make it so that the user gets a string. Notice that Charizard's type2 is set to the string "Flying." So if a user wanted to see type2 of Charizard they'd get that info pretty easy. I can't really set the Pokemon types to be strings though without screwing up my solution for getting the damage multiplier. Maybe I now need a dedicated function to getting the type instead of just using
Code:
print Charizard.type1

2)

Where do I even put the weakness chart, integer assignments for Fire, Water, etc..., and the get_damage_multiplier function? Outside of the classes? In another class perhaps made to handle everything related to battles specifically?
Code:
class Battle(object)?
? I mean battles will need to access things from both the Pokemon class and the Move class.


Sorry for all these questions. I'm fairly knew to programming in general, and even less experienced with Object Oriented stuff. I may be biting off more than I can chew right now.
 

Haly

One day I realized that sadness is just another word for not enough coffee.
Well, to make a "ghetto enum", you can use a dictionary, which is a lookup table of "keys" and "values". So, you populate the keys with the type names as strings, and values with the numeric equivalents as integers.

I can't answer 2 because I don't know what file hierarchies looks like in Python. However, usually, for a bunch of variables you'll want to use all throughout your program, you'll make them global.
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
Just gonna dump my current code here since I have just a bunch of questions and this will make it easier.

1)

The weakness matrix allows me to get a damage multiplier pretty easily. Unfortunately if I try to allow a user to view the type1 of Blastoise or Charizard they get an integer. I'm unaware of a way to make it so that the user gets a string. Notice that Charizard's type2 is set to the string "Flying." So if a user wanted to see type2 of Charizard they'd get that info pretty easy. I can't really set the Pokemon types to be strings though without screwing up my solution for getting the damage multiplier. Maybe I now need a dedicated function to getting the type instead of just using
Code:
print Charizard.type1

2)

Where do I even put the weakness chart, integer assignments for Fire, Water, etc..., and the get_damage_multiplier function? Outside of the classes? In another class perhaps made to handle everything related to battles specifically?
Code:
class Battle(object)?
? I mean battles will need to access things from both the Pokemon class and the Move class.


Sorry for all these questions. I'm fairly knew to programming in general, and even less experienced with Object Oriented stuff. I may be biting off more than I can chew right now.

1) Easiest way would be to run it through a switch statement when the request for Pokemon type is called.
Code:
switch (type) {
	case 0:
		return 'Fire';
		break;
	case 1:
		return 'Water';
		break;
	case 2:
		return 'Grass';
		break;
	case 3:
		return 'Flying';
		break;
	case 4: 
		return 'Normal';
		break;
	case default:
		return 'Type not specified';
		break;
        // etc, etc for all types
}

2) You are on the right track. Battles would have a lot of data to them, so it could be worthwhile to split the battle functions out into a separate class.

Also, you're asking some great questions and grasping OOP principles a lot faster than others I've seen.

-----

edit: Haly kills it again. A dictionary would be a far more elegant way of handling that.
 
The destructor is invoked on an object created as an automatic variable when that variable falls out of scope. That doesn't apply to any object created using new. You have to invoke the object's destructor through, for instance, the delete operator.

The job of the destructor is to free up the object and any resources it created during its lifetime. The former happens implicitly, you have to code the latter. So if you have a class that uses a pointer and creates and maintains a linked list, say, the destructor should delete the list to ensure that all objects of that class will die harmlessly after first calling the linked list destructor. It's okay to call delete on a pointer to NULL or 0, nothing happens.

A class with a poorly designed destructor may cause mysterious memory leaks in any C++ program using it. This is a huge deal and a major weakness of C++, hence the language is still evolving defensive programming styles and language support features (for instance, RAII and smart pointers) to alleviate the problem.
 
Well, to make a "ghetto enum", you can use a dictionary, which is a lookup table of "keys" and "values". So, you populate the keys with the type names as strings, and values with the numeric equivalents as integers.

I can't answer 2 because I don't know what file hierarchies looks like in Python. However, usually, for a bunch of variables you'll want to use all throughout your program, you'll make them global.

1) Easiest way would be to run it through a switch statement when the request for Pokemon type is called.
Code:
switch (type) {
	case 0:
		return 'Fire';
		break;
	case 1:
		return 'Water';
		break;
	case 2:
		return 'Grass';
		break;
	case 3:
		return 'Flying';
		break;
	case 4: 
		return 'Normal';
		break;
	case default:
		return 'Type not specified';
		break;
        // etc, etc for all types
}

2) You are on the right track. Battles would have a lot of data to them, so it could be worthwhile to split the battle functions out into a separate class.

Also, you're asking some great questions and grasping OOP principles a lot faster than others I've seen.

-----

edit: Haly kills it again. A dictionary would be a far more elegant way of handling that.

Thanks again guys. Dictionaries slipped my mind. That would be a good way of handling it.

@ Granadier: First time seeing the term 'switch statement.' Doing more reading on it, it seems the best way to approximate this in Python is with a dictionary.

Anyway @ Haly's second point: In this case I'm not too sure if I should make the weakness chart a global variable since it is pretty much only going to come up in battles. I think I'll experiment with making a Battle class and putting the get_multiplier and fight function in there.
 

Onemic

Member
Is the finally statement in Java only used for closing files and streams? Reading these Oracle Java tutorials it seems like that's the only time you'd use finally.

Also, what exactly is a wrapper?
 
Is the finally statement in Java only used for closing files and streams? Reading these Oracle Java tutorials it seems like that's the only time you'd use finally.

It's a good example, but you can use the finally statement in many situations. Usually it's related to cleaning up some kind of resource regardless of whether an exception occurred.
 
Also, what exactly is a wrapper?

In software, a wrapper is a generic name for any piece of software that is used to mediate access to another. You typically use a wrapper to provide a simpler or more regular interface (a facade) or to provide a required interface for a piece of software to access another (an adapter). In many standard language libraries, higher level functions are built up as wrappers around lower level functions (the latter are usually called primitives in this context).

The code implementing the wrapper is often called "glue code" because its function is to allow two pieces of software to interface, or "stick together".
 

smiggyRT

Member
Java question, anyone know why JSONObject is adding the class info in the outputted JSON?

Code:
{"genre":"Sci Fi","author":"Orson Scott Card","title":"Enders Game",[B]"class":"class smiggyRT.BookInfo"[/B]}
 

Onemic

Member
In software, a wrapper is a generic name for any piece of software that is used to mediate access to another. You typically use a wrapper to provide a simpler or more regular interface (a facade) or to provide a required interface for a piece of software to access another (an adapter). In many standard language libraries, higher level functions are built up as wrappers around lower level functions (the latter are usually called primitives in this context).

The code implementing the wrapper is often called "glue code" because its function is to allow two pieces of software to interface, or "stick together".

Besides I/O, a resource can be heap memory, a memory mapping, a lock or mutex, or basically anything else the program has to ask for and then release when it's done.


thanks for the explanations man, appreciate it.
 

oxrock

Gravity is a myth, the Earth SUCKS!
Just gonna dump my current code here since I have just a bunch of questions and this will make it easier.

Code:
weaknesses = [[1.0, 0.5], [2.0,1.0]] 

#just doing two types for now 
Fire = 0
Water = 1 

#gets the damage multiplier of an attack. Not really sure where to put this function. 
def get_damage_multiplier(x,y):
	multiplier = weaknesses[x][y] 
	return multiplier
	
class Pokemon(object):
	def __init__(self, name, hp, type1, type2, move1, move2, move3, move4):
		self.name = name 
		self.hp = hp
		self.type1 = type1
		self.type2 = type2 
		self.max_hp = hp
		self.move1 = move1
		self.move2 = move2 
		self.move3 = move3
		self.move4 = move4 




class Move(object):
	def __init__(self, name, damage, type):
		self.name = name
		self.damage = damage
		self.type = type 
		
	def info(move):
		print move.info 
		

	
class Ember(Move): 
	def __init__(self):
		Ember.name = "Ember" 
		Ember.damage = 3
		Ember.type = Fire
		Ember.info = "A basic fire attack. Not very strong." 
		
class Flamethrower(Move):
	def __init__(self):
		Flamethrower.name = "Flamethrower"
		Flamethrower.damage = 6 
		Flamethrower.type = Fire  
		Flamethrower.info = "A fairly powerful fire attack." 
class FireBlast(Move):
	def __init__(self):
		FireBlast.name = "Fire Blast" 
		FireBlast.damage = 10
		FireBlast.type = Fire 
		
class Bubblebeam(Move):
	def __init__(self):
		Bubblebeam.name = "Bubblebeam"
		Bubblebeam.damage = 8
		Bubblebeam.type = Water 
	
	
class Charizard(Pokemon):
	def __init__(self):
		Charizard.name = "Charizard" 
		Charizard.hp = 30
		Charizard.type1 = Fire 
		Charizard.type2 = "Flying" 
		Charizard.move1 = Ember()
		Charizard.move2 = Flamethrower()
		Charizard.move3 = FireBlast() 
		
class Blastoise(Pokemon): 
	def __init__(self):
		Blastoise.name = "Blastoise"
		Blastoise.hp = 35
		Blastoise.type1 = Water
		Blastoise.move1 = Bubblebeam()

1)

The weakness matrix allows me to get a damage multiplier pretty easily. Unfortunately if I try to allow a user to view the type1 of Blastoise or Charizard they get an integer. I'm unaware of a way to make it so that the user gets a string. Notice that Charizard's type2 is set to the string "Flying." So if a user wanted to see type2 of Charizard they'd get that info pretty easy. I can't really set the Pokemon types to be strings though without screwing up my solution for getting the damage multiplier. Maybe I now need a dedicated function to getting the type instead of just using
Code:
print Charizard.type1

2)

Where do I even put the weakness chart, integer assignments for Fire, Water, etc..., and the get_damage_multiplier function? Outside of the classes? In another class perhaps made to handle everything related to battles specifically?
Code:
class Battle(object)?
? I mean battles will need to access things from both the Pokemon class and the Move class.


Sorry for all these questions. I'm fairly knew to programming in general, and even less experienced with Object Oriented stuff. I may be biting off more than I can chew right now.
I'm just curious, what are you using for an engine or will this game you're working on be text based only?
 
Just gonna dump my current code here since I have just a bunch of questions and this will make it easier.

Code:
weaknesses = [[1.0, 0.5], [2.0,1.0]] 

#just doing two types for now 
Fire = 0
Water = 1 

#gets the damage multiplier of an attack. Not really sure where to put this function. 
def get_damage_multiplier(x,y):
	multiplier = weaknesses[x][y] 
	return multiplier

Is there a reason you don't just do:

Code:
def get_damage_multiplier(x,y):
	return weaknesses[x][y]
 
Last week, Rust hit 1.0 alpha! Rust is a programming language developed by Mozilla desigend for systems programming (the area C and C++ are targeting currently) that has a bunch of very cool features. The most interesting thing is that the language is not garbage collected but the compiler makes sure that all pointers are valid and your programs are memory-safe. For me, the killer feature is that it's close to equal to C++'s speed but has none of the baggage that C++ has assembled over the last 30 years and it combines the coolest features from a couple of my favorite languages. (RAII from C++, Type classes, pattern matching, closures, type inference, stream processing, algebraic data types, basically almost everything cool from Haskell but without being Haskell)
 

poweld

Member
Last week, Rust hit 1.0 alpha! Rust is a programming language developed by Mozilla desigend for systems programming (the area C and C++ are targeting currently) that has a bunch of very cool features. The most interesting thing is that the language is not garbage collected but the compiler makes sure that all pointers are valid and your programs are memory-safe. For me, the killer feature is that it's close to equal to C++'s speed but has none of the baggage that C++ has assembled over the last 30 years and it combines the coolest features from a couple of my favorite languages. (RAII from C++, Type classes, pattern matching, closures, type inference, stream processing, algebraic data types, basically almost everything cool from Haskell but without being Haskell)

I've been meaning to check out Rust, maybe now's a good time. Have you tried Go, and if so, have any metrics to compare them by?
 

poweld

Member
I've also been following their updates as I've been wanting to dive into Rust, but I wanted to wait until they hit v1.0. Also, at first glance the language seems a little verbose (which could be completely untrue). Do you think it'll catch on the way C++ has?

I think it'd be hard to predict which languages will be supported and ubiquitous after 35 years :)
 

V_Arnold

Member
Hi, Programming-GAF!

I have a meta-programming question. Which is: how much should I rely on javascript's specifics if I might have to port my creations to other programming languages as well? Mainly, I am looking at a potential switft and java "ports". Where game logic would have to be transitioned perfectly (same numbers, same data, etc).

My problem is that I simply love relying on simple tricks Javascript has. Like these:

Code:
game.ready = function() { // stuff } 
game.loading = function() { //stuff, leads to gamestate ready } 
game.state = "ready" (or loading, setup, etc) 
game[game.state]();

I guess this one could be replaced with a switch.
How about this?

Code:
function overloadingWithStuff(checker,data){

switch (checker)
case "single-argument" {
 //Do not rely on data at all
} break;

...

case "multiple-argument" { stuff(data[2])
} break;

Which is just making flexible functions where I am expecting some references in certain cases, more or less references in other cases. Should I never ever rely on js-specific stuff (I could bring more examples, problem is that in the past two years, I mainly programmed in javascript, I do not even remember which functions are language specific anymore, compared to when I was actively doing stuff in c#/java/as. Thanks for any advice! I heard Swift is actually close to ecmascript2/3/5/whatever, so maybe that one is not going to be so tricky. But creating classless stuff in java, where objects sorta borrow functions from each other on the fly? Not so sure :O
 

injurai

Banned
I've also been following their updates as I've been wanting to dive into Rust, but I wanted to wait until they hit v1.0. Also, at first glance the language seems a little verbose (which could be completely untrue). Do you think it'll catch on the way C++ has?

It has to do with what the language is trying to accomplish, and how rust is defined as a formal language to implement it's core features. I think it has a very good chance to catch on. I think it will grow significantly to fill the niche that it's made for, but when the paradigm shift occurs is anyones guess. This is clearly meant to be more than the next language fad, it's supposed to be a long term effort to improve upon languages that are by all means past their expiration dates.

I'm really looking forward to sinking my teeth more into it. I've been trying to pick between Rust, Nim and Elixir for a while now. Now that Rust is at 1.0, I think I'll take a deeper dive.
 
I've been meaning to check out Rust, maybe now's a good time. Have you tried Go, and if so, have any metrics to compare them by?
I've personally not messed with Go, the only experience I have with it was my attempt to port a Go library to Rust (which I started but never finished). Go has a much weaker type system from what I can tell, no real generics and it's garbage collected. Rust has a type system with very strong compile-time guarantees (almost like Haskell). Go's advantages seem to lie in the concurrency field, which I have little experience in.

I've also been following their updates as I've been wanting to dive into Rust, but I wanted to wait until they hit v1.0. Also, at first glance the language seems a little verbose (which could be completely untrue). Do you think it'll catch on the way C++ has?
As for verbosity, I feel it's definitely better than C++ or Java. Can't really say much more than that. The #[derive(..)] feature removes a lot of the boilerplate for data types. An example would be:
Code:
#[derive(Show, Clone, PartialEq, Eq)]
struct SomeValues {
    i: i32,
    x: String,
    things: Vec<u32>
}
The struct can now be converted to a string (Show), cloned and compared with other instances of the same type (PartialEq, Eq).

So, does Rust have OOP now?
Not in the traditional sense, there's no inheritance. There's ways to do composition via traits (basically interfaces that can have implemented methods).
 
It has to do with what the language is trying to accomplish, and how rust is defined as a formal language to implement it's core features. I think it has a very good chance to catch on. I think it will grow significantly to fill the niche that it's made for, but when the paradigm shift occurs is anyones guess. This is clearly meant to be more than the next language fad, it's supposed to be a long term effort to improve upon languages that are by all means past their expiration dates.

I'm really looking forward to sinking my teeth more into it. I've been trying to pick between Rust, Nim and Elixir for a while now. Now that Rust is at 1.0, I think I'll take a deeper dive.

How good a language is is really orthogonal to how well it will catch on. Whether it catches on will be determined by how good its toolchain, ide, and debugger support are imo.
 
I think it'd be hard to predict which languages will be supported and ubiquitous after 35 years :)
Lol fair enough. I guess my bigger question is, "Does Rust fill an adequate enough niche in the C/C++ world to stay viable long term?"

As for verbosity, I feel it's definitely better than C++ or Java. Can't really say much more than that. The #[derive(..)] feature removes a lot of the boilerplate for data types. An example would be:
Code:
#[derive(Show, Clone, PartialEq, Eq)]
struct SomeValues {
    i: i32,
    x: String,
    things: Vec<u32>
}
The struct can now be converted to a string (Show), cloned and compared with other instances of the same type (PartialEq, Eq).

This is definitely interesting (I don't know how unique it is). I guess I will have to look into after all this assembly!
 
The only thing enum really does is make your code more legible. If you create your own "cheatsheet" by manually writing down what types correspond to which numbers, you can use my example verbatim.
Some of what I say below may depend on the implementation of enumerations on a per language basis. My point of reference here is C/C++/ObjC/to a lesser extent,Java etc.

I think you're underestimating the importance of this and highly advise against this approach. Encoding the meaning in an enumeration name is potentially its greatest strength. Also, in languages like C or C++, a popular but awful way of doing things is using macros but you lose important things like type safety as well as proper debugger support.

EG (using C code):
Code:
int rawIntConsultYourLookupTable = 5;

#define SOME_VALUE 10
int testy = SOME_VALUE;

typedef enum
{
    SE_VALUE_A,
    SE_VALUE_B
} SomeEnum_t;
SomeEnum_t anEnum = SE_VALUE_A;

Assuming all of that is in some main function in C and you can actually compile/run the program, lets say you're using the visual studio debugger and you step through the above code. Set a breakpoint after the assignments and check the values of these variables.

What does the VS debugger show for the value of rawIntConsultYourLookupTable after the assignment?

5, and you have ZERO point of reference if you lose said lookup table or if you change it and forget to update the reference, or even more poisonous, your reference is straight wrong. You can't even see any context in your assignments.

What does the VS debugger show for the value of testy after the assignment?

10, but at the very least you can see some context at your assignment locations, assuming of course that you're disciplined enough to always use macros AND you also make damn sure that no invalid values get assigned (cause the compiler can't automatically help you with that matter, so you'll have to write extra code to guarantee valid assignments).

What does the VS debugger say for the value of anEnum after the assignment?

SE_VALUE_A(0)

Keep in mind that you're often working across files - you may not see the assignment to the variable as easily as you can above so rather than having to consult some weird number chart, you can see clearly the meaning in the name.

Enums also restrict assignment to valid values. If you just write down what number corresponds to what, in the long term it's going to be hard to understand, hard to change (especially if you have many points of reference), and also very error prone. If your code assumes a certain range of values, and somehow an invalid number gets assigned to the variable, then you're in for a fun debugging session.

A common pattern for enums in C/C++ is to use switch tables to implement logic specific to certain types an enum maps to. Most compilers (that I've used) allow you to make switches that don't handle every value declared in the enumeration as an error. What does this mean? If you add to an enumeration, say by introducing another character type, then rather than having to manually look up every single switch in your code that works with said enum (while potentially missing some switch statements, and thus potentially introducing a bug into your code), you can just hit the compile button and it will error out and tell you exactly where you need to add cases.

This advice is partially language specific, but even if legibility were your ONLY concern (say if we're dealing with a language without any type safetyp it's STILL (IMO) worth it to use enums in many cases.

Of course there are certain things that would be stupid and clumsy to enums with but something like character types is begging for enums (at least if you're not handling it polymorphically or something)
 

cyborg009

Banned
Does anyone have any personal recommendations for website hosting free or paid? I started working with foundation and it was pretty great.
 

injurai

Banned
How good a language is is really orthogonal to how well it will catch on. Whether it catches on will be determined by how good its toolchain, ide, and debugger support are imo.

This is a clean start though, so a bunch of enthusiast who understand the core intrinsic values will be building those. So people eventually come. Of course it needs those things, and it's part of their long term plan to build it into a viable language. Because it's obvious the C/C++ languages at their core hold many antiquated pitfalls that we can get passed today.
 
This is a clean start though, so a bunch of enthusiast who understand the core intrinsic values will be building those. So people eventually come. Of course it needs those things, and it's part of their long term plan to build it into a viable language. Because it's obvious the C/C++ languages at their core hold many antiquated pitfalls that we can get passed today.

I wouldn't go that far. Just because rust solves some of the problems that some C/C++ Programs have does not mean it will be a suitable replacement for every C++ program. So calling them "antiquated pitfalls" is a little too much. Pitfalls maybe, but they will continue to be necessary for many programs
 

injurai

Banned
I wouldn't go that far. Just because rust solves some of the problems that some C/C++ Programs have does not mean it will be a suitable replacement for every C++ program. So calling them "antiquated pitfalls" is a little too much. Pitfalls maybe, but they will continue to be necessary for many programs

You've really missed the point. People want better languages. They realize after exploring new ideas of computation, automata, compiler design that things could be done better. Instead of building up old languages with these gothic buttresses of features. We see a consolidation of great ideas into new cores. There is an impetus for why these languages are created, people value defining safe expressive turing complete languages.

Of course C++ has incredibly rich features sets, libraries, and toolchains. It started out with very little. Of course new languages will have to reach similar milestones to reach similar ubiquity.

Rust has a plethora of unsafe programming features. You can call C/C++/assembly even. But the core ideas around Rust are intended to be something better. Something of great value to both the theory of computation and the actual writing of programs.

All you're really saying is it still has it's work ahead of it. I think it's completely fair to say that the languages of yesteryear have pitfalls, but that the new languages seeking to replace them go out of their way to not make the same mistakes of the past. Eventually those too will be replaced as we flesh out even more corners and paradigms of programming.
 

phoenixyz

Member
Not in the traditional sense, there's no inheritance. There's ways to do composition via traits (basically interfaces that can have implemented methods).

I tried Rust a few months ago and that was what made me give up pretty fast. Why would a language which wants to succeed C++ not offer traditional OOP? That smells of ideology.
 
I tried Rust a few months ago and that was what made me give up pretty fast. Why would a language which wants to succeed C++ not offer traditional OOP? That smells of ideology.

Many people and languages are shifting away from (implementation) inheritance as an object model. Its one of those things that you use constantly when starting out, and much less as you become more experienced.
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
Monday I have an interview for a web dev intern position at a local company. While discussing it I was shown the job description paper, but was told that the work I'd be doing would be beyond that since I have previous experience working with the tech. What worries me though is that the job description made it seem to be unpaid with a $500 stipend at the end. Since my work would be beyond that scope though, I'd like to request a better pay setup.


How best should I go about requesting for a higher stipend or hourly pay for the position?


(this would be my first "real" position in the industry)
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
Thanks but it was only $5 for the domain seems like I'll have to shell out another 10 for the hosting. Also good luck on the job.

Ahh, I handle my hosting through GitHub pages, so I didn't realize that. Google could be another option with $12/year. And thanks.
 
Many people and languages are shifting away from (implementation) inheritance as an object model. Its one of those things that you use constantly when starting out, and much less as you become more experienced.

Yeah, for sure. Even in C++ and Java, the langauges where inheritance is probably the most wide-spread, the style has shifted to composition over inheritance. There are still some use cases where inheritance is very useful and it's planned for Rust, but IIRC, there's no concrete ETA yet. If there's one thing that's annoying about Rust, it's that it can sometimes be frustrating to try to satisfy the borrow/type checker. It has improved a lot recently though and in the end, it will catch errors that would otherwise occur at runtime.
 

phoenixyz

Member
If there's one thing that's annoying about Rust, it's that it can sometimes be frustrating to try to satisfy the borrow/type checker. It has improved a lot recently though and in the end, it will catch errors that would otherwise occur at runtime.

Iirc it wasn't the lack of traditional inheritance which bugged me the most but this. When you expect stuff to just work because of polymorphism you need (or needed?) to jump through all kinds of hoops.
 

nOoblet16

Member
Can anyone help me figure out me what is wrong with the following please ? This is regarding cryptography.

Take a message M, generate a random private RSA key K. Encrypt M with K and take the first 240 bits of the result as a hash of M.

Maybe I'm wrong here, I probably am but I feel like it might be something to do with RSA being non deterministic, or maybe it's to do with the message being un-decryptable with the public key if we don't use the entire text and only the first 240 bits.
 

poweld

Member
Can anyone help me figure out me what is wrong with the following please ? This is regarding cryptography.



Maybe I'm wrong here, I probably am but I feel like it might be something to do with RSA being non deterministic, so it can give you the same cipertext for two different plaintext, and as such using this cipertext as a hash could result in a hash collision.

I'm not quite sure what you're asking, but if it's "could this result in hash collisions?" the answer is yes.

However, keep in mind that any time you're hashing to a fixed length, you're going to introduce the possibility of hash collisions. MD5, SHA, Murmur, etc, all take n bytes and produce y bytes - the output length is unrelated to the input length.

Let's say you're using a one byte hashing algorithm. In one byte, you can store 8^2 = 256 different values. For all inputs, there can only be 256 different outputs, so of course you're going to get collisions when your input can be millions of bytes long.

The hash provided with many crypto algorithms is usually to ensure that it is unfeasible to tamper with the data. The purpose of a hash is for the output to change dramatically even when the input only changes slightly. Therefore, it's difficult to find another input that matches a hash value, especially in a short amount of time (say, during a man in the middle attack)

Hope this answered your question.

edit: regarding the non-determinism of RSA, you mentioned that two different plaintexts can have the same ciphertext. That doesn't actually mean a lot - this could happen with other ciphers and doesn't indicate non-determinism. What does make RSA non-deterministic is that the same plaintext encrypted twice with the same context may have different ciphertexts, due to some randomness in padding during the encryption process.
 

nOoblet16

Member
I'm not quite sure what you're asking, but if it's "could this result in hash collisions?" the answer is yes.

However, keep in mind that any time you're hashing to a fixed length, you're going to introduce the possibility of hash collisions. MD5, SHA, Murmur, etc, all take n bytes and produce y bytes - the output length is unrelated to the input length.

Let's say you're using a one byte hashing algorithm. In one byte, you can store 8^2 = 256 different values. For all inputs, there can only be 256 different outputs, so of course you're going to get collisions when your input can be millions of bytes long.

The hash provided with many crypto algorithms is usually to ensure that it is unfeasible to tamper with the data. The purpose of a hash is for the output to change dramatically even when the input only changes slightly. Therefore, it's difficult to find another input that matches a hash value, especially in a short amount of time (say, during a man in the middle attack)

Hope this answered your question.

edit: regarding the non-determinism of RSA, you mentioned that two different plaintexts can have the same ciphertext. That doesn't actually mean a lot - this could happen with other ciphers and doesn't indicate non-determinism. What does make RSA non-deterministic is that the same plaintext encrypted twice with the same context may have different ciphertexts, due to some randomness in padding during the encryption process.

I see.
As for my question, it was basically that I am given this algorithm that was detailed in the quote in my previous post

Take a message M, generate a random private RSA key K. Encrypt M with K and take the first 140 bits of the result as a hash of M.


and I was asked "What is wrong with it". As in why it won't work ?
Since then I've found out that it's basically that if we are to decrypt a message successfully with a public key then we have to use the entire ciper message rather than just the first 240 bits to generate the hash, as the decryption won't work otherwise. Since hash map is a key value pair and without the entire message it won't be able to find the key when it tries to search for it.
 

YoungFa

Member
Is anyone here doing Go? It seems to be next big thing in terms if languages. Can anyone share their experiences switching to go?
 

poweld

Member
edit: nvm

Have a cat instead: www.clickforcats.com/gifs/couchattack.gif

Is anyone here doing Go? It seems to be next big thing in terms if languages. Can anyone share their experiences switching to go?
I learned it earlier this year for a relatively small project. I am way into its concurrency model and rapid compilation, but definitely stumbled on its type system. Like mentioned earlier, inheritance is not quite like in C++, for better or worse.
 
Hopefully I'm not going too off-topic, but what laptops do you guys use for programming/development? I mostly use my desktop when I'm home but I feel like I'm starting to need a better laptop with good battery life and more power for my job and for school.

I use Visual Studio for work and I'm currently using Netbeans for school to give you some idea of what I'd be doing. If you could point me in the right direction, I'd appreciate it!
 

poweld

Member
Hopefully I'm not going too off-topic, but what laptops do you guys use for programming/development? I mostly use my desktop when I'm home but I feel like I'm starting to need a better laptop with good battery life and more power for my job and for school.

I use Visual Studio for work and I'm currently using Netbeans for school to give you some idea of what I'd be doing. If you could point me in the right direction, I'd appreciate it!

For any non-desktop work I'm using my Lenovo x220. Got it a few years ago, installed Debian on it, been happy as a clam. With the extended battery I get about 6-8 hours, with the battery slice on top of that, 10-12.

I also get anxious about battery life, so it works incredibly well for me. Plus, dat keyboard.
 
Top Bottom