Advertising (This ad goes away for registered users. You can Login or Register)

Are constructors and destructors Evil?

Discuss about your favorite (gaming...or not) devices here. The most popular ones will end up getting their own categories
Programming discussions for your favorite Device
Forum rules
Forum rule Nº 15 is strictly enforced in this subforum.

Are constructors and Destructors Evil?

Yes
0
No votes
No
4
100%
 
Total votes: 4

User avatar
Acid_Snake
Retired Mod
Posts: 3099
Joined: Tue May 01, 2012 11:32 am
Location: Behind you!

Re: Are constructors and destructors Evil?

Post by Acid_Snake » Tue Mar 11, 2014 10:45 pm

[spoiler]QT sucks
░░░░░▄▄▄▄▀▀▀▀▀▀▀▀▄▄▄▄▄▄░░░░░░░
░░░░░█░░░░▒▒▒▒▒▒▒▒▒▒▒▒░░▀▀▄░░░░
░░░░█░░░▒▒▒▒▒▒░░░░░░░░▒▒▒░░█░░░
░░░█░░░░░░▄██▀▄▄░░░░░▄▄▄░░░░█░░
░▄▀▒▄▄▄▒░█▀▀▀▀▄▄█░░░██▄▄█░░░░█░
█░▒█▒▄░▀▄▄▄▀░░░░░░░░█░░░▒▒▒▒▒░█
█░▒█░█▀▄▄░░░░░█▀░░░░▀▄░░▄▀▀▀▄▒█
░█░▀▄░█▄░█▀▄▄░▀░▀▀░▄▄▀░░░░█░░█░
░░█░░░▀▄▀█▄▄░█▀▀▀▄▄▄▄▀▀█▀██░█░░
░░░█░░░░██░░▀█▄▄▄█▄▄█▄████░█░░░
░░░░█░░░░▀▀▄░█░░░█░█▀██████░█░░
░░░░░▀▄░░░░░▀▀▄▄▄█▄█▄█▄█▄▀░░█░░
░░░░░░░▀▄▄░▒▒▒▒░░░░░░░░░░▒░░░█░
░░░░░░░░░░▀▀▄▄░▒▒▒▒▒▒▒▒▒▒░░░░█░
░░░░░░░░░░░░░░▀▄▄▄▄▄░░░░░░░░█░░[/spoiler]
Advertising

User avatar
codestation
Big Beholder
Posts: 1660
Joined: Wed Jan 19, 2011 3:45 pm
Location: /dev/negi

Re: Are constructors and destructors Evil?

Post by codestation » Tue Mar 11, 2014 10:52 pm

I agree, QT (QuickTime) sucks.
Advertising
Plugin list
Working on: QPSNProxy, QCMA - Open source content manager for the PS Vita
Playing: Error: ENOTIME
Repositories: github, google code
Just feel the code..

User avatar
Infinite Chalupas
Posts: 92
Joined: Thu Feb 20, 2014 9:00 pm

Re: Are constructors and destructors Evil?

Post by Infinite Chalupas » Sun Mar 16, 2014 11:16 pm

So I've came to a conclusion about what I'm wanting to do with the project I'm working on, which is that I'll be implementing constructors and destructors (albeit, slightly different)


Basically, I'm working on designing a new programming language.

[spoiler]It's similar to C# and Java and has several goals:
  • It will be designed particularly with multi-threading in mind; having directives for thread control and automated heap allocation. Eg. there could be an attribute called 'threaded' that tells the compiler that the stack space for the method should lie on the heap.
  • There will be clearer type definitions. char/uchar == 8 bits/6 trits, half int/uint/fixed/float = 2 chars, int/uint/fixed/float = 4 chars, double int/uint/fixed/float = 8 chars.
  • There will be no binary dependence. Instead of a 'bool', there will be a 'logic' type. This is to allow the language to be expanded in the future for more complex architectures that may be ternary, quaternary, etc.
There are also other ideas like >>> <<< (logical shift), ^> ^< (bitwise rotation), and Create / Destroy operators in place of constructor / destructor. For example, where you would normally type:

Code: Select all

String string = String("Test");
string.~String();
To create a string and destroy a string in C++ without allocating memory, you would instead use:

Code: Select all

String string = String.Create("Test");
string.Destroy();
Which is much more understandable. 'new' and 'delete' operators will still work the same way.

Another idea was to provide access to the scope of interfaces, classes, methods, and properties that (as the name implies) allows the user to get specific information about the object such as the name, object size, stack size, and members at runtime. Useful for debugging, relocating code, or implementing reflection.


Anyhow, things are still in the planning process. When I finish writing a compiler for it, I'll create a new topic.[/spoiler]

User avatar
hgoel0974
Retired Mod
Posts: 2154
Joined: Mon Jul 23, 2012 11:42 pm
Location: Maia, Pleiades Nebula

Re: Are constructors and destructors Evil?

Post by hgoel0974 » Sun Mar 16, 2014 11:44 pm

Good luck with that ;)
I personally have tried writing a programming language multiple times, but have always failed to figure out how to properly parse the code
"If the truth is a cruel mistress, then a lie must be a nice girl"

User avatar
Acid_Snake
Retired Mod
Posts: 3099
Joined: Tue May 01, 2012 11:32 am
Location: Behind you!

Re: Are constructors and destructors Evil?

Post by Acid_Snake » Sun Mar 16, 2014 11:46 pm

Infinite Chalupas wrote:Basically, I'm working on designing a new programming language.
I'm also working on my own language (got modular programming, basic OOP and syntax working), and from what I can tell by your definition, you're gonna make the same mistakes that makes Java and C# a no-go for most serious programmers, big-budget game developers and hackers: outdated C syntax (for C it's understandable, it's a freaking old language, but when modern languages do this it feels like kicking the creator in the ***), no low-level access (and lets be honest, adding pointers doesn't make your language low level, for the most part C# pointers are useless), virtual machine *** that slows the whole thing down, forced OOP-only ideals which force you to do code smells (like static classes), overly convoluted descriptors (private static final unsigned long int x = 0, wtf?), no proper modular programming (and badly implemented namespaces, if implemented at all) and overall treating programmers like **** while still doing a lot of implicit stuff (which is in itself a contradiction, but these two languages do it).
hgoel0974 wrote:Good luck with that ;)
I personally have tried writing a programming language multiple times, but have always failed to figure out how to properly parse the code
some people would suggest you to use regex, but I personally write my own algorithms.

User avatar
hgoel0974
Retired Mod
Posts: 2154
Joined: Mon Jul 23, 2012 11:42 pm
Location: Maia, Pleiades Nebula

Re: Are constructors and destructors Evil?

Post by hgoel0974 » Mon Mar 17, 2014 12:26 am

Acid_Snake wrote:
hgoel0974 wrote:Good luck with that ;)
I personally have tried writing a programming language multiple times, but have always failed to figure out how to properly parse the code
some people would suggest you to use regex, but I personally write my own algorithms.
I think I see how regex would work in a language where newlines and spacing are syntactically important but what about something like C#/Java/C/C++ where anything can at most be anywhere?
"If the truth is a cruel mistress, then a lie must be a nice girl"

User avatar
Acid_Snake
Retired Mod
Posts: 3099
Joined: Tue May 01, 2012 11:32 am
Location: Behind you!

Re: Are constructors and destructors Evil?

Post by Acid_Snake » Mon Mar 17, 2014 12:52 am

hgoel0974 wrote:I think I see how regex would work in a language where newlines and spacing are syntactically important but what about something like C#/Java/C/C++ where anything can at most be anywhere?
normally what they do is use a grammar parser to turn the code into an intermediate code that is easier to parse, I kinda do that, I convert the code independently between different formats until I obtain a fully compilable C file.

User avatar
Infinite Chalupas
Posts: 92
Joined: Thu Feb 20, 2014 9:00 pm

Re: Are constructors and destructors Evil?

Post by Infinite Chalupas » Mon Mar 17, 2014 1:34 am

Acid_Snake wrote:
Infinite Chalupas wrote:Basically, I'm working on designing a new programming language.
I'm also working on my own language (got modular programming, basic OOP and syntax working), and from what I can tell by your definition, you're gonna make the same mistakes that makes Java and C# a no-go for most serious programmers, big-budget game developers and hackers: outdated C syntax (for C it's understandable, it's a freaking old language, but when modern languages do this it feels like kicking the creator in the ***)
Most good languages are C based. I love the python syntax, don't get me wrong, but it's a bigger kick in the *** when a single misplaced space can destroy your entire program. I am bringing something new to the table with the scope accessing. The idea came to mind from back when I was writing N64 assembly mods, how efficient it would be if I could relocate my code without having to use an assembly stub.
Acid_Snake wrote:, no low-level access (and lets be honest, adding pointers doesn't make your language low level, for the most part C# pointers are useless), virtual machine *** that slows the whole thing down,
This is meant to compile to native code (or rather, compile to an intermediate assembly language, then from that to the actual assembly language, then to machine code) One of the reasons I decided to do this to begin with was because of the nasty GNU AT&T syntax that makes low-level stuff tedious and almost impossible. The assembler should adhere to the architecture's specification in my opinion.
Acid_Snake wrote:forced OOP-only ideals which force you to do code smells (like static classes), overly convoluted descriptors (private static final unsigned long int x = 0, wtf?),
I've thought about that quite a bit actually. Despite my favorite language being C, I do believe programs should be well structured, so namespaces and classes are a must. As for the overly convoluted descriptors, I think you're looking too much into it. The only one you actually need is "static". Members are public by default. The others have no actual purpose other than to restrict the developer; as there is no difference between a private and public member at runtime. You can go without using them if you want, but they're essential for team projects as a way of communication, saying to anyone else who may be working with your code that "you shouldn't use this private function, because it could change", or "you shouldn't extend this object".
Acid_Snake wrote:no proper modular programming (and badly implemented namespaces, if implemented at all) and overall treating programmers like **** while still doing a lot of implicit stuff (which is in itself a contradiction, but these two languages do it).
Namespaces were never intended for modularity, as the name suggests, they were meant to shorten object names and encapsulate objects into spaces to prevent symbol conflicting.

================================================

Also, just a glimpse of the syntax I've been working on so far:

Code: Select all

namespace MyNamespace
{
	class MyClass
		is private, static, and final
	{
		method DoStuff()
			throws MyException
		{
			for (var i = 0; i < 5; i++)
			{
				if (i == 4)
					throw MyException.Create("MyExceptionText");
			}
		}
	}


	interface MyInterface
	{
		method DoMoreStuff();
	}


	class MySubclass
		extends MyClass,
		implements MyInterface,
		and is public
	{
		property MyProperty as int is public
		{
			get { return 0; }
		};


		method DoMoreStuff()
			returns int
		{
			return 0;
		}
	}
}
I thought it would be a good idea to use "as", "is", and "and" keywords to move the attributes to the right of the object declarations, which would allow them to optionally be placed on a new line; thus making the code more legible. Thoughts?

User avatar
Infinite Chalupas
Posts: 92
Joined: Thu Feb 20, 2014 9:00 pm

Re: Are constructors and destructors Evil?

Post by Infinite Chalupas » Mon Mar 17, 2014 3:47 am

So I've been trying to think of a way to tiptoe around the issue C has for when there are too many arguments for a function to fit on one line. One idea I came up with was to toss out parenthesis and have a 'with' keyword. I was also considering doing away with the "." used to access members of an object, because it would really be just as easy to use a space as a delimeter.

Code: Select all

namespace System Data
{
	class Buffer
	{
		var address as object is private;
		var size as uint is private;


		property Address as object is public
		{
			get { return this address; }
		}

		property Size as uint is public
		{
			get { return this size; }
			set
			{
				this address = realloc(this address, value);
				if (this address == null)
					this size = 0;
				else
					this size = value;
			}
		}


		method Create
			as operator is public and static with
			var size as int,
			var fillWithZeros as bool = false
			returns Buffer
		{
			this address = malloc(size);
			if (this address != null)
			{
				this size = size;
				if (fillWithZeros)
					memset(this address, 0, size);
			}
			else
				this size = 0;
			return this;
		}

		method Destroy
		{
			if (this address != null)
				free(this address);
		}
	}
}

What's your opinion on this?

User avatar
Acid_Snake
Retired Mod
Posts: 3099
Joined: Tue May 01, 2012 11:32 am
Location: Behind you!

Re: Are constructors and destructors Evil?

Post by Acid_Snake » Mon Mar 17, 2014 10:46 am

Infinite Chalupas wrote:but it's a bigger kick in the *** when a single misplaced space can destroy your entire program
mostly because python allows whitespaces to be either tabs or spaces, my language only allows tabs, they are easier to use, they will not create conflict between different pieces of code, they are easier to see and easier to parse.
Infinite Chalupas wrote:I've thought about that quite a bit actually. Despite my favorite language being C, I do believe programs should be well structured, so namespaces and classes are a must. As for the overly convoluted descriptors, I think you're looking too much into it. The only one you actually need is "static". Members are public by default. The others have no actual purpose other than to restrict the developer; as there is no difference between a private and public member at runtime. You can go without using them if you want, but they're essential for team projects as a way of communication, saying to anyone else who may be working with your code that "you shouldn't use this private function, because it could change", or "you shouldn't extend this object".
the problem with it is that it takes more time for the programmers to read the code and see what it does than with other methods. Python for example uses underscores to declare private attributes, this is better as with less code you are giving away more information, and the way I do it (as shown on the other thread) is even better.
Infinite Chalupas wrote:Namespaces were never intended for modularity, as the name suggests, they were meant to shorten object names and encapsulate objects into spaces to prevent symbol conflicting.
structs weren't intended for OOP either but it evolved into it, same applies with namespaces, not being developed for that doesn't mean you have to stay archaic and continue to use namespaces like that. Modular programming has been proven to be a really good way of structuring code and the ultimate evolution to namespaces.

I see that your language is following the trend that Java and C# have followed, which is also the trend that keeps them archaic: OOP-only, no modular programming, god-awful old-looking not-at-all sexy C syntax. Do one simple test: write a hello world in C and a hello world in your language, if it takes more code in your language then you are going the wrong way.

Post Reply

Return to “Programming and Security”