C# and other OOP languages - Page 1
Forum section: electronics / general

author: Stonent
author_rank: Super Contributor
timestamp: October 06, 2014, 01:08:03 am
content: I'm currently taking a C# class that is part of a degree in database administration that I'm working on. The degree required a programming credit but none of the programming classes I took 13+ years ago were transferable, so I had to take an introductory programming course to fill that credit need. Years back when I took programming classes, the introductory class was Turbo Pascal and the next semester, you had a choice of "Programming I" which was C, or VB 6. I decided on VB since I had learned BASIC as a kid and eventually took C later, but have had no experience working with Object Oriented languages and until now never really understood what an object really was. I had just assumed it was a fancy way of saying function or subprogram.Since a lot of you guys do program maybe you could answer some questions about a few things that have been gnawing at my mind, but I don't know if they are specific to C# or object oriented languages in general, since as of this point I'm not really sure where one ends and the other begins.Here goes:I feel like I do a lot of unnecessary type conversions to avoid compiler errors. Does the compiler/IDE (Visual Studio 2012 in my case) realize when they are not necessary and not bother to do a wasted type conversion or does it go through the motions of converting a type when not needed? This example I just created out of thin air to be an extremely obvious waste of a conversion.Code:string string1 = "This is a string";string string2;string2 = Convert.ToString(string1);I could have simply said string2 = string1 and it have been functionally the same. Is that optimized out during the compile stage?I also see that I can do a lot of crazy things that I find myself saying "well this seems logical but there's no way it would work" but it does work.Example:This is a line from a program I'm working on (no I'm not asking for homework help on this). The line is just there to give me some status as to what my variables are doing as I'm working on part of it.wordGuess is an array of chars and I'm outputting it is a string. I had tried to use the ToString method but apparently you can't do that for whatever reason with an array of chars. So I did some research and found out about using "new string" but the example was something like:Code:string s = new string(c);In my case I didn't need to assign it to anything, I just wanted to monitor its status my program did its thing, so I thought, what if I just omit the assignment?So here I create a new string out of thin air with no variable for it to go into, and it works.Code:Console.WriteLine("{0} {1} {2}", wordList, index, new string (wordGuess));Is this some kind of on the fly thing that disappears or does it actually take a small snip of memory that it doesn't give back. If I ran it through an infinite loop, would the program eventually crash because of eating up too much resources?I guess I think about wasted resources a lot more because playing with microcontrollers has made me appreciate the skills and forethought needed to make a fairly complex program work on a platform with maybe 128 bytes of RAM and 512 bytes of flash and then you learn things like storing things in the flash to avoid them being in RAM.So were my examples above just C#-isms or do other OO languages give you the power to do these odd things?

author: c4757p
author_rank: Super Contributor
timestamp: October 06, 2014, 01:32:54 am
content: The specifics depend on the language, but most of this is typical. Disclaimer: I've done lots of OO languages, but not C#.Quote from: Stonent on October 06, 2014, 01:08:03 amNo, it's not optimized out, and it might not be equivalent. I don't know how Convert.ToString() responds when given something that's already a string - whether it makes a copy, or just returns the original. Check the documentation. But either way, the call is unlikely to be optimized out.Most people would just saystring2 = string1;unless they needed a copy, in which case they'd usenew string.Of course, all of this copy business depends on whether strings in C# are even mutable. If they're not, then it doesn't even make sense to make a copy.QuoteAlso depends on the language. C# is a garbage-collected language, like Java. This means that the new strings are created somewhere in memory and left there - and occasionally, a garbage collector comes along and frees resources that aren't in use anymore. It's a bit unpredictable - I really don't like it, myself - but common in OO languages and a bit easier. Something like C++ would create the object specifically for the duration of the function call and then immediately destroy it when the function returns.**I wouldn't spend too much time worrying about efficiency in general. As Knuth said, "premature optimization is the root of all evil". Let the garbage collector do its job, and if you start having memory problems, be more clever about memory usage or do that bit in a language like C where you do the memory management yourself. Creating a string out of thin air for the purpose of displaying it is hardly excessive on a PC.**Edit:Notif you said "new string". Thenewkeyword has a subtly different meaning in C++ - if you create something withnew, you're expected to destroy it withdelete. But instances can be created in other ways too, and anything created as part of a variable or argument declaration is destroyed when that variable or argument goes out of scope.

author: IanB
author_rank: Super Contributor
timestamp: October 06, 2014, 02:11:45 am
content: Concerning OO in general (all languages, not just C#). Objects are user defined data types that represent the properties and behavior of the things your program is dealing with. All objects have a type. A type represents common properties and behaviors shared by objects of the same type, but each individual object may contain unique data (or state). The OO programming approach allows you to organize your program logic in a more convenient way using principles like abstraction and encapsulation.Concerning C# in particular, you really need to spend some time on introductory principles of C# and the .NET programming environment. In particular you need to know the difference between value types and reference types. That's absolutely fundamental to C# programming.If the compiler gives you type conversion errors it is trying to save you from making a mistake. You need to understand what mistake you were making and not try to find a way around it. If you do things the right way the compiler won't (normally) complain.Creating an array of chars is a somewhat unusual thing to be doing in C# (although completely normal in C). If you are doing that it is possible you are not using the features of C# in the most natural way.In your example, when you say "new string(wordGuess)" you are creating a new string object using one of the string constructors. If you don't keep a reference to this object anywhere then it will have a temporary lifetime and the memory will be recovered by the system for re-use after you have finished with it.

author: poorchava
author_rank: Super Contributor
timestamp: October 06, 2014, 06:11:01 am
content: you can create variables like int, string, byte, char and so on same as you would in C. There is no 'new' keyword needed. Nevertheless those types are also objects of particular class (press '.' or ctrl+space after variable name and you'll see that those types have public methods. Basic types liek strings, chars, ints and so on also have a helper static class that contains some useful methods (like for example Int32.Parse).

author: amyk
author_rank: Super Contributor
timestamp: October 06, 2014, 06:37:14 am
content: Classes in OOP are just a way of grouping together data and some functions that operate on that data. If you know what C structures are and have written functions that do things with them then you're basically doing some OOP even if you don't realise it.

author: Stonent
author_rank: Super Contributor
timestamp: October 06, 2014, 06:43:09 am
content: The reasoning behind the array of chars was I tried to manipulate the chars in the string by using an index but it won't let you address it that way. So I have to copy the string into an array of chars make my changes and move it in to a string by using new string on the array of char.So (at least in C#) myString = 'g'; will not work as the string is considered immutable.I ended up using something like this: (wordList is an array of strings, wordGuess is an array of chars)Code:rndNum = ranNumberGenerator.Next(0, 8); // Generate a random number from 0 to 7 to be used to select a word in the arraywordLength = wordList.Length; // Get the length of that wordwordGuess = wordList.ToCharArray(0, wordLength); // Load that word into a char array for manipulation// Now that the word is loaded, manipulate the datafor (index = 0; index < wordLength; ++index){/* Changes to the char array happen here */}wordGuessString = new string(wordGuess); // Load the char array into wordGuessString for display purposes

author: Stonent
author_rank: Super Contributor
timestamp: October 06, 2014, 06:59:59 am
content: Quote from: amyk on October 06, 2014, 06:37:14 amI remember doing structures in my C class 13-ish years ago, but haven't had the need to use them in any of my microcontroller projects yet, so I had essentially forgotten about them.Initially I had hoped to learn C++ instead of C# since C++ wasn't Microsoft centric. So I figured they're both object oriented and related to C so I should be able to make some sense of C++ after learning some C#, right? Nope, C++ looks even more confusing to me now than it ever did before, but on the plus side (I guess it's a plus...) I can now read Java for the most part. I can't speak it, but I can look at it and figure out what's going on.

author: dekra54
author_rank: Unknown
timestamp: October 06, 2014, 07:44:30 am
content: HiHave you tried the String.Remove and String.Insert methods ?wordList.Remove(INT32 value start of remove , INT32 Value end of remove);and then insert the new chars with String.InsertwordList.Insert(INT32 start Index of Insertion, STRING String value to insert);http://msdn.microsoft.com/de-de/library/d8d7z2kk%28v=vs.110%29.aspxhttp://msdn.microsoft.com/de-de/library/system.string.insert%28v=vs.110%29.aspx

author: nctnico
author_rank: Super Contributor
timestamp: October 06, 2014, 09:52:43 am
content: From a C++ background that seems weird to me. In C++ you can write string1=string2 which puts a copy of string2 into string1 (similar to many high level languages). I can't believe the same operation is so obfustigated in C#.

author: c4757p
author_rank: Super Contributor
timestamp: October 06, 2014, 10:45:54 am
content: Quote from: nctnico on October 06, 2014, 09:52:43 amIt's quite simple, actually, no obfuscation anywhere. C++ makes you manage memory yourself, so naturally it has separate value, pointer, and reference modes. A variablestring s1is a direct string whose data is stored on the stack; a variable of typestring *s1isn't a string, but a pointer whose value is stored on the stack, which points to a string whose data is stored on the heap.C# and Java still make that distinction, but differently. All types are stored on the stack always - but class types are actually stored as references. A variablestring s1isn't a string, it's a reference to one. It can be 'null' just like a C++ pointer, and can point to any string anywhere in the heap. The only difference between these and pointers is that pointer arithmetic is not supported.Essentially, they makenew/deleteeasier by replacingdeletewith a garbage collector, and then force you to use them by making all class instance variables pointers.

author: nitro2k01
author_rank: Frequent Contributor
timestamp: October 06, 2014, 11:34:16 am
content: Quote from: Stonent on October 06, 2014, 01:08:03 amstring1 and string2 are references to objects in memory. If you do string2 = string1;, they both now point to the same object in memory. Normally, this would mean that if you modify the object, say if you add an item to an array list, you will see the newly added object whether accessing the object from one or the other reference. This is not so different from a pointer pointing to a memory location in C.However, strings are, by design, immutable. There is no way you can modify the memory that the object is located at. string2 = string1; is therefore perfectly safe and sensible. If you later do string2 = "Another string"; a new string object is created, and the string2 reference ("pointer") is now made to point to that object instead, and string1 is left intact.string2 = Convert.ToString(string1); may or may not be optimized depending on the implementation. Convert.ToString may choose to return the same object if the object is of type string instead of creating a new one. Bottom line is, that that shouldn't matter for strings and other immutable objects, as far as correct execution is concerned.Should? Should. There is a common pitfall, at least in java, and quite possibly in c#, which is that the == operator compares the references and not the contents of the objects. Something like:Code:string string1 = "a string";string string2 = "a string";if (string1 == string2){Console.Write("true")}else{Console.Write("false")}would then report false, since the strings are stored in separate objects. To confuse things further, the compiler might be smart enough to point string1 and string2 to the same reference, as their contents are identical and they appear in the same scope. The comparison above might then be true, while the same comparison made from user input would be false.The correct way to compare strings is with Equals: if (string1.Equals(string2))Quote from: Stonent on October 06, 2014, 01:08:03 amUnlike a language like c++, c# has a garbage collector, whose job it is to look for unreferenced objects and recycle their resources. Unless garbage collector leaks resources, that line should not create any problem.To aid your mental model, new string (wordGuess) is an expression. Expressions can generically be used both in a function call or in an assignment, or even on its own.Code:new string (wordGuess) <- Example of an expressionstring s = <some expression>;Console.WriteLine(<some expression>);<some expression>;So:string s = new string (wordGuess);Console.WriteLine(new string (wordGuess));new string (wordGuess);The last line is of course utterly useless for strings. But if you were creating an object from a class you wrote, that does something useful in its constructor, but that you don't need a reference to, then that code is a valid, though quirky way of creating an object of that type.Going on, the reason that you cannot do a ToString on a char array, is that a char array, much like an int or a float, is not an object. Thus it has no methods you can execute. You should still be abloe to convert it into a string using Convert.ToString(chararray) or new string(chararray).

author: tggzzz
author_rank: Super Contributor
timestamp: October 06, 2014, 03:21:57 pm
content: Quote from: IanB on October 06, 2014, 02:11:45 amEr, not C++. The pointer/referencein the source codecontains contains the type information, which may or may not be valid and certainly is not present in the object code. In C++ the bytes in memory can be interpreted in any way you choose, by casting just as in C.In all sane languages you are, of course, correct. The mechanism, as I'm sure you know, is that in one way or another each object contains a pointer to something representing the class of the object.

author: tggzzz
author_rank: Super Contributor
timestamp: October 06, 2014, 03:26:41 pm
content: Quote from: nctnico on October 06, 2014, 09:52:43 amEr no, not at all in C++. If you want to copy a string you have to invoke a method/function to do so.Presuming string2/1 are pointers/references to the bytes in memory that you wish to be interpreted as strings, all you've done is get two variables to point to the same set of bytes, i.e. created an alias.

author: nctnico
author_rank: Super Contributor
timestamp: October 06, 2014, 04:17:06 pm
content: Quote from: tggzzz on October 06, 2014, 03:26:41 pmNope. The standard C++ string type has overloaded the = operator to copy the string when you write string1=string2. I looked it up specifically to be sure.

author: tggzzz
author_rank: Super Contributor
timestamp: October 06, 2014, 04:36:41 pm
content: Quote from: nctnico on October 06, 2014, 04:17:06 pmOh hell, I'd forgotten the abomination of operator overloading. Why? Because the last time I used C++, and abandoned it as being "Completely The Wrong Thing Done To Perfection", it didn't have operator overloading.Mind you, presuming certain specific declarations of string1 and string2, it does look as if the compiler can to choose tomoveit, and if moved, string2 is left in an unspecified but valid state. Whatever that means. ( Sourcehttp://www.cplusplus.com/reference/string/string/operator=/)That is yet another simple example of how C++ is great for language lawyers who enjoy wrestling with aligators, but not for people that simply want to get a job done by draining the swamp.

author: IanB
author_rank: Super Contributor
timestamp: October 06, 2014, 04:55:48 pm
content: Quote from: tggzzz on October 06, 2014, 03:21:57 pmI think this is a slightly unreasonable mixing up of the conceptual abstraction of the language and the precise details of how it is implemented.Stroustrup himself is very clear that the motivation for classes in C++ is to represent user-defined types. It is true that with an implementation built on top of C, then some low level machinery is more exposed than it might be, but that doesn't undermine the conceptual abstractions that the language is aiming to provide.The truth is that with C++ I can code in an OO manner more conveniently than I can with C, and from the point of view of C++ that would count as mission accomplished.

author: Wilksey
author_rank: Super Contributor
timestamp: October 06, 2014, 05:17:04 pm
content: Different languages, different ways of doing things, it's like VC++ using WinForms, the pointer is now a ^ rather than * apparently, very confusing unless you are used to it.C# was designed by the same person that designed Delphi I believe, I use it day in day out for windows based stuff, it does the job and I can create something very quickly.I came from an array of different languages, from BASIC, assembler, C/C++, Java and a few variants of, when Microsoft released .NET my RAD windows stuff was done in VB6, I didn't like the new VB.NET, but I did like C#, I did used to get Java and C# mixed quite a bit back in the early days, but eventually overcame that.The only issue I have had with C#, and the same can be said for Java is it is extremely easy to reverse engineer, so I downloaded a free obfuscator for C# which works well and I have made my own for Java, not foolproof but nothing is, and keeps the majority of people out.

author: Bored@Work
author_rank: Super Contributor
timestamp: October 06, 2014, 05:32:30 pm
content: Quote from: Stonent on October 06, 2014, 06:59:59 amNot surprising. C# was Microsoft's way to kill Java on the desktop, esp. the Windows desktop. They took more from Java than from C / C++ when designing the language. Of course Microsoft denies having copied Java - but when did they ever tell the truth?The language was designed by the same guy who decades ago did develop Turbo Pascal and Delphi, and later had already done J++ for Microsoft. J++ was Java with Microsoft extensions to lock programmers to Windows. That created some trouble for Microsoft later on. In fact $1.6bn of trouble, the sum Microsoft had to pay to Sun. The guy doing J++ was then moving on to do C#. And he and Microsoft had 1.6 billion good reasons denying any association of C# with Java. Nevertheless, C#'s lineage is roughly Java --> J++ --> C#Microsoft also had a language called J#. That was derived from the above mentioned Microsoft J++, with .NET features added. J# was also intended to lure Java developers away from (theoretically) cross-platform Java to definitely Windows-only code.J++ didn't really take off, J# did not really take off, but C# did, and Java on the Windows Desktop was dead and is ever since.

author: tggzzz
author_rank: Super Contributor
timestamp: October 06, 2014, 05:37:34 pm
content: Quote from: IanB on October 06, 2014, 04:55:48 pmUnfortunately with C++ (much more than Java/C#) the conceptual abstraction rapidly degenerates due to the horrific interactions with the implementation. I'm reminded of the old joke "If you want to get there, I wouldn't start from here", where "there" is OOP nirvana, and "here" is C.QuotePersonally I find Objective-C is far better starting point for OOP-in-C. But then that's because my trajectory in the '80s was C->Smalltalk->C/C++.I rapidly dropped the C++ when it became apparent that C++ would always need to be subsetted for a given project, and that each library you might think of purchasing would use a slightly different subset. That judgement was shown to be valid for, say 15 years, but might be slightly less valid in the past 10 years.But I don't care since for all projects that might use C++ now use either C or Java (or C#, which is essentially Java with a different concept how the runtime should work).

author: tggzzz
author_rank: Super Contributor
timestamp: October 06, 2014, 05:47:25 pm
content: Quote from: Bored@Work on October 06, 2014, 05:32:30 pmNot quite, as you acknowledge below. The impetus was to lock application developers into Windows, using the tried and tested "embrace and extend" technique.QuoteWhen Anders Hejlsberg gave us a talk (in c2000) before C++ was released, it was completely apparent that C#was indeedJava plus a different philosophy about how the runtime should be implemented. When we asked if we were missing something, he didn't answer.QuoteOh, (while there's some truth there) thats too strong. There are many Java applications that run under Windows, but typically they don't go out of the way to make that evident.

author: nctnico
author_rank: Super Contributor
timestamp: October 06, 2014, 06:41:49 pm
content: Quote from: Bored@Work on October 06, 2014, 05:32:30 pmIMHO C# is 'Java which works for Windows'. Given that many Java programs work very crappy I feared the worse when Google announced they wanted to use Java for Android. Fortunately Google decided to create their own Java engine from scratch which more or less acknowledged my fears.

author: tggzzz
author_rank: Super Contributor
timestamp: October 06, 2014, 07:06:31 pm
content: Quote from: nctnico on October 06, 2014, 06:41:49 pmWhich is equally true for all languages, of course. Maybe the key factor isn't the language

author: nctnico
author_rank: Super Contributor
timestamp: October 06, 2014, 08:45:28 pm
content: Quote from: tggzzz on October 06, 2014, 07:06:31 pmNo. Sometimes the problem is in the framework. Lot's of errors I've seen in Java programs originate from parallel threading errors.

author: nctnico
author_rank: Super Contributor
timestamp: October 06, 2014, 08:49:18 pm
content: Quote from: mojo-chan on October 06, 2014, 08:15:21 pmThat may be true but if you step outside the Windows world then C# suddenly is a poor choice. When I have to create a desktop application I use C++ and Wxwidgets because I know I can get my software to work very easely on every popular platform without having to depend on specific libraries or limited implementations (like Mono). In fact I develop all my 'for Windows' software on Linux because it is easier.

author: vvanders
author_rank: Regular Contributor
timestamp: October 07, 2014, 03:39:00 am
content: Having spent a bunch if my career working on tools built in wxWidgets I find that surprising. You're missing out on delegates, properties, a great editor and an even better debugger.If I'm writing for multiple platforms I could see wxWidgets but if you're writing windows only there's many advantages to C#/winforms/etc.

author: tggzzz
author_rank: Super Contributor
timestamp: October 07, 2014, 07:23:56 am
content: Quote from: nctnico on October 06, 2014, 08:45:28 pmI appreciate English (probably) isn't your first language. In the context of programming, the word "framework" has so many different definitions, meanings and usages that it has become almost meaningless. From a famous book written by a logician 150 years ago:"When I use a word," Humpty Dumpty said, in rather a scornful tone, "it means just what I choose it to mean—neither more nor less.", seehttp://en.wikipedia.org/wiki/Humpty_Dumpty#In_Through_the_Looking-GlassSo, in order to understand what you are trying to say, could you please indicate which meaning of "framework" you are using?(For some meanings I would not disagree with you, but for others you are plain wrong.)

author: miguelvp
author_rank: Super Contributor
timestamp: October 07, 2014, 07:46:28 am
content: Hmmm, where to start.There is a fundamental problem with Java vs C#. Java uses CORBA for marshalling and it's quite expensive, C# and all other M$ languages and technologies use COM and that's more than obvious in Windows8 where everything is an interface.C++ without COM interfaces is fast and with lambdas and the new additions of C++11 it makes it a more robust language, of course you have to know what you are doing because it's still as powerful as ASM, C and C++.Object orientation is really not hard to grasp, the premise is simple, you define an object and provide methods to work on that object.But concurrency and fault tolerance are not free. It's up to the programmer to make it scalable on any language.The new trend, well not really yet a trend, is to use functional languages like Erlang and Haskell for cloud computing that is scalable, fault tolerant and concurrent. It's going to help a lot too when we have a thousand cores.C# and Java are cute. I rather program in python since I can import C++ libraries, in any event C++ is still king until the Functional languages take over so we can use more than 10% of our processors without a lot of programmers sleepless hours to use all of those cores at full capacity.Say no to marshalling it just too expensive (even if COM is lighter because it wasn't developed by committee like CORBA was).COM btw started as OLE then ActiveX adopted by .NET etc.. the new inception is Windows Run Time (WRT) it's powerful but not the quickest (but better than CORBA) Distributed COM or D-COM is powerful too, better than RPC.To me marshalling is like a copy construct in C++, you just don't want to do that, or at least avoid it when possible.So for OOP languages, if they need to be on the cloud and be scaleable and concurrent. I will say Erlang.

author: nctnico
author_rank: Super Contributor
timestamp: October 07, 2014, 11:12:02 am
content: Quote from: tggzzz on October 07, 2014, 07:23:56 amIn programming context a framework is a set of libraries that complete a language or offer a programming environment. See:http://en.wikipedia.org/wiki/Software_framework

author: tggzzz
author_rank: Super Contributor
timestamp: October 07, 2014, 12:04:48 pm
content: Quote from: nctnico on October 07, 2014, 11:12:02 amOK. So then the validity or otherwise of your argument depends onwhichlibraries you mean.If you mean the standard Java runtime libraries that that are part of the JDK/J2SE, then you will have to work very hard and be very specific in order to justify your assertion. Why? Because there are many high-reliability high-availability soft real-time applications that would be visible andveryexpensive if they failed. I know. I've seen them and built some myself.If, on the other hand, you mean some other library that uses the standard Java runtime libraries, then you will also have to be specific, but it will be less difficult to justify your assertion. Why? Because anybody can "write a Java framework", publish it and then try to debug it when someone complains - and many have with predictably ghastly results.If, on the third hand, the frameworks you are referring to involve communicating with other computers across the internet, then you may well be right, because far too programmers don't understand the fundamental limitations of distributed systems. Far too few have even heard of L Peter Deutsch's "eight fallacies of distributed computing", let alone realised how thry must shape frameworks and applications. Far to many presume that the network and all the other computers (that they don't even know exist) will always function conrrectly.Hells teeth, I've even come across people that think it is possible to have reliable distributed transactions. (Hint: it isn't, unless you've made fundamental breakthroughs in solving the Byzantine General's problem, and the "split brain" problems arising from network partitioning). Such people are very likely to create a subtly faulty mess even on a single computer, in any language.But neither the "other hand" nor the "third hand" issues are related to Java: they are common to all languages and environments.Blaming Java almost always the equivalent of saying that, say, Analog Devices integrated circuits are faulty because a Chinese (or other) backstreet shop read an application note, copied a circuit in it without understanding, turned it into a bad PCB, and sold it.

author: nctnico
author_rank: Super Contributor
timestamp: October 07, 2014, 01:10:52 pm
content: Then explain why Java applications are more prone to erratic behaviour than others (based on my own observations). I've seen quite a few Java application where following the same procedure results in an error every now and then. Even Eclipse isn't entirely free of this kind of behaviour. If it is a bug then it would fail every time; not once in a while.

author: HackedFridgeMagnet
author_rank: Super Contributor
timestamp: October 07, 2014, 01:30:44 pm
content: QuoteCause the JVM's written in C++.QuoteThe funny thing is Microsoft just paid $2.5 billion for a Java game. Java on windows is not quite dead yet.My kids love it. They're just worried about Microsoft wrecking it.

author: tggzzz
author_rank: Super Contributor
timestamp: October 07, 2014, 02:02:14 pm
content: Quote from: nctnico on October 07, 2014, 01:10:52 pmAnecdotes are not data.The simple, and almost certainly correct, explanation is that the applications are written badly. "Badly" = not taking into account all possible sequences of inputs, or not taking into account that the sub-systems they communicate might fail, or merely in a way that should feature on "The Daily WTF!".Whenever an engineer comes to me and says "my circuit doesn't work, so the IC must be faulty", I tell them to "prove it". In trying to do so, they almost always end up finding the fault in their understanding of the IC or their circuit.The same is true of computer programs (with the notable exception of C++, where even language lawyers can't agree on what is right)QuoteI've seen even more C#, C++, C, Ruby, .... applications that give an "error now and again". Should we then suppose that C#, C++, C, Ruby etc is to blame? I think not.QuoteNonsense.To summarise your position: "I've seen a few failures, so Java is at fault". Unconvincing.

author: nctnico
author_rank: Super Contributor
timestamp: October 07, 2014, 04:37:21 pm
content: You seem to misunderstand. A real bug is easy to reproduce. A program always fails in the same way. What is different with Java programs (note the plural) is that programs don't always fail in the same way but behave erratic. You may call that an anecdote and dismiss it but that still doesn't mean there is no underlying problem.

author: tggzzz
author_rank: Super Contributor
timestamp: October 07, 2014, 06:24:59 pm
content: Quote from: nctnico on October 07, 2014, 04:37:21 pmNonsense, both in practice and in theory, both for hardware and for software.You've clearly never had to locate faults in large systems with various components written by various companies, changing asynchronously with each other.Suppose one programmer sets the transaction properties of a database transaction in a different way to other programmers. There's no chance whatsoever of detecting that in unit tests, and it is improbable (though conceivable) that you would detect it in integration tests. Even if you were to try and stimulate that specific problem, it would be very difficult to do it reliably. The way you are likely to see it is in very infrequent "random" failures in the installed system - and those failures would lookto youjust like a multithreading problem. Well in a way it is a multithreading problem, but not one that can be blamed on the database or language.Or another example: consider the idiots that believe there are 24 hours in a day or 60 seconds in a minute. Even if you get it right inside your code, how will your program work with a separate system (or library) that gets it wrong? Unless you explicitly test for all those possibilities, you will have to wait anindeterminatenumber ofyearsfor the right conditions to stimulate the problem.QuoteNonsense.You clearly haven't dealt with large scale distributed programs and networking hardware.QuoteErratic behaviour is nothing new, and there are endless ways in which it might occur.Your assertion is that the Java multithreading is the root cause of all these bugs. You have no evidence whatsoever to substantiate that presumption. A much simpler and more likely reason is that the developers didn't understand the behaviour inherent in the system they were "designing", and hence wrote bad code.They would have done the same in any language you care to choose.

author: nctnico
author_rank: Super Contributor
timestamp: October 07, 2014, 07:09:51 pm
content: Quote from: tggzzz on October 07, 2014, 06:24:59 pmThen let's say that my observation is that Java programmers appear to have above average problems understanding their programming environment (framework) and leave it at that. You may choose to use that information to your advantage or not.

author: SirNick
author_rank: Frequent Contributor
timestamp: October 07, 2014, 07:22:31 pm
content: I hate Java, and I shudder to defend it. But...Code:#include <stdio.h>int main () {int x;if (x == 3) {printf("Error -- aborting.\n");return 1;}printf("All clear!\n");return 0;}Code:gcc -o test test.cCode:./testAll clear!Code:./testAll clear!Code:./testAll clear!Code:./testError -- aborting.Now, did I just witness an inconsistency in the language? Or a bug?

author: c4757p
author_rank: Super Contributor
timestamp: October 07, 2014, 07:27:03 pm
content: The language is quite consistent and the compiler's not buggy. It's a bug in your code. What do you think the value ofxis at the moment you test it?The operating system is just giving you whatever block of memory happens to be available, with whatever data already happens to be in it. It won't load an initial value unless you tell it to.By the way, you can and should make the compiler smarter:Code:% gcc -Wall -Wextra -Werror -o test test.ctest.c: In function ‘main’:test.c:6:8: error: ‘x’ is used uninitialized in this function [-Werror=uninitialized]if (x == 3) {^cc1: all warnings being treated as errors

author: miguelvp
author_rank: Super Contributor
timestamp: October 07, 2014, 07:43:39 pm
content: Uninitialized data is a common rookie mistake.It doesn't help that when you make a debug build some compilers initializes the data for you.

author: tggzzz
author_rank: Super Contributor
timestamp: October 07, 2014, 08:15:20 pm
content: Quote from: nctnico on October 07, 2014, 07:09:51 pmThere is no practical use that I, or anyone else, could make of that (very arguable) observation.Java is now the ab initio language of choice, so one would expect more ab initio class errors.Java is sufficiently powerful that it enables ordinary programmers to tackle far more complex problems than are possible in many earlier languages.If you look athttp://thedailywtf.com/you will see many languages represented, including Java and C#.I note that you are not attempting to defend your assertions, unsurprisingly.

author: tggzzz
author_rank: Super Contributor
timestamp: October 07, 2014, 08:17:25 pm
content: Quote from: SirNick on October 07, 2014, 07:22:31 pmIt is always good to see someone recognising that all tools have their advantages and disadvantages. Knowing them is the essential starting point for choosing the most appropriate tool for the task at hand.But you knew that!

author: SirNick
author_rank: Frequent Contributor
timestamp: October 07, 2014, 08:31:33 pm
content: Quote from: c4757p on October 07, 2014, 07:27:03 pmBTW, in case it wasn't obvious, I fully understand the implications of the code as written. The variable was intentionally not initialized to illustrate that sometimes "languages" do "random" things because the humans that write code in those languages make mistakes that aren't always immediately visible. Code like that example could work perfectly for years, until it suddenly doesn't.Are Java's problems similar? Who knows. Without a specific case study, including source and test results, it's hard to substantiate claims that it tends to fail in inconsistent ways.However, in my own, scientifically unproven opinion, the Java environment tends to be fragile and prone to having code that worked yesterday stop working today. It's almost always the result of users updating the JRE every time it pops up a notification, leaving a trail of dozens of prior versions, and ensuring that no one has any clue which JRE is actually running a given app or applet at any given time. Not that C is free of its own dependency issues, of course...

author: nctnico
author_rank: Super Contributor
timestamp: October 07, 2014, 09:17:18 pm
content: Quote from: tggzzz on October 07, 2014, 08:15:20 pmI don't have to. I know what I have seen. If you Google 'Java erratic behaviour' there seem to be many ways to shoot yourself in the foot because of less obvious issues to be aware off. Java (the one from Sun) is often touted to be an easy language to use but if that where the case then why did Google go through all the trouble and create their own version of Java. They wheren't going to avoid having to pay for Java anyway. I don't see you trying to answer that question.

author: jancumps
author_rank: Unknown
timestamp: October 07, 2014, 09:32:53 pm
content: Quote from: miguelvp on October 07, 2014, 07:43:39 pmOh dear, have I been bitten by that one in the late 1990s©In visual C++, a Date variable was initialized in debug mode and not in non-debug mode. That got me completely on the wrong path for the best part of a (well paid) day.It's not a language issue though, just an implementation library issue. But I recognized miguelvp's situation.

author: SirNick
author_rank: Frequent Contributor
timestamp: October 07, 2014, 09:42:31 pm
content: Quote from: nctnico on October 07, 2014, 09:17:18 pmIt has always been unclear to me why they chose Java, out of all the available languages. To insulate themselves from future architectural changes? Some folks have presented very impressive numbers in terms of JIT execution overhead. But on a space and speed constrained platform, why volunteer for any overhead at all?

author: c4757p
author_rank: Super Contributor
timestamp: October 07, 2014, 09:45:50 pm
content: Quote from: SirNick on October 07, 2014, 08:31:33 pmDoesn't matter. Languages which initialize to a default value can mask the uninitialized variable just as well as they can point it out. All depends on whether the default value is valid in a given case or not. The only way around this is to detect it intentionally: enable warnings for uninitialized access, and run a memory checker like Valgrind. And unless you're developing for a platform where you can't use Valgrind, there is no excuse for not doing either one.

author: Bored@Work
author_rank: Super Contributor
timestamp: October 07, 2014, 10:03:13 pm
content: Quote from: nctnico on October 07, 2014, 09:17:18 pmGoogle didn't create their own version of Java. In fact, you need to use the Sun, now Oracle, toolchain, including the Oracle Java compiler, to develop for Android. Google added a way to later on transpile the bytecode, as generated by the Oracle Java compiler, into their own version of bytecode, for their own virtual machine.But the language, and compiler implementation is 100% Oracle Java. Every alleged, imaginary or real limitation or idiosyncrasy of the language is 100% there, because of the use of the originally compiler from Sun/Oracle.Google also developed copies of many, but not all standard Java libraries, or used open source. That code is written in the original Sun/Oracle Java language and is compiled with the Oracle Java compiler, too.QuoteActually, paying is exactly what Google were and is still trying to avoid. They didn't like the licensing terms offered by Sun. So the went ahead, using the freely available Sun/Oracle Java compiler, adding a bit of stuff at the end, and their own libraries.Oracle doesn't like that a bit and is dragging Google through the courts because of thishttp://en.wikipedia.org/wiki/Oracle_v._GoogleQuote from: nctnico on October 07, 2014, 07:09:51 pmWell, you didn't exactly show any above average knowledge of Java with your rather strange claims of Googles own version of Java.

author: tggzzz
author_rank: Super Contributor
timestamp: October 07, 2014, 10:38:05 pm
content: Quote from: nctnico on October 07, 2014, 09:17:18 pmComplete ignorance. Google didn't create their own version of Java, so the whole premise of your question and conclusions evaporate into thin air.Oracle tried to sue Google for that reason (for >$1bn), and their case was comprehensively demolished in court.Android/Dahlvik has different libraries, a different compilation philosophy (much more like .NET), a different runtime, leaving merely some similar syntax and semantics.

author: tggzzz
author_rank: Super Contributor
timestamp: October 07, 2014, 10:41:53 pm
content: Quote from: SirNick on October 07, 2014, 09:42:31 pmThe didn't choose Java, as has been proven in court.They did choose a language with similar semantics and syntax so as to enable a rapid uptake by the hoardes of Java programmers. Dahlvik is principally an ahead-of-time compilation system, similar to .NET. Caveat: I haven't looked at Google's reported replacement for Dahlvik.

author: tggzzz
author_rank: Super Contributor
timestamp: October 07, 2014, 10:44:58 pm
content: Quote from: Bored@Work on October 07, 2014, 10:03:13 pmPrecisely.As far as I can determine, all his assertions on this subject have been more-or-less a rant. I make no assertions about his statements on other topics.

author: nctnico
author_rank: Super Contributor
timestamp: October 08, 2014, 12:21:51 am
content: Quote from: Bored@Work on October 07, 2014, 10:03:13 pmThe interesting thing about observations is that you don't need in depth knowledge to make them. And if Google only wrote their own JVM then they probably had a good reason to do so instead of buying it off the shelve from (at that time) Sun.

author: tggzzz
author_rank: Super Contributor
timestamp: October 08, 2014, 12:50:42 am
content: Quote from: nctnico on October 08, 2014, 12:21:51 amNo indeed. But it does help if you want to makevalidobservations.QuoteWell that's correct except for two facts: Google didn't write their own (they bought a company.), and it isn't a JVM (it is much closer to the .NET philosophy)

author: IanB
author_rank: Super Contributor
timestamp: October 08, 2014, 02:08:08 am
content: Quote from: SirNick on October 07, 2014, 08:31:33 pmNot really, because in any professional development environment--I mean workplace environment, not software environment--in any professional development environment the compiler flags would be set to catch that bug.You have a choice. You can use an angle grinder without eye protection, but if you don't, and if you get hot metal in your eye, it's your fault and not the fault of the angle grinder.

author: IanB
author_rank: Super Contributor
timestamp: October 08, 2014, 02:13:45 am
content: Quote from: tggzzz on October 07, 2014, 08:15:20 pmI'm rather inclined to disagree with this statement. To suggest that any language is "more powerful" than another is to underestimate the stupidity of ordinary programmers.An anti-tank gun is more powerful than a BB gun. Which one is more likely to cause damage in untrained hands?Java was specifically designed to be the BB gun to other language's anti-tank guns. So why on earth would anyone choose to use Java when they want to get a job done?

author: miguelvp
author_rank: Super Contributor
timestamp: October 08, 2014, 02:42:25 am
content: Quote from: IanB on October 08, 2014, 02:08:08 amYou are quite right, maximum level warnings and treat warnings as errors is just the beginning in a professional development environment. That code just wouldn't compile

author: SirNick
author_rank: Frequent Contributor
timestamp: October 08, 2014, 02:44:12 am
content: Quote from: IanB on October 08, 2014, 02:08:08 amI don't know why I'm surprised, but I should learn never to discount the potential for a simple example to get blown out of proportion.OK, for the sake of everyone's sanity:1) IT WAS JUST AN EXAMPLE.2) There was an intentional, stupid, easily preventable bug in the EXAMPLE code.3) I was trying to illustrate (with an EXAMPLE) how it's possible for the same (user) input to lead down different execution paths, and how this is not necessarily the fault of the language.4) Yes, you should always enable the most pedantic, obnoxious warnings you possibly can; then use Valgrind to make sure your compiler didn't miss anything; then run it through unit tests; then peer reviews; then static code analysis or whatever it's called; then throw it away and use managed languages, because that's the only thing that's safe. Oh yeah, EXAMPLE.Alright. Are we good now?

author: miguelvp
author_rank: Super Contributor
timestamp: October 08, 2014, 03:48:58 am
content: I know it was just an example and it was obvious that was your intention, and only meant like that, I was just pointing out that there are many levels to prevent that, including no warning compiles

author: zapta
author_rank: Super Contributor
timestamp: October 08, 2014, 05:18:24 am
content: Quote from: SirNick on October 07, 2014, 07:22:31 pmInconsistency? I see a very consistent result in all runs, an undefined outcome per the language's specification. ;-)BTW, it's interesting that nobody mentioned yet Go and Scala, these are the next languages on my todo list. Both are used successfully in actual products.

author: tggzzz
author_rank: Super Contributor
timestamp: October 08, 2014, 07:56:22 am
content: Quote from: IanB on October 08, 2014, 02:13:45 amThe older I get the less I underestimate their stupidityWhen I started you had to be interested in the subject and relatively intelligent. Nowadays you only need to be interested in making a living, and the mantra is "everybody should be taught how to code".Such people should be kept away from keyboards, in the same way I should be kept away from javelins and discuses (discusi?).QuoteWell, it depends on the job, of course. Bad analogy, of course! A better analogy would be Java=car and, for example, C++=track-laying vehicle.There are no silver bullets, however much salesmen and fanbois claim otherwise. Similarly there are few complete turds. (But if C++ is The Answer, I think The Question ought to be revisited)When I first used Java (in 1996/1997), I was stunned at the speed with which many usable libraries became available, and the ease with which multiple librariesfrom multiple sourcescould be simply bolted into the same application - and "just work". That was something that C++ had failed to achieve in the 10 years it had been around - and arguably is till true to some extent.Java (and C#) strike a very good balance between rigidity (e.g. you can't cast a horse into a tank), expressivity (e.g. covariance and contravariance), and not having to fight with irrelevancies implementation artefacts (e.g. GC, although you still have to watch out for self-inflicted "data cancer" and a few corner cases). Never underestmate the power of "control-space" in advanced invironments!Having said that, the unwise overuse of reflection (in the guise of dependency injection) is starting to negate those advantages.It is the combination of expressivity, extendability and removal of implentation artefacts that makes the Java class environments so powerful - in the sense they enable larger projects and systems to be tackled. Just as procedural HLLs enabled larger systems than assemblers and macrocodes.

author: miguelvp
author_rank: Super Contributor
timestamp: October 08, 2014, 08:27:35 am
content: Of course that's your opinion. I've been using C++ for the last 28 years or so, and not once I found it constraining in any way.

author: tggzzz
author_rank: Super Contributor
timestamp: October 08, 2014, 08:54:51 am
content: Quote from: miguelvp on October 08, 2014, 08:27:35 am"Horses for courses", of course, and for some purposes it is the most appropriate technology.I wouldn't regard C++ as "constraining" any more than C is "constraining". However, IMNSHO, C++ is not as "enabling" as Java/C#/Smalltalk/Objective-C.

author: miguelvp
author_rank: Super Contributor
timestamp: October 08, 2014, 09:18:24 am
content: Enlighten me what those can do to enable me more than C++/11.

author: nctnico
author_rank: Super Contributor
timestamp: October 08, 2014, 10:06:36 am
content: Quote from: miguelvp on October 08, 2014, 09:18:24 amI'm not quite sure whether Java/C#/Objective-C are a step up. I do like to take a look a Lua for embedded software at some point. One of the problems I see with C and less with C++ is that you still need to keep track of variables, types, etc. A more protected environment like a script language run as bytecode (like Lua) would allow to concentrate on implementing the 'business logic' of a piece of software instead of having to worry about cleaning up variables and keeping track of memory. When I program in C++ I try to avoid using pointers as much as possible. I have a habit of checking input value ranges on every module's API and/or public members of a class.

author: tggzzz
author_rank: Super Contributor
timestamp: October 08, 2014, 10:48:30 am
content: Quote from: nctnico on October 08, 2014, 10:06:36 amI'd be reluctant to consider Java/C# for embedded small systems, despite the claims of the JavaME salesmen. Lua does look attractive in this area.QuoteIt is difficult to avoid pointers (or the semantic equivalent references) in OOP programming. It is less difficult if you subset C++ so that you are only using ADT style programming, i.e. not far off C-with-classes. But that, of course, will tend to preclude using many useful libraries, forcing re-invention of yet another wheel.

author: tggzzz
author_rank: Super Contributor
timestamp: October 08, 2014, 10:59:13 am
content: Quote from: miguelvp on October 08, 2014, 09:18:24 amNothing, in the sense that it is possible to ride a pushbike from Ireland to India. (As did Dervla Murphy in 1963, famously described in her first book "Full Tilt").But choosing the faster development tools (or transportation) takes up less of your remaining life. Concentrating on implementation artefacts at the expense of the problem you are trying to solve is rarely a good tradeoff. Unless, of course the journey is more important than the destination.I don't like reinventing wheels. I like solving newer bigger problems. That's what C++ prevents.(BTW, are there anyfully compliantC++11 compilers yet? IIRC it took5 yearsfor the first full C++98 compiler to appear. I wonder if the first full C++14 implementation will appear before I retire?)

author: Wilksey
author_rank: Super Contributor
timestamp: October 08, 2014, 12:29:03 pm
content: I very rarely use C++ for windows dev unless I need cross platform, even then it's via either QT or WX.Java holds a large place in the developer world with C# rising.Look at the TIOBE polls (http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html).I use C nearly every day for embedded work, I don't think you will ever find a more popular language for general programming, for nearly every platform if not every platform there is a C compiler.What I find funny is that 20-30 years ago nearly every machine you bought came with a version of BASIC, and now BASIC is quite low down the food chain (according to the TIOBE list).I can't say there is a "right or wrong" language to use for a particular job, if you are used to it, i.e. programming in C/C++ for 30 years, your obvious language of choice is going to be C++ unless a very good reason prevents you from using it.If you find a language that helps you work faster for quick RAD apps (mine is C#) then use it if it is capable of doing the task.

author: miguelvp
author_rank: Super Contributor
timestamp: October 08, 2014, 02:38:02 pm
content: Quote from: tggzzz on October 08, 2014, 10:59:13 amI can't imagine an example that C++11 prevents me from doing, just because you don't know/like or use the language correctly, it doesn't make it a blocker. And yes, there are fully compliant compilers. But of course MS had to add their flavor for use in WRT that expands the language and specially tailored for WRT for their whole .NET, ActiveX, COM etc, that actually is not too bad (I mean the extension they introduced in their implementation). Win8 is a totally different beast, but you know, at least it's finally evolving.

author: vvanders
author_rank: Regular Contributor
timestamp: October 09, 2014, 02:26:33 am
content: Quote from: nctnico on October 08, 2014, 10:06:36 amMost of what makes C# a step up is the environment and the rapid UI tools around it.I've used Lua in embedded-like projects(~16mb total system memory) to great success. It's got a very wide adoption in game dev circles which usually care very much about execution speed and memory footprint.

author: ruffy91
author_rank: Regular Contributor
timestamp: October 09, 2014, 05:01:46 am
content: I really like python as an OOP. It's easy to learn and harder to make errors than in other languages. Just to throw in another language in the mix.

author: jeremy
author_rank: Super Contributor
timestamp: October 09, 2014, 07:13:29 am
content: I'll throw my vote in: Python for anything where speed is not critical. Otherwise c++11 or C where that is not available.Also, while I appreciate it is not for everyone, complaining that you have to manage types and memory in c++ doesn't make much sense. It is no accident and very specifically designed into the language, because it allows the optimiser to do things that would not be possible in a less strongly typed language. In Java, a 32 bit integer requires 192 bits of memory. In c++, a 32 bit integer requires 32 bits of memory. Seehttps://blogs.oracle.com/jrose/entry/fixnums_in_the_vmIf you want to write something that is truly fast (linear algebra operations, real time graphics, JIT compiler, etc), pretty much your only choices are c, c++ or assembly. Often a mix of all three are used. I believe Linus Torvolds said that in some cases he optimises down to the point where he is shuffling instructions so that they enter the pipeline in a better order. That's the sort of performance I'm talking about here. If you give up strong types and manual memory management, you can't have that level of control anymore.

author: miguelvp
author_rank: Super Contributor
timestamp: October 09, 2014, 07:35:29 am
content: Quote from: vvanders on October 09, 2014, 02:26:33 amNot sure what game dev circles. Maybe mobile because on consoles it's all C++ and now C++11.

author: jeremy
author_rank: Super Contributor
timestamp: October 09, 2014, 07:38:20 am
content: Quote from: miguelvp on October 09, 2014, 07:35:29 amActually, lots of game engines use Lua because it is easily embedded in a C program. The Lua is usually only for the game logic, not the render loop or anything important like that. Cryengine and world of warcraft comes to mind as examples.

author: miguelvp
author_rank: Super Contributor
timestamp: October 09, 2014, 07:55:43 am
content: I guess if a game cycle is 33.333ms you can use that, but at 16.666ms at full 1080p well it's another ballpark when running on systems under $500 worth of BOM.But I get it that for just the game loops it could be used to drive the actual engine code, then again most studios have their own scripting languages tailored for their specific game.Just look at PS3/360 games 8 years ago and the last ones using the same hardware. 8 years of code optimization tailored to a specific hardware platform does that.

author: _Sin
author_rank: Regular Contributor
timestamp: October 09, 2014, 08:11:07 am
content: Some studios/engines might have a custom domain specific language (with special mention for those utilising a graphical system rather than text-based programming), but these days many are almost certainly using something standard.Our engine (running a game engine team being my day job!) has been used in about 200 titles so far, and it's written primarily in C++, with bits of asm, scripting in Lua and tools in C#.

author: tggzzz
author_rank: Super Contributor
timestamp: October 09, 2014, 08:48:27 am
content: Quote from: vvanders on October 09, 2014, 02:26:33 amThis is spot-on, is equally true with Java, and has to be experienced to be believed. It is also a strong reason not to create another crappy domain specific language (DSL).There is zero possibility that a C++ environment could ever have a decent refactoring browser with "control-space" and "rename this method and all references to this method". Why? Because of the extreme difficulty of accurately parsing C++ source code, particularly when macros (as they always are) are included in the equation.

author: tggzzz
author_rank: Super Contributor
timestamp: October 09, 2014, 08:49:38 am
content: Quote from: ruffy91 on October 09, 2014, 05:01:46 am... except when you copy/paste, get the indentation wrong, and it still compiles perfectly.

author: tggzzz
author_rank: Super Contributor
timestamp: October 09, 2014, 08:56:09 am
content: Quote from: jeremy on October 09, 2014, 07:13:29 amC++ is anuntypedlanguage, in contrast to Java/C# etc. If you don't believe that, then if you look at a chunk of memory and see 0xdeadbeefcafebabe, please tell me with certainty whether that is a pointer, an integer, a car, a bitvector... With Java/C# there is always an associated explicit definition of what it is, a pointer to the class definition.With C++ you have to be content with saying "I'm going to interpret it as a car, since that's what my code thinks it ought to be".

author: tggzzz
author_rank: Super Contributor
timestamp: October 09, 2014, 09:06:03 am
content: Quote from: jeremy on October 09, 2014, 07:13:29 am...and you have to do it all over again with the next generation of processor. And again. And again.In contrast Java's HotSpot looks at what code is actually being executed (cf what the compliler can guess in the presence of having be pessimistic because of aliasing), and optimises the shit out of that. And when a new processor comes along, your workload is precisely zero, because HotSpot does it all for you. C# still has the aliasing problem, but does optmise for a specific processor when the assembly is installed. (Probably one reason why Windows updates take soo long to complete)Interestingly when the same HotSpot techniques were applied to C/C++ code they radically improved the speed of +O2 and +O4 C/C++ code. Even running post-compiled code on anemulationof processor X was as fast or faster than running the code on the same processor X. Look for HP's Dynamo compiler for details.

author: jeremy
author_rank: Super Contributor
timestamp: October 09, 2014, 09:47:04 am
content: Quote from: tggzzz on October 09, 2014, 08:56:09 amWell, if we are going to get technicalthere isn't a good definition of what "strongly typed" or "untyped" even means. Ultimately the type system in C is as present as you would like it to be. You can pass around void* for everything if you like, but you are fighting the optimiser.Quote from: tggzzz on October 09, 2014, 09:06:03 amYep, that's the point. Different processors are different? If you wanna squeeze out every last drop, that's what you have to do. And you also need a language to write the JIT compiler in.

author: tggzzz
author_rank: Super Contributor
timestamp: October 09, 2014, 10:06:39 am
content: Quote from: mojo-chan on October 09, 2014, 09:46:52 amSo it only gets is wrong 20% of the time? In that case you still have to go and manually inspect all the changes it made, which defeats the purpose.My point stands.

author: tggzzz
author_rank: Super Contributor
timestamp: October 09, 2014, 10:15:40 am
content: Quote from: jeremy on October 09, 2014, 09:47:04 amJust so. But regarding C/C++ as strongly typed (or even typed) is getting dangerously close to unhelpful Humpty-Dumpty speak, viz. "When I use a word it means just what I choose it to mean — neither more nor less."QuoteThe point is that such mechanical operations should (almost always) be left to robots, so that humans can concentrate on things that robots are incapable of doing. Humans should choose whatever mechanisms techniques and tools enable robots to take more drudgery off their hands. That's why HLLs have almost completely replaced assembly and macrocode languages. And why HDLs have replaced fuse maps.

author: nctnico
author_rank: Super Contributor
timestamp: October 09, 2014, 11:04:01 am
content: Quote from: vvanders on October 09, 2014, 02:26:33 amPerhaps but then you are locked into a Windows environment forever. There are plenty of RAD tools for QT and WxWidgets which don't have that problem.Quote from: tggzzz on October 09, 2014, 08:48:27 amEclipse CDT does refactoring in C++ just fine. I'm using it every once in a while.

author: tggzzz
author_rank: Super Contributor
timestamp: October 09, 2014, 11:44:33 am
content: Quote from: nctnico on October 09, 2014, 11:04:01 amPerhaps you are only using it for "simple cases", maybe the "easy 80%"?C++ is a real pig to parse correctly. Looking at various usenet newsgroups inhabited by people who have worked with C/C++ for decades and who also serve on various standardisation committees, even they haveunresolveddifficulties sometimes! Ifyouneed a language lawyer to determine the interpretation, thenIcan probably find another language lawyer to provide a differing and equally valid interpretationNot good.

author: _Sin
author_rank: Regular Contributor
timestamp: October 09, 2014, 12:07:25 pm
content: Quote from: tggzzz on October 09, 2014, 11:44:33 amYour original assertion was that there was 'zero' chance of an IDE doing 'decent' refactoring. Sadly 'decent' is subjective so you can always argue that it doesn't meet your personal definition and be 'right', but for most reasonable people an implementation that works in the majority of cases they ever meet would qualify just fine.You can actually do some pretty cool things by coupling an IDE with a modern C++ front-end like Clang.Which is not to say that other languages don't lend themselves better to this sort of thing, but I think you're being disingenuous with regard to what you can actually do with C++ these days.

author: HackedFridgeMagnet
author_rank: Super Contributor
timestamp: October 09, 2014, 12:21:45 pm
content: QuotePretty sure 'int' is 32 bit. It probably takes 32 bits of memory.'Integer' is a class derived from object, this is why is it bigger.'integer' doesn't exist in Java.I think the only fair comparison is with Java 'int'.

author: jeremy
author_rank: Super Contributor
timestamp: October 09, 2014, 12:33:22 pm
content: Quote from: HackedFridgeMagnet on October 09, 2014, 12:21:45 pmDon't you at least need to expose it to the mark/sweep garbage collector? And any reference to the integer (a pointer) would take up some space in RAM, since it's location can't be known at compile time I think (is there compile time in java? just JIT time and runtime I think).I don't think the comparison is fair between C++ int and Java int because, for instance, you can't put a Java int in a collection, but you can put a C++ int in a std::vector or std::map just fine.But Java is not my strong suit, so I'm happy to give you the benefit of the doubt

author: tggzzz
author_rank: Super Contributor
timestamp: October 09, 2014, 02:12:22 pm
content: Quote from: _Sin on October 09, 2014, 12:07:25 pmOnly to some extent.To me "decent" starts with "gets it right all the time without omissions or other mistakes". Anything less is a mere semi-random permutation of my source code - which most people would regard as unacceptable.And I'm presuming that the programmer is using all the facilities in the C++ language, not a small convenient subset.

author: tggzzz
author_rank: Super Contributor
timestamp: October 09, 2014, 02:19:16 pm
content: Quote from: jeremy on October 09, 2014, 12:33:22 pmNo you don't. When an "int" in memory then it is part of an object defined by a class, and only that object visible to the GC. Since the GC knows the objects fields, it avoids treating an int as a pointer.QuoteYou can have many "ints" inside an object (e.g. an Array object or a user defined object) and each int only occupies 32 bits. The containing object has its own single class reference, of course.

author: miguelvp
author_rank: Super Contributor
timestamp: October 09, 2014, 02:23:39 pm
content: Every tool can be misused, it's not a problem with the tool but the operator handling the tool.Like _Sin mentions give Clang a try it's been C++11 feature complete since over a year and a half and C++14 feature complete since last year. And developed by people paid to do so.Even enums can be strongly typed.

author: tggzzz
author_rank: Super Contributor
timestamp: October 09, 2014, 03:01:42 pm
content: Quote from: mojo-chan on October 09, 2014, 02:23:22 pm"Control-space" (=tab, I presume) is an incredible powerful feature. In Java it enables you to explore code easily by asking questions such as "given that object, what is the exhaustive list of things could I do with it" - and you can reliably do thatwithout executingany of your code.In contrast reflection and immediate execution are "only" relevant in executing programs.

author: jeremy
author_rank: Super Contributor
timestamp: October 10, 2014, 06:52:07 am
content: Quote from: tggzzz on October 09, 2014, 02:19:16 pmRight, but not in a generic container or user defined templated object. You can't store an int in a Vector without it being boxed to an Integer. Seehttp://mindprod.com/jgloss/intvsinteger.htmlandhttp://illegalargumentexception.blogspot.fr/2008/08/java-int-versus-integer.htmlUnless that has changed recently. Pretty sure I couldn't last year when I did some android work.

author: tggzzz
author_rank: Super Contributor
timestamp: October 10, 2014, 08:07:58 am
content: Quote from: jeremy on October 10, 2014, 06:52:07 amCorrect, and it hasn't changed. But the context of this subthread has been snipped: that a 32bit int occupies 192bits. And that's incorrect since you can't have a "naked" int in memory, and adding an int to an existing class only adds 32bits of memory.

author: jeremy
author_rank: Super Contributor
timestamp: October 10, 2014, 08:11:13 am
content: Quote from: tggzzz on October 10, 2014, 08:07:58 amFair enough, but I originally meant Integer (as in the boxed type) not the primitive because you can't use the primitive and have everything work.My point was that by using only the primitive int, you lose some of the standard library in Java. For using a primitive int in C++, you don't lose templating or containers.

author: miguelvp
author_rank: Super Contributor
timestamp: October 10, 2014, 08:29:25 am
content: From:http://www.techrepublic.com/article/the-geekiest-tech-jokes-on-the-internet/?tag=nl.e101&s_cid=e101&ttag=e101&ftag=TRE684d531QuoteMy favorite one from that link:Quote

author: SirNick
author_rank: Frequent Contributor
timestamp: October 10, 2014, 08:44:53 pm
content: Better than those people that tell TCP jokes, then go "get it? get it? get it?" until you say "YES. I GOT IT."

author: miguelvp
author_rank: Super Contributor
timestamp: October 10, 2014, 10:53:23 pm
content: Quote from: SirNick on October 10, 2014, 08:44:53 pmBe careful not to SLIP while you PPP, get it? get it? get it?Made that one up myself long ago and it used to be my signature on usenet, or was it "when you PPP" don't recall.Funny you can't find it even in Google and not everything is invented, but how will use SLIP or PPP? maybe mobile phones?

author: nctnico
author_rank: Super Contributor
timestamp: October 10, 2014, 11:09:12 pm
content: AFAIK mobile phones still use PPP to get internet access. A couple of years ago I built a tablet with 3G modem and I had to use PPP over a serial port to get internet from the 3G modem.

author: tggzzz
author_rank: Super Contributor
timestamp: October 10, 2014, 11:27:02 pm
content: Quote from: jeremy on October 10, 2014, 08:11:13 amI'm prepared to lose that, since the reason that is lost is to ensure all sorts of pains, errors, nightmares are also lostPersonally I'd prefer the int/Integer thing to have been "inverted", as it was in Smalltalk 33 years ago. Then, in effect, everything was an Integer but there was a hidden optimisation that small integers were invisibly, silently and transparently optimised to ints (and ditto back to Integers when they grew larger). But that isn't going to happen.As for templates, as far as I can tell (since I gave up on C++ before they existed), the combination of templates and exceptions results in some very non-entertaining compiler error messages and core dumps. It always struck me as remarkably bad that C++ took so long to get container classes, when other contemporary languages had fully-fledged variants available from the first release.

author: vvanders
author_rank: Regular Contributor
timestamp: October 11, 2014, 04:54:09 am
content: Quote from: nctnico on October 09, 2014, 11:04:01 amQT I buy but wxWidgets? Eargh, I've spent many years working with it(not much recently) and it's the opposite of RAD.Quote from: nctnico on October 09, 2014, 11:04:01 amAt the risk of kicking off another religious debate Eclipse is a horrible IDE, poorly intuitive, buggy as all hell(doesn't detect file changes in win32). That said I've yet to see VS(>2012) misparse any autocomplete, and that's in some very complex codebases some near the million loc size.

author: nctnico
author_rank: Super Contributor
timestamp: October 11, 2014, 10:17:29 am
content: I don't share your vision on Eclipse. Maybe you looked at a very early version 10 years ago but the current version detects file changes just fine. It does take some getting used to Eclipse because it has been setup for dealing with huge projects consisting of many sub-projects. It is therefore more complicated than Visual Studio. But once you get the hang of it, it works really well. It makes big spaghetti projects like the Linux kernel or a huge VHDL project managable.

author: tggzzz
author_rank: Super Contributor
timestamp: October 11, 2014, 11:10:36 am
content: Quote from: nctnico on October 11, 2014, 10:17:29 amI'll second that, and I have never seen the problems mentioned by vvanders.I cannot comment on VS, since I've only used that for one tiny program.

author: vvanders
author_rank: Regular Contributor
timestamp: October 11, 2014, 03:32:33 pm
content: Nope use it on a daily basis and it just doesn't play nice, at least on win32. Unfortunately it's required for some of the platforms we work on.It just seems like a poorly put together IDE. You can't reference relative files outside of the project without going through a multi-step process(1. Add file as absolute 2. Re-edit path 3. sub in ${project_loc}). Their find is sub-par(why do I have to expand a billion tree-nodes to get to the final source location if I have deep namespaces like you get in Java). Ctrl-Tab equivalent goes through order tabs are opened and not order of last edited which makes quickly switching between source files slow. Can't start a build if you haven't "edited" a file in eclipse so any edits outside of the editor require touching something in the editor before it will start a build, etc.I'm no stranger to high learning curve tools, if I'm on a non-win32 platform though I'll happily take VIM over eclipse.

author: nctnico
author_rank: Super Contributor
timestamp: October 11, 2014, 04:45:29 pm
content: You shouldn't add external files but import them. That way you can choose whether Eclipse links to them based on an absolute path or relative to the project. Note that Eclipse won't allow to use versioning on imported/external files.Regarding editing files outside Eclipse: enable the option 'Refresh using native hooks or polling' in the workspace settings. See:http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2Freference%2Fref-9.htm

author: zapta
author_rank: Super Contributor
timestamp: October 11, 2014, 06:49:44 pm
content: Quote from: tggzzz on October 09, 2014, 08:49:38 amPython almost always complies perfectly and that's the problem.

author: Stonent
author_rank: Super Contributor
timestamp: October 11, 2014, 09:26:09 pm
content: Whoa, this thread has gotten big...Quick question:In C# can you declare a const in your class and have all methods within that class use it without having to pass it into the class or do you just need to declare that const in main and pass it through to the method like MethodName(var1, var2, CONST1, CONST2, CONST3);Having it at the class level would make it nice to easily update, right now the constant is inside one of my methods, but I realized another method needed that info as well so I was going to move it outside the method. If it can be moved up to the class area and be usable without passing it into the method it would save me rewriting some code, but if it can't be done, or there's implications with doing this, I may just have to do it the long way.

author: HackedFridgeMagnet
author_rank: Super Contributor
timestamp: October 11, 2014, 11:31:38 pm
content: http://stackoverflow.com/questions/6373072/defining-local-variable-const-vs-class-constthat should answer some of your question. Class constants are fine.For 'global c style' constants I make up a public class with public constants so they are all in one place. then call something like Constants.SpeedOfLight or Constants.MaxThreadsBTW been using eclipse for years, for java, c, c++. I'll agree its not as slick as VS but it doesn't give me problems.QuoteUseful I didn't know that.

author: Marco
author_rank: Super Contributor
timestamp: October 11, 2014, 11:42:07 pm
content: Quote from: zapta on October 11, 2014, 06:49:44 pmC style commenting has the same problems (and solutions) as Python's indentation ...Python also got a bit better than it was in the past, they stopped allowing you to mix tabs and spaces in indentation.

author: VK3DRB
author_rank: Super Contributor
timestamp: October 12, 2014, 02:39:26 am
content: Quote from: tggzzz on October 11, 2014, 11:10:36 amEclipse has annoying bugs. I am currently doing the soul-destroying job of refactoring about 50,000 lines of frogshit written by an succession of so-called electronics engineers who had no idea about embedded C programming.On several occasions Eclipse chucked a wobbly and I lost work. Also sometimes for no apparent reason not all of the function calls, variables or constants get updated. The WinAvr compiler detects those. Maybe this mess of code is so convoluted and messed up, Eclipse is saying "You are abusing me. I'm out of here!" But I cannot complain about Eclipse - it is free and overall it is an invaluable tool for refactoring work created by dropkicks. It is a bit too Java-centric though; most most the nice add-ons are for Java applications.I use Atmel Studio and Notepad++ as adjunct tools to help with the refactoring. With all the tools, it is a doable job. It has taken me a month already and I am about 1/4 of the way through.

author: tggzzz
author_rank: Super Contributor
timestamp: October 12, 2014, 08:48:16 am
content: Quote from: Marco on October 11, 2014, 11:42:07 pm1) just so2) oh good grief! Not a case of reinventing the wheel, more a case of fitting an elliptical wheel! Some of us remember the original makefile format where spaces and tabs had different meanings; everybody using makefiles wasted some of their life over that misfeature.

author: miguelvp
author_rank: Super Contributor
timestamp: October 12, 2014, 09:06:04 am
content: Like everything else, only careless ones lost time. Cobol and Fortran were column based, and there was no confusion.Granted things have changed since then, but you gotta learn the rules to play the game

author: tggzzz
author_rank: Super Contributor
timestamp: October 12, 2014, 10:55:26 am
content: Quote from: miguelvp on October 12, 2014, 09:06:04 amBecause you couldseethe columns.You can'tlookatCode:hellohelloand tell whether or not there is difference between the two lines. You have to open an editor, move to the correct position, then move again and see how far the cursor moves.Try that with line-oriented editors, which were the norm when the original format was designed (even with screen editors, it is bad enough!)

author: miguelvp
author_rank: Super Contributor
timestamp: October 12, 2014, 11:11:41 pm
content: You have to use the right tools.

author: zapta
author_rank: Super Contributor
timestamp: October 13, 2014, 12:11:42 am
content: Quote from: Marco on October 11, 2014, 11:42:07 pmMy problem is more with the lack of static typing (that is, a compile time constraint on the types of arguments and variables). It is less readable IMO and defers much of the type checking to runtime (assuming the the code is covered).Last year I implemented an internal systems and did it in Python to speed up the development. After a week or so I realized that as the code becoming more complex the development slows and the code becomes less maintainable, so I rewrote it in Java and continued the development in Java.Static typing is a very strong language feature.

author: tggzzz
author_rank: Super Contributor
timestamp: October 13, 2014, 12:33:46 am
content: Quote from: zapta on October 13, 2014, 12:11:42 amI wholeheartedly agree.Static compile-time typing is an excellent form of self-documentation, easy way for the compiler to eliminate silly errors, and prerequisite for allowing an environment to guide you through other people's codebases including libraries.Strong run-time typing enables decent debugging technology, allows elimination of dangling pointers (though not "data cancer"), and enables all sorts of advanced programming techniques (some of which can be abused).

author: nctnico
author_rank: Super Contributor
timestamp: October 13, 2014, 10:33:19 am
content: Quote from: VK3DRB on October 12, 2014, 02:39:26 amFor large projects you may need to tweak the memory limits for the indexer otherwise it can't keep track of all the variables.

author: SirNick
author_rank: Frequent Contributor
timestamp: October 14, 2014, 07:33:44 pm
content: Ah yes. Taking memory management out of the programming language and putting it into the IDE where it belongs.

author: miguelvp
author_rank: Super Contributor
timestamp: October 14, 2014, 07:54:33 pm
content: How will the IDE know how the hardware is put together for the target device or how is it being used?Or the language for that matter, it should be up to the programmer.Edit: by programmer I mean the coder.

author: SirNick
author_rank: Frequent Contributor
timestamp: October 14, 2014, 08:43:53 pm
content: Just a tongue-in-cheek comment...I was referring to the popular opinion that modern HL languages are better than C/C++ because you're not forced to manage memory -- but, with a popular IDE, you have to (or might have to) tweak the memory management to support context sensitive completion for large code bases.IMHO, the IDE can and should use as much memory as it requires. I don't care. Just keep allocating more as necessary until I run out of RAM. If that happens, I'll add more or prune my project. But I like my languages to be lean and mean.

author: tggzzz
author_rank: Super Contributor
timestamp: October 14, 2014, 09:17:20 pm
content: Quote from: SirNick on October 14, 2014, 08:43:53 pmI don't think anyone has claimed that the C++languageis lean and mean.Personally I like my languages and run-time environments to be, to paraphrase Einstein, as lean and mean as possible, but no leaner and no meaner.That does, of course, presume there is a stated objective/purpose against which leanness/meanness can me measures - and implies different objectives/purposes are to be expected.

author: nctnico
author_rank: Super Contributor
timestamp: October 14, 2014, 09:33:27 pm
content: Quote from: SirNick on October 14, 2014, 08:43:53 pmThe creators of Eclipse and Java have put some conservative memory restrictions in place. If you Google for 'Eclipse more memory' you'll find several ways to allow Eclipse to use more memory and deal with exceptionally large projects.

author: vvanders
author_rank: Regular Contributor
timestamp: October 15, 2014, 12:36:47 am
content: Which has never been an issue with any other IDE that I've used on commercial projects(with codebases nearing the million loc).

author: nctnico
author_rank: Super Contributor
timestamp: October 15, 2014, 12:41:01 am
content: That may be but those probably wheren't written in Java running in a virtual machine (JVM)

author: VK3DRB
author_rank: Super Contributor
timestamp: October 15, 2014, 11:02:33 am
content: Quote from: nctnico on October 13, 2014, 10:33:19 amThanks for the tip. I might try that tomorrow at work. It might save time in refactoring.Speaking of which, I have found that almost EVERY line of the 50,000 lines needed refactoring. Entire functions have been rewritten to make them run efficiently. The goodness in all of this is maybe a sense of satisfaction at the end I have turned crap into clay, if I don't have a mental breakdown first. Also, the code will be maintainable from then on.

author: nctnico
author_rank: Super Contributor
timestamp: October 15, 2014, 04:25:40 pm
content: Working on crappy code can be a bitch. I once worked on software for which the author didn't know he could use multiple source files in a C project and he didn't like to put stuff in functions either. The end result was a single file with a few functions, even switch/case statements spanning thousands of lines. I printed everything (still on a matrix printer) and annotated everything by hand to identify the stuff I had to change. At some places there where chunks of code which I could replace with 3 lines of code which did exactly the same. Oh horror

author: VK3DRB
author_rank: Super Contributor
timestamp: October 16, 2014, 10:14:54 am
content: Quote from: nctnico on October 15, 2014, 04:25:40 pmThank is pretty bad. But what I am dealing with is much much worse. Seriously so.Examples:(a)tHisisa_FuntTHAT_IMADE_pm(unsigned char a, unsigned char p).(b) A function calleddo_nothing(), which contains a timer loop and a watchdog timer reset routine.(c)rrunDAIG(), where DAIG is meant to be Diagnostics.(d) Putting a watchdog reset in a 1ms timer interrupt. Tossers!(e) About 200 files all up - 100% of which had names which meant nothing or were ambiguous.(f) Functions put into random files.(g) Extreme abbreviations likeget_prdc_get_tm_sm()where the acronyms have no logical meaning.(h) 5000 lines reduced to about 700 lines yesterday. Cut 'n paste kiddies.(i) Up to 6 levels of Gets and Sets all over the place. Bloody Windoze OOP programmers.(j) #defines without any case consistency. eg a_COnstant, A_constant, acon, Acon, whatever they wanted. You cannot easily depict a constant from a variable.No joke, this is a nightmare. 50,000 lines worth. Every line of code has had to be refactored. There is more spaghetti in that code than in a bolognese for a large Italian wedding.The good news is the more I do the less I have to do. The other good news is if there are people let loose out of universities writing this sort of frogshit, there must be a demand for people to refactor code. I feel like charging $200 per hour to do this.... $100 for my pocket and $100 for psychological rehab.The other good news is the weekends.

author: tggzzz
author_rank: Super Contributor
timestamp: October 16, 2014, 12:22:04 pm
content: There's another way in which you can come across incomprehensible source code inanylanguage, although C is the most common. Starting point: regarding C as a portable assembler. The point is to realise that the C (or whatever) code isn't the actual real source code, but C is being used as an intermediate portable code. Instead the "real source" code is written in another language, and the C is autogenerated from that "real source" code.I first saw that in the 80s, where Kyoto Common Lisp was compiled down to C.Nowadays the starting point is typicallyscrotty little Domain Specific Languages written by computer software graduates who don't feel fulfilled unless they are implementing a compiler, orFinite State Machines, sometimes generic, sometimes highly specialised in which case they are an example of a DSLA neat "job preservation trick" is to supply a project's deliverables in the form of the incomprehensible C "source code", so that any changes imply re-hiring the originating company or contractor.Apart from that, I suspect the worst C code I ever saw was actually assembler converted back to C, for reasons unknown.

author: vvanders
author_rank: Regular Contributor
timestamp: October 16, 2014, 05:57:29 pm
content: There's nothing wrong with a DSL to do code gen. I much prefer it to overly complex templates or a mess of macros.That said its easy to do wrong but that could be said about 90% of C/C++.

author: tggzzz
author_rank: Super Contributor
timestamp: October 16, 2014, 10:29:14 pm
content: Quote from: vvanders on October 16, 2014, 05:57:29 pmWell, comparing a good DSL to typical templates or macros isn't much of a contest - and I'd agree with you. The problem is that most DSLs aren't good.Usually they "start small" as a means of adding scriptability to a compiled application, and usually the reasons for that are bogus. Then something can't be expressed/done in the existing DSL, so a hack is added on. And then another. And another. And soon the DSL has grown like Topsy so that nobody, including the inventor, can quickly and intuitively grasp the interaction between all the misfeatures.(And I wouldn't dream of comparing that to C++, oh no)And, of course, there is zero tool support since it isn't needed for a tiny add-on to the real application.And you can't find anyone external with experience in myScrottyDSL so you have to train people. Except that anyone with an ounce of gumption won't want to tie their career prospects to a non-portable skill.Contrast that with having a library expressing the same concepts. Tool support comes for free, developers already know the language and toolset so no training, and you can get the best rather than the dullards.I once made the mistake of creating a scrotty little DSL for a 2 week job. I quickly realised I should just have used Forth (in that case), and vowed never to make a similar mistake again.I have, however, repeatedly seen projects and companies spending many years going down the blind alley of custom DSLs - one to the extent that it actually killed the company!

author: HackedFridgeMagnet
author_rank: Super Contributor
timestamp: October 16, 2014, 10:43:23 pm
content: QuoteWow some impressive stuff there. A worthwhile hijack.For code like that you really need an IDE to find your way around it.Does the project actually work?does d) call b) ??!! they are both WTF by themselves.I guess 6 levels of Gets and Sets might be ok if it was an OO language.I can't remember ever seeing code that crazy in an actual project, and I have been on the receiving end of a few still born projects. A pet hate is badly written MACROs, they make life very hard.Got any more juicy examples?

author: vvanders
author_rank: Regular Contributor
timestamp: October 17, 2014, 01:26:42 am
content: Quote from: tggzzz on October 16, 2014, 10:29:14 pmI guess we just have different experiences, I find protobuf, flatbuffers and a few other DSL based code gen frameworks to be a lifesaver. It also depends on how you build your DSL, I find that ANTLR with either the C# or Java runtime to work particularly well.Now writing your own DSL parser, that's the path of madness. If I'm building a project where I need to do a lot of boiler plate code(interop between C++/C# or other languages) I find DSLs to be a life saver.

author: tggzzz
author_rank: Super Contributor
timestamp: October 17, 2014, 08:39:34 am
content: Quote from: vvanders on October 17, 2014, 01:26:42 amThe differences aren't so great: you have chosen decent DSLs with limited ambitions, and used them only where they shine.The trouble is that many DSLs, and more importantly DSL advocates, aren't so knowledgable and disciplined.

author: VK3DRB
author_rank: Super Contributor
timestamp: October 18, 2014, 12:13:26 pm
content: Quote from: HackedFridgeMagnet on October 16, 2014, 10:43:23 pmThe project worked reasonably well after I spent 5 months fixing 40 bugs in the inherited code.Other juicy examples...Yesterday I found ticks and tocks all over the place as variables and functions names.is a tock?! They meant nothing special, eg: not alternate timer ticks. They were used to refer to timer ticks in some obscure way. I got rid of all the tocks by turning them into ticks and sensibly renaming some functions and variables or deleting others as dead code. Except there is one tock I missed coming across... the completetockwho wrote that code.Another line of code I found, which appears in a few similar ways in different files....error_code = the_errorcode;

author: sunnyhighway
author_rank: Frequent Contributor
timestamp: October 18, 2014, 01:46:35 pm
content: Quote from: VK3DRB on October 18, 2014, 12:13:26 pmLet me guess...error_codehas a global scope.

author: amyk
author_rank: Super Contributor
timestamp: October 18, 2014, 02:37:28 pm
content: Quote from: VK3DRB on October 16, 2014, 10:14:54 amThat sounds likehttp://thedailywtf.com/

author: VK3DRB
author_rank: Super Contributor
timestamp: October 18, 2014, 10:56:54 pm
content: Quote from: sunnyhighway on October 18, 2014, 01:46:35 pmGood guess, but no.the_errorcodewas passed on the stack into the function anderror_codewas locally defined. BOTH were used. Cleaning up the function removed the local one and the passed in one was renamed.

author: linux-works
author_rank: Super Contributor
timestamp: October 19, 2014, 03:28:23 pm
content: Quote from: zapta on October 13, 2014, 12:11:42 amI used to think so, but not so much anymore.I just completed 2 weeks of python classes at work, given by a python core dev (raymond H., fairly well known teacher, developer and evangelist). I was skeptical, being a 25+ yr c programmer. at the end of the 2 weeks, I was pretty convinced that python is the Next Big Thing(tm)java? let it die already. too complex and never really delivered on 'portability' (look at all the versions and problems they have). python is much simpler, does have all the fancy language features you'd need and really is portable (ignoring the v2.x and v3.x stuff for now).I'm also finding that python is being taught to corporate guys (like me) in a very serious way. I'm at cisco right now and they are sending a lot of their engineers to python training. we are even going to convert a lot of our test code from tcl over to python (dumping tcl is a good move, of course). I'm seeing this in the industry all over; python is being accepted very quickly. its very useful to list it on your resume/cv and so I'm now happy to learn and use itthere are some cultural things that are interesting, though: it seems that people from india are very heavily invested in java, certs for the language and this probably won't change quickly. otoh, in the US, we are a bit less locked-in to java and I see python 'winning' the war. if 2 groups in the same company start to work on a new project, the india group will usually pick java and the US group will (more often) pick python. whoever gets there first gets to continue on (lol). it may be some time before india stops being java's b*tch and sees the light, but I do think it will happen eventually.if you get a chance to take some python courses, do so! go in with an open mind and I bet you will see the benefits of the language and its huge runtime libr. (built in and contrib) richness.

author: VK3DRB
author_rank: Super Contributor
timestamp: October 20, 2014, 11:57:59 am
content: Am at the half way point! Whoo hoo... about 24,000 lines of frogshit has been refactored. Another 6 weeks and it should be finished if I don't become a serial killer of slapdash engineers first.Today I found a sprintf() for a simple conversion from an integer to a 5 character string in an area where speed was critical. To make matters more silly, there was already a function that would do that exact conversion efficiently sitting two functions away.Also found a byte XOR calculator where the passed characters into the function were typed as chars and the XOR calculator was typed as an unsigned char. I don't like XOR as a so-called "checksum" as much as summation, because unlike with summation, XOR of two consecutive bytes of the same value produces 0x00.The original programmers called their XORed bytes CRC's quite often in function names, variable names and in the comments. It is obvious they did not know what a CRC actually is, and they would have done well to have used it.

author: zapta
author_rank: Super Contributor
timestamp: October 22, 2014, 03:52:24 am
content: Quote from: linux-works on October 19, 2014, 03:28:23 pmI can sell you the Bay Bridge ;-)I know of at least one Python project by a core Python developer that was rewritten in Java for maintainability. It's a glamorous scripting language, not the first and not the last.http://en.wikipedia.org/wiki/Scripting_language

author: linux-works
author_rank: Super Contributor
timestamp: October 22, 2014, 04:21:04 am
content: sure, not the first or last, but its getting traction and being taken very seriously. quite a lot of companies are investing in it, in training for their people (which I find surprising, given how cheap companies are and how they hate to spend money on training, overall).if you know java, you will probably want to continue with it, because you were trained in it and it did take a lot of training.if you don't know java then python is, imho, probably the better thing to write in. java, to me, seems way too complex for what it should be doing. (I never quite got what it was supposed to be good at, anyway, but ...)if java loses popularity, I'd be quite happy to see python pick up the slack. the language is just plain easier, and the culture is nicer, too.I'm convinced that you can write big and complex apps in both and if you are good, either will be supportable and debuggable. but java's learning curve is much higher and there's more stuff you have to deal with and worry about. python has no build system, it just plain runs (lol). its funny, but I kind of like that. big change from 'ant' and all that xml build file crap.

author: miguelvp
author_rank: Super Contributor
timestamp: October 22, 2014, 04:25:08 am
content: Also you can import C++ or C modules in python, so you can get performance as well.

author: tggzzz
author_rank: Super Contributor
timestamp: October 22, 2014, 01:09:05 pm
content: Quote from: zapta on October 22, 2014, 03:52:24 amYes indeed. Many people have fallen into that trap, and many more will.Techniques that work well with small programs often don't scale. In particular they run into difficulties whenproof is required that certain methodologies have been followedmultiple people simultaneously creating a large applicationintegrating new components (i.e. not battle-proven libriaries) written in haste by other people/companiesmaintenance of codebases written 10 years ago by people/companies that have gone away

author: VK3DRB
author_rank: Super Contributor
timestamp: October 23, 2014, 10:02:13 am
content: The language does not matter!You can make poetry or garbage from any language, whether it be C, assembly, C++, C#, Python, JAVA or any other language.The triple A attributes to writing good code is Attitude, Aptitude and Ability. If any of those are lacking, rubbish will be the result; you get high levels of all three from an engineer or programmer and you have a winner.

author: tggzzz
author_rank: Super Contributor
timestamp: October 23, 2014, 10:43:10 am
content: Quote from: VK3DRB on October 23, 2014, 10:02:13 amThe language is not absolutely good/bad, but thelanguage definitely does mattersince it increases/decreases the probability of a good result.A good language (including library where appropriate) allowseasy expression of the algorithm used to implement the program's objectives and requirementssimple easily-understandable correspondance between the requirements and the codeavoids unexpected behaviouravoid behaviour that can only be understood upon close inspection by users with exceptional experienceprevents common errors from resulting in code that executes without visible errorsA bad language (including library where appropriate) allowsrequires contorted tricks to implement the algorithm used to implement the prograb's objectives and requirementshas unexpected behaviourhas behaviour that can only be understood upon close inspection language and implementation expertsallows common errors to execute without visible errorsAs a humourous example of language mattering, can you imaging whispering sweet nothings to a lady such as "you have beautiful bust-warts"? (Brustwarze is German for nipple, and guess what the literal translation is). Or try pronouncing the German for "butterfly" (Schmetterling) and seeing if it invokes a feeling of something delicate and beautiful!

author: VK3DRB
author_rank: Super Contributor
timestamp: October 23, 2014, 01:16:02 pm
content: Quote from: tggzzz on October 23, 2014, 10:43:10 amAgreed, the language matters to some extent, but is a poor second to the three A's. At the moment I am working with refactoring coding mostly in C where 4 of the 5 predecessors had at least 1 of the 3A's missing and a maybe a few screws loose as well. However, one predecessor was very good and wrote crisp clean efficient C code, easy to follow and beautifully commented.That programmer included some AVR assembly language files, three which I came across today when I noticed that my Windows 7 sees a .asm file, it calls the file "Assembler source file". There is no such language as assembler and there never has been. The correct term isassembly language. Notepad++ used to call assembly language "assembler" until I got the authors to change it around version 4. I am not sure whether it is Visual Studio, AVR Studio, some other compiler or Windows Explorer incorrectly identifying the .asm file.

author: tggzzz
author_rank: Super Contributor
timestamp: October 23, 2014, 02:56:53 pm
content: Quote from: VK3DRB on October 23, 2014, 01:16:02 pmWhere refactoring is concerned, C offers pretty dismal and error prone facilities - Java is much much better. Yes, I appreciate Java doesn't solve all the world's ailments, but in this respect it is orders of magnitude better.Why is C so bad?Well, let's start with trying to determine all the places a function is called. Potentially very error-prone, given the ability of the macroprocessor to completely change the source code before it gets to the "real" compiler. Yes, I have seen some truly horrible things done with macros.Next let's move onto trying to determine which bits of code can alter a specified variable. Consider (void *) - enough said. It is impossible to solve accurately - it is the aliasing problem that plagues attempts to have globally optimising C compilers and linkers. The obvious manifestation is the plethora of mutually-incompatible compiler/linker flags that attempt to allow the programmer to allow the compiler to optimise.And time's run out, so I won't mention some of the others!So good luck with refactoring C - in Java the "refactoring browsers" in IDEs are a very significant advantage. Refactoring is the norm and is routinely done on a day-by-day basis.And that's an excellent example of where languages can help/hinder.QuoteYou can't polish a turd, whatever language it is written in. But some languages at least put the turds in plastic bags.

author: linux-works
author_rank: Super Contributor
timestamp: October 23, 2014, 03:15:32 pm
content: a lot of what you just said is all based on TOOLS issues, not so much language issues.with a good ide, all languages are refactorable and you can find refs to functions, vars, externs, etc.a lot of what java fans think is good about java is quite often about the ide they learned on!don't get me started about makefiles (their equiv) on java. what a horrible mess! makefiles in c have been around so long, its a proven technology and not hard to master. ant and other build systems for java are horribly complex and take a long time to learn to do them well.I love that python has no build system and no need for it. no compilers, and yet it runs very fast if you do things in the proper pythonic wayc++ always annoyed the hell out of me. I love C since its been around forever, its used to write os's, networking stacks and most of the unix cmds you use every day. for scripting, though, I am migrating from bash to python. java was an interesting experiment, but I consider it like pascal: great to learn stuff on, but I hate having to support other peoples' code when they use java. and its mostly the new generation that insists on java; us oldtimers still mostly reject it (personal experience working in the bay area, fwiw).

author: tggzzz
author_rank: Super Contributor
timestamp: October 23, 2014, 03:37:06 pm
content: Quote from: linux-works on October 23, 2014, 03:15:32 pmNo. The macroprocessor and aliasing issues are solely in the language, and in general tools cannot get around the issues. The tools can help in special cases where disciplined developers only used a restricted subset of the language's capabilities - but in that case it probably won't be necessary to do refactoring in the first place.The aliasing issue is very real and is a very significant problem, and significantly restricts the ability of compilers to do optimisations that are trivial in other languages. The workarounds (use of myriads of compiler flags) are error prone. If youor your libraries' useraccidentally uses the valid-but-inappropriate-combination of flags, a presumption is violated and their program will produce subtle errors. Perhaps the user will notice the error, probably not.QuoteI learned computing using Algol-60 on 5-channel paper tape. (Consider how you can represent digits, letters and symbols in 5 bits.)I used C in the 80s, eventually moving to Objective-C, and avoiding C++.I've used Java professionally since 1997.So I've got wide knowledge and a solid history of making good choices about what technology really does advance the art of the possible.QuoteFamous problem with makefiles was thatinvisible differencesin the makefile caused different behaviour: tabs had different meanings to spaces! Stunning.QuoteAnd the indentation-is-significant produces all sorts ofrun-timeerrors that is avoided by "{...}" or "begin....end".Welcome to shellshock-class bugs in every program!QuoteIf C++ is the answer, then (a) I want to know th equestion and (b) we should change the question.

author: SirNick
author_rank: Frequent Contributor
timestamp: October 23, 2014, 06:52:49 pm
content: I find it about as absurd to compare Python, Java, and C as it would be to compare a can opener, scissors, and chainsaw.Giving up Bash scripting for Python is a good move. Giving up C for Python is not. Python is a scripting language, like Perl, and is really good for quick-n-dirty tasks, or minor applications. For whatever reason it's the darling of developers right now, but you wouldn't write a device driver in Python, or a kernel, or an embedded application. Wrong tool.C is really the sweet spot between ASM and Java / Objective C / whatever, and despite a LOT of en-vogue languages coming and going through the years, it's still ubiquitous. Yeah, void* can be a pain in the butt, however the times you use void* should be relatively few and far between. And in such cases, there should be no obviously preferable way to handle it. It's a very sharp knife, so don't be careless with it. Hopefully you're not using it for a tight loop's index, so optimization of a raw pointer shouldn't be so critical anyway. Most of the time, you're dealing with char, int, structs, and pointers to the same. In those cases, the code you compile probably can'tgetany more optimized. (Just ask the guys in the 1 Minute thread.)Anyway, Java is pretty big, and if it's going to be unseated, it won't be by Python. For e.g., the US government relies on Java pretty heavily for web services and such. No one's going to be tossing out all that enterprisey app server stuff for a scripting language. C'mon...

author: Howardlong
author_rank: Super Contributor
timestamp: October 23, 2014, 08:17:11 pm
content: Quote from: tggzzz on October 23, 2014, 03:37:06 pmMe too! On an Elliott 803. 8k words of 39 bits each. Hardware floating point. Ahhhhh....I do Java and C# if I have to, but C is my real home.

author: tggzzz
author_rank: Super Contributor
timestamp: October 23, 2014, 08:30:56 pm
content: Quote from: SirNick on October 23, 2014, 06:52:49 pmYou are missing the point.It is valid to compare those objects(languages), and particularly to compareaspectsof those objects(languages), to understand the domain in which each object(language)is most appropriate.Where somebody misunderstands objects(languages) features and characteristics, it can lead to misuse and choice of the wrong tool for the job at hand.QuoteIn the past C really was a good choice for a very wide range of projects, but recently that range has been significantly reduced by more modern tools.Unfortunately there is still a lot of crap legacy stuff written in C, still some dinosaurs that think C is the best tool for most problems, and other dinosaurs that don't understand the liberating power of newer tools.QuoteOften they are wrong about high optimisation: see the HP Dynamo project for whyemulatedC can befasterthan -O2 and -O4 C running on the same processor. The techniques necessary to achieve that are applied automatically and invisibly to every program running in a standard HotSpot JVM. Key point: the C compiler has to be unnecessarily pessimistic because it can't prove there isn't any aliasing.It is frequently necessary to ensure that the very sharp naked knives (which are often unwittingly left behind in projects) are covered by suitable guards/handles/covers/screens etc.QuoteYup. Choose the right tool for the job at hand. But do understand the competitions strengths.

author: tggzzz
author_rank: Super Contributor
timestamp: October 23, 2014, 08:34:33 pm
content: Quote from: Howardlong on October 23, 2014, 08:17:11 pmSnap! Minimum instruction time: 0.576ms i.e. ~2kIPSI still have the opcode handbook and some audio tapes of it clucking like a broody hen when "fetching Algol", and playing tunes (very flat high notes!).Must go to Bletchley sometime.

author: SirNick
author_rank: Frequent Contributor
timestamp: October 23, 2014, 11:09:18 pm
content: Quote from: tggzzz on October 23, 2014, 08:30:56 pmOK, we're getting a little pedantic here. But very well, I'll rephrase:"I find it absurd to consider Python, Java, and C as competitors for the same space."Quote from: tggzzz on October 23, 2014, 08:30:56 pmNow it's my turn to be pedantic. C stillisa good choice for a very wide range of projects, but recently there are many alternatives available that may prove more convenient. I take exception to the opinion that using C is the recourse of fossilized gray-beards who don't know better, though. Scripting and VM-based languages have been around for a while now, and they have their place, but C gives you a very rich set of tools. It's qualified for a great many purposes.Depending on your comfort level, your attention to detail, the time and effort you can afford to dedicate to a project, thescopeof that project, and the cost of errors, there may be no compelling reasonnotto use C where another language is equally capable (and possibly better suited.) This is particularly the case in Unix-land, where there are libraries and utilities for everything. Those tools often do ONE thing, and that one thing they do well. So, the burdens presented by C as a language do not weigh heavily on the developer -- and the availability of a C compiler for just about everything with a CPU is a relevant factor as well. Likewise with the ability of many languages to interface with compiled C code.Quote from: tggzzz on October 23, 2014, 08:30:56 pmIt's a neat trick, but you're talking about implementing a VM, with associated overhead, to relieve the processor from having to re-fetch data since it can't guarantee the copy in the register is still current. I'm sure there are times where this is a benefit, but wouldn't it just as likely be a huge resource suck as well? For that matter, hardware caching will likely make unoptimized reads a little less costly. I'll grant you this -- in a performance-critical loop, it might be wise to avoid dereferencing pointers at all, and thereby afford the compiler better control over the instructions used. (This does assume you have access to the source, and enough wherewithal to use the right language features.)Still I don't see this as much a cause for condemnation of a language. Some operationsmighttakeslightlylonger than absolutely necessary. Meanwhile, the fix is to virtualize the execution environment, analyze the code and look for patterns, and replace those patterns with more performant patterns? Hm... I'm not convinced this is the right approach in all but the corner-iest of cases. (Straight-up cross-platform emulation being a glowing example.)

author: tggzzz
author_rank: Super Contributor
timestamp: October 23, 2014, 11:40:31 pm
content: Quote from: SirNick on October 23, 2014, 11:09:18 pmAnd with that I completely agree.QuoteC is still an appropriate tool for many problems."Dinosaurs" don't recognise that, for some problems, there are now better tools than there were in the past. The naive and easily-beguiled-by-salesmen believe that all new tools are better than old tools - especially the scripting language du jour.QuoteAgreed, and I will attack the use of scripting languages more often than I defend them - I'm not a fan. By and large I prefer a good language+tools with libraries appropriate to the current problem.QuoteAgreed.QuoteYou don't understand how HotSpot (and Dynamo) work.The essential point is that they observe theruntimecode+data patterns to see which subset of code pathways areactuallyexecuted "90%" of the time - and then HotSpot optimises the shit out of whatactually happens(while leaving fallback escape route for the other 10%).In contrast, any C/C++ compiler has to make static compile-timeguessesas to whatmighthappen at runtime - and include pessimising code just in case aliasing happens to be occurring. And God help the user when, not if, the programmer uses too aggressive compiler optimisation flags.QuoteThe L1/L2/L3 caches are notoriously badly used by any pointer+dereference based language such as C/C++ (in contrast to, say, Fortran). At least with Java and C# the VM has a chance to ensure frequently/infrequently accessed code and data is in/out of the cache. Far from perfect, but impossible in C/C++.QuoteSounds like a good argument in favour of Java/C#QuoteIt certainly isn't the right approach in all cases. But it is, demonstrably, both good and good enough in a very wide range of cases. Embedded systems are probably the best counter-example, and also I suspect tablet-based systems.

author: miguelvp
author_rank: Super Contributor
timestamp: October 24, 2014, 12:30:11 am
content: Maybe you should tell NVidia to use Java instead, so they can beat Intel next year:http://en.wikipedia.org/wiki/Xeon_Phi#Design

author: vvanders
author_rank: Regular Contributor
timestamp: October 24, 2014, 03:13:24 am
content: Quote from: tggzzz on October 23, 2014, 11:40:31 pmYou must not have a great grasp of C/C++ if you think it's impossible. C/C++ gives you *complete* control over your memory layout that let you deal with cache issues in a way that Java can't touch and C# can only get close to(with struct values). Seehttp://research.scee.net/files/presentations/gcapaustralia09/Pitfalls_of_Object_Oriented_Programming_GCAP_09.pdforhttp://channel9.msdn.com/Events/Build/2014/2-661@ 12:15 for values types or 24:00 for where things really get interesting.Ignore data layout and cache usage at your own peril.

author: miguelvp
author_rank: Super Contributor
timestamp: October 24, 2014, 03:22:56 am
content: To be fair, Java does better than C/C++ on multicore processors because it scales better without a lot of research in the C/C++ front. Most programs can probably use one of the cores, maybe a couple.However C++11 does better than all of the above, and Erlang does even better than any of them, so when we have 1000 cores old C/C++ will be impossible to use if you want to use the whole capabilities of the chip.But if you have specialists and a lot of time for a speed competition, it's hard to beat dedicated handwritten code in the most appropriate language for the task.Edit: but then again at the lower level C++/C or assembly is where is at, even on high concurrent functional languages that scale to factors unobtainable by Java.

author: vvanders
author_rank: Regular Contributor
timestamp: October 24, 2014, 03:26:57 am
content: I'm actually a huge fan of Rust, it's got tons of bits in common with Erlang. Compiles down to x86 and has some really awesome static enforced(via RAII) resource ownership semantics.Someone recently ported his raytracer to Rust from C++ and it was a fairly interesting read:http://ruudvanasseldonk.com/2014/08/10/writing-a-path-tracer-in-rust-part-1The language still has a ways to go before it's considered stable but it looks pretty interesting.

author: SirNick
author_rank: Frequent Contributor
timestamp: October 24, 2014, 03:29:31 am
content: Quote from: tggzzz on October 23, 2014, 11:40:31 pmWhat? Hey, cut it out. This is the Internet, man!Quote from: tggzzz on October 23, 2014, 11:40:31 pmYeah... well.... I... agree with that, too.Quote from: tggzzz on October 23, 2014, 08:30:56 pmThat's likely true. Are you saying these tools optimize the code atcompile-time, by stepping through the instructions and observing how the program would normally run? I was (am?) under the impression they stood between the executing hardware and the bytecode to watch trends and shuffle instructions as necessary. Like a debugger. That seems anything but fast, so I hope I'm wrong.Also, for what it's worth ... Ulrich Drepper has a great paper on cache-aware programming. This discussion made me go back and revisit a couple sections from it. It's a dense read, and at the end of the day, it may only matter in time-critical or extremely long loops. The rest of the time you can get away with letting the compiler optimize what it can, and accept your losses for the rest. Anyway, the paper touches on compiler flags and attributes (some of which have been the subject of debate here WRT side-effects), and C99 features that resolve some of the issues -- although there's a footnote that says compiler support isn't quite there yet. It's a few years old now, but I assume in the scheme of things (again... C99...) not much has changed.Hand-optimization is an alternative, which may or may not be wise -- given portability, resource constraints, the impact of improvements in compiler optimization down the road, etc etc etc... It's a trade-off. C's flexibility will let you do many things (for better or worse). C# and Java have their baggage too, afterall. You're never going to stall a C program waiting for garbage collection, for example.

author: vvanders
author_rank: Regular Contributor
timestamp: October 24, 2014, 04:48:54 am
content: There's really not a need for non-portable hand optimizations in the types of systems where cache misses hit you hard(dram based, 400+ cycle losses). In those cases you're only optimizing the 10% that's in the domain of the compiler. The rest of it, the way you organize and access data, that's where the real perf gains are to be made. I highly recommend watching the Herb Sutter talk I linked previously, he shows quite a few examples where even simple arrays over hashmap/etc end up multiple orders of magnitude faster due to locality of data and prefetching.

author: miguelvp
author_rank: Super Contributor
timestamp: October 24, 2014, 05:02:10 am
content: Sure there is a need to hand optimiz if you are competing for the fastest supercomputer in the world.

author: tggzzz
author_rank: Super Contributor
timestamp: October 24, 2014, 08:25:03 am
content: Quote from: miguelvp on October 24, 2014, 12:30:11 amNow you're being silly. As I have very explicitly said, one tool doesn't fit all - use the right tool for the particular job at hand.

author: tggzzz
author_rank: Super Contributor
timestamp: October 24, 2014, 08:36:30 am
content: Quote from: vvanders on October 24, 2014, 03:13:24 amPartly true forsome staticaccess patterns that a programmer can correctlyguessbefore compilation. False for many common and pessimal access patterns, where there simplyis no locality of reference. Such access patterns necessarily "bust the cache" (except in toy applications where the entire dataset is small enough to fit in the cache).Being free to move commonly accessed data structures around memory based on theiractual measured run-timebehaviour can be surprisingly beneficial. But certainly not a panacea.QuoteVery true. Nowadays in terms of latency, cache = main memory, main memory = disk.

author: tggzzz
author_rank: Super Contributor
timestamp: October 24, 2014, 09:00:07 am
content: Quote from: SirNick on October 24, 2014, 03:29:31 amMirrorSorry I'll try not to make that mistake again.QuoteHotSpot is a runtime only tool, independent of the compiler. It operates in various stages, first noting which methods+operands are common and optimising them, then for the very common methods+operands it optimises inside methods and across multiple methods.It is fun to watch the execution time of some Java applications.Initially they can be slow as they code is lazily-loaded into the VM (necessarily lazy since in general it can be loaded from remote machines).Next they run at "normal" speed.After a few thousand iterations, they suddenly speed up noticably.That behaviour should be understood by anyone doing or reading Java benchmarks - there are too many very misleading benchmarks around. You have to "warm up" the JVM each time the program is run! Which isn't noticable for long-running applications but can be an issue for soft-realtime (e.g. telecoms) applications. Microbenchmarks should be ignored completely.QuoteIIRC it took 6 years before the firstfullC++99 compiler became available. I certainly remember triumphant announcements on usenet to that effect, but I had long lost interest in C++ by then. I have no idea how C11++ code will work with libraries compiled with 15..25 year old compilers and standards.The compiler flags issue frightens me. Even if I managed to get it right for my code now, I doubt I could get it right for other people's/companies' code, and I doubt people using my code in 5 years will get it right - because they don't have time to understand how my code works internally.As for accepting your losses on cache-busting code - yes, but let's have a go at gettingthe machine to nibble away at the problem.QuoteHand optimisation doesn't really cut it in a commercial organisation where the hardware changes significantly every year, but the code doesn't - in many cases the source code is no longer obtainable!

author: tggzzz
author_rank: Super Contributor
timestamp: October 24, 2014, 09:11:06 am
content: Quote from: vvanders on October 24, 2014, 04:48:54 amYou clearly don't understand how large organisations (plural) develop and run large applications that must continue to run in the years and decades to come.QuoteYes, I'm sure that's true for those microbenchmarks. If you want to go down that route, note that Fortran is inherently an array based language, and in these respects it is noticably better than pointer-based languages such as C/C++/Java/C#. More snidely, it sounds as if Sutter has triumphantly re-invented Fortran!Let me know when you have removed most pointer de-referencing from most C/C++/Java/C# programs, and I'll start to think Sutter has a point that is relevant to general C/C++/Java/C# programs.

author: miguelvp
author_rank: Super Contributor
timestamp: October 24, 2014, 09:16:35 am
content: Quote from: tggzzz on October 24, 2014, 09:00:07 amUnless you work on a locked down platform like say game consoles and keep improving the quality of the games every year on the same hardware.

author: VK3DRB
author_rank: Super Contributor
timestamp: October 24, 2014, 09:41:33 am
content: Quote from: tggzzz on October 24, 2014, 08:36:30 amSSD's are not disks.Nowadays, the termsoftwarehas expanded to encompass what we used to callfirmware.

author: HackedFridgeMagnet
author_rank: Super Contributor
timestamp: October 24, 2014, 11:19:32 am
content: Quote from: tggzzz on October 24, 2014, 08:36:30 amTo simplify, in terms of latency, cache = disk??! Not sure if that is what you mean.

author: _Sin
author_rank: Regular Contributor
timestamp: October 24, 2014, 11:35:19 am
content: In terms of actual time taken, getting stuff from disk into registers (via memory) is faster than ever, so virtual memory and paging is practical (and in some circumstances, largely transparent).But in terms of cycles taken, memory is actually slower than ever, which is why there are ever more layers of cache, and for real-time stuff, handling data properly to minimise fetching and maximise work-done-while-waiting is more important than ever.

author: tggzzz
author_rank: Super Contributor
timestamp: October 24, 2014, 01:04:49 pm
content: Quote from: miguelvp on October 24, 2014, 09:16:35 amA good valid counter-example to my point, even if it isn't an example that applies to many programmers/companies.

author: tggzzz
author_rank: Super Contributor
timestamp: October 24, 2014, 01:05:51 pm
content: Quote from: HackedFridgeMagnet on October 24, 2014, 11:19:32 amOh, in this case my "=" isn't transitive

author: tggzzz
author_rank: Super Contributor
timestamp: October 24, 2014, 01:09:36 pm
content: Quote from: _Sin on October 24, 2014, 11:35:19 amWe agree, but I carefully distinguish between latency and bandwidth. Main memory bandwidth has increased significantly. Main memory latency has hardly decreased.This puts more stress on caches, benefits Fortran-style array access patterns, hinders C/C++/Java/C# pointer-dereference style access patterns.

author: tggzzz
author_rank: Super Contributor
timestamp: October 24, 2014, 01:11:46 pm
content: Quote from: VK3DRB on October 24, 2014, 09:41:33 amSSDs are indeed a halfway house, but that doesn't invalidate the (somewhat crude) analogy I was making.I don't see the relevance of the software/firmware dichotomy to the analogy.

author: miguelvp
author_rank: Super Contributor
timestamp: October 24, 2014, 02:35:30 pm
content: Quote from: tggzzz on October 24, 2014, 01:04:49 pmOk, how about Rigol DS series firmware/software developers? Or any other product for that matter that receives updates on a lock down hardware, I'm pretty sure most programs run in non changing hardware.

author: Howardlong
author_rank: Super Contributor
timestamp: October 24, 2014, 10:14:45 pm
content: If I may add my own experiences of VM based languages, based on over two decades of developing and troubleshooting enterprise level financial trading systems, the symptoms still remain the same. Namely, indeterministic response times, and that to make these systems work, there is a huge amount of configuration to be done for every implementation, not to mention the significant specialised resources to maintain them.In the "bad" old days of client-server, things were simpler, and it was usually fairly clear to diagnose where a problem lay, be it desktop, network, or server-side, and configuration was minimal. Since the onslaught of VM based languages, and their even more distributed systems, configuring and maintaining them has become very time consuming, and is like treading on eggshells. When it all goes completely do-lally, restarting a complex system can take several tens of minutes, while all the code re-JITs. This JIT compilation is all very well, and I am sure hotspot-type analysis is fine and dandy, but with my troubleshooting hat on I'd far rather have a system that ran in a consistent way than one that thinks it knows better, causing a lot of head scratching.An example of this automated optimisation has already been happening on the database side (my primary area of expertise) for over fifteen years now. When it makes the wrong decision, perhaps after randomly updating some optimizer statistics from a non-representative subset of data, it can cause major performance problems, and take an awfully long time to diagnose. But it has kept me gainfully employed as a result.My point is that the cleverer you make your environment, in general the more complex and less deterministic it becomes, and to resolve those problems takes a more specialist set of individuals, some of whom were probably commoditised and likely don't exist anymore.

author: tggzzz
author_rank: Super Contributor
timestamp: October 24, 2014, 10:54:42 pm
content: Quote from: Howardlong on October 24, 2014, 10:14:45 pmThat is all thoughtful and valid, and I can't disagree with any of those points. My background in this area is in telecom systems rather than financial systems, but there are many similarities.I would, however, modulate some of those statements with some other observations which are relevant to such large systems whether or not they contain VM-based components.Firstly such systems have become more complex w.r.t. number of components, interconnection/interdependence between components, and geographical area. (That's also true if you replace "component" with "company"). All of those considerations lead towards more fragile systems.Secondly, the processors themselves have become more indeterministic. Almost all the increase in processing power has relied on increasingly large L1/L2/L3 caches to mask the increasing mismatch between processor speed and main memory speed. Such caches are inherently non-deterministic - and IMNSHO precludes such processors being used for hard realtime operation. (They are fine for soft realtime systems provided the protocols have been designed to be delay-insensitive, which is the case for telecom systems).Thirdly, I have a strong suspicion that many of the components in large systems will exhibit degraded performance during startup, for the simple reason that they contain various explicit and implied caches. In such cases, soft-start operational techniques are almost mandatory.Now long ago I made a career decision to stay away from databases (other than specialised distributed in-memory key-value pairs!), I'm pretty sure that databases are subject to these phenomena as well.In conclusion, while needing to "warm up" VMs certainly doesn't help, in my limited experience that it is no worse that the other phenomena I noted above. And the the techniques already required to mitigate (not solve) one, also mitigates the other.The truth is rarely pure and never simple.

author: SirNick
author_rank: Frequent Contributor
timestamp: October 25, 2014, 01:03:16 am
content: Quote from: vvanders on October 24, 2014, 04:48:54 amThat's actually what I was referring to WRT "hand-optimizing". Data sets and algorithms, not instructions. Although, if the shoe fits...Quote from: tggzzz on October 24, 2014, 09:00:07 amHere's the way I see it:Softwarealwayshas bugs. Optimization problems can be sneaky, for sure, but hopefully a good test suite will catch a lot of this before the code ever sees the light of day. If not, then maybe they will be found in the wild, investigated, and resolved in whatever way is most appropriate. Not ideal, perhaps, but realistically that's just part of the software release cycle.If the end-user has access to the source, it's wise to set sensible build defaults, and mention known issues somewhere in the docs (Makefile, header comments, readme) In some cases, the project / author's site will say "before filing a bug report, make sure you've compiled the software with these flags..." In general, there seems to be a consensus among developers and users what is considered "safe", and to go beyond that is The Road Less Traveled.If the source isn't available, then those things should be controlled internal to the build process anyhow.I'm not solving this problem for anyone here, obviously -- it's all well understood. I only mean to describe my own perspective on the nature and scale of the problem.One might say, "But why exacerbate the potential for bugs by continuing to use languages where this is a problem?" That's a fair point, One. However, this has to be considered as one of the often many potential drawbacks of any given tool. Java has dependency issues like a mother, for e.g. Root help you if you have the wrong JRE. That will often lead to the same kind of "WTF -- it works fine on my other computer!" problems as optimization flags. .Net has its share of quirks as well. This is not a unique dilemma to C.Maybe Fortran runtime environments are perfect though. I dunno, never used it.Quote from: VK3DRB on October 24, 2014, 09:41:33 amI think there's some confusion here. I took our consonant friend's remark to say, "cache is the new RAM, and RAM is the new disk", referring to performance expectations rather than the medium itself.Quote from: miguelvp on October 24, 2014, 02:35:30 pmIf by "most", you mean "some ambiguous number I've pulled from my exhaust pipe"Sorry, I couldn't resist. No offense intended, I'm just skeptical of anyone's guess as to the nature of "most programs". That seems as nebulous as saying "most webpages are HTML 4 Transitional" or something. Good luck proving a sample is representative.

author: miguelvp
author_rank: Super Contributor
timestamp: October 25, 2014, 01:18:42 am
content: Quote from: SirNick on October 25, 2014, 01:03:16 amEmbedded hardware outnumbers webpages or computers and their associated installed programs.No need to even prove it, you have more lock down hardware running code in your house than any other software. Even your "exhaust pipe" runs embedded software on dedicated hardware

author: SirNick
author_rank: Frequent Contributor
timestamp: October 25, 2014, 01:21:18 am
content: Y'know... you're probably right, actually. Contemplating the number of embedded devices is rather mind-boggling.OK, I take my sarcastic quip back.

author: vvanders
author_rank: Regular Contributor
timestamp: October 25, 2014, 01:42:08 am
content: Quote from: tggzzz on October 24, 2014, 09:11:06 amIf you had watched the full talk you would have seen that he refers to other people's real-world use cases later on. Feel free to dig up Mike Acton or any other other Data Oriented Design enthusiasts. There's many practical, real-world examples that are shipped in many products.FYI I've got nothing wrong with Fortran, it's just a language that I'm not familiar with and that you won't see a wide a compiler support across the embedded space. I'm just hoping to educate the people who are using C/C++ to use is smarter and better rather than the way "traditional" CS courses tend to teach it. Things like why Radix Sort for normal datasets(for <1000 based on simple keys) is disgustingly faster than any other sorting algorithm, cache usage and all the unintuitive stuff they don't teach you in school.

author: VK3DRB
author_rank: Super Contributor
timestamp: October 25, 2014, 02:26:44 am
content: Quote from: SirNick on October 25, 2014, 01:03:16 amBugs includes incorrect use of upper and lower case in documentation (a common disability found in engineers), poor alignment of text boxes, inconsistencies in GUI layout, and an illogical state machine.For critical applications a good test suite includes unit testing, boundary testing, automated functional testing with a test harness, usability testing and of course ad-hoc testing. Ad-hoc testing in my opinion is the most powerful because it discovers unexpected behaviour not identified in the test suite. Ad-hoc testing and usability testing should be given to someone who has minimal knowledge of the software so that there are no prejudices.It is highly unlikely Apple did any proper usability testing with their iTunes crapware.

author: tggzzz
author_rank: Super Contributor
timestamp: October 25, 2014, 12:37:06 pm
content: Quote from: SirNick on October 25, 2014, 01:03:16 amI do wish you would stop making well-reasoned points which are relevant in theory and practice: it is soooo boring.QuoteOld engineering maxim: you can't test quality into a product. Unfortunately software-neophytes aren't taught that, to the extent that I've seen too many believe that if the tests are passed then it works.Test suites are vital, but limited. A particular problem is that each product's test suite almost certainly doesn't address issues w.r.t. integrating the product into a system. But you are probably very keenly aware of that!In general my attitude is to choose tools that minimise the chance of problems occurring now or later. Yes, I prefer the "bluntest" tool that does the job. If a tool has to be "sharp" I want to see it have adequate handles, guards and shields - so that mistakes by me or others don't hurt too much.QuoteJust so. But at least the fault appears early before any damage has been done (cf dangling pointers), is reproducable, and relatively easy to find, and you you can be certain when you have fixed it.QuoteSplutter. If only! I've only written one Fortran program, but I listen to people that have used (and debugged) many large systems (e.g. HPC number crunching) written in different languages. Their opinion is much more valid than mine.

author: westfw
author_rank: Super Contributor
timestamp: October 25, 2014, 11:08:49 pm
content: QuoteHeh. Shared common areas! And the things you had to do to deal with text!The problem is that even within a single "problem", there are multiple sub-problems that are significantly different than one another. I spent a long time not understanding why OOLs were useful, given that my deep embedded and CLI "problems" seemed equally suited to traditional procedural methods. And then I looked into writing a window-based application on a desktop. "Gee, it sure would be nice if there was some way to package up all this initialization data and such into the libraries. Oh! That's what those "objects" are good for!"For a while, companies were designing general purpose languages that were supposed to do everything and anything that any programmer could want. PL/1 and Ada are the most extreme examples I can think of. Those didn't work out so well. The more modern trend is to produce languages aimed at smaller targets. Which works pretty well until you have flame wars about how some interpreted language is "just fine for systems programming, as long as you run it on a sufficiently powerful platform."

author: Howardlong
author_rank: Super Contributor
timestamp: October 26, 2014, 12:21:13 am
content: Here's an example of .Net ridiculousness. As we all know it has its fair share of security updates. But for some time, each security update required the framework, or whatever it's called these days, to completely re-compile the entire runtime code base.So, say you're installing the OS, it's not uncommon to have several dozen .Net security updates to apply. Each one needs to recompile the runtime. Again and again. What a crock. And why is it pre-compiling? I thought this stuff was JITted? Nope, because they realised that JITting caused apps to load so slowly that they disposed of that idea and decided to precompile the runtime anyway.That same recompile happens one or more times on patch Tuesday too.So why not just distribute the patched code pre-compiled anyway?Microsoft also claim that the supposed "background" processes like .Net compilations that go on have no effect on the end user desktop experience, because they run at a low priority. Meantime, the end user's disk cache in well and truly purged. Someone better teach these guys about how disk caching works, or upgrade everyone to SSDs.

author: tggzzz
author_rank: Super Contributor
timestamp: October 26, 2014, 08:53:37 am
content: Quote from: Howardlong on October 26, 2014, 12:21:13 amThe ahead-of-time static analysis and compilation was a very deliberate choice, and is a good choice for resource-constrained devices e.g. small portable devices. Android does something similar.It also enabled their marketing department to make snide remarks about Java, which was a real threat to MS when .NET was being developed.QuoteEffective ahead-of-time optimisation requires fitting to the precise machine in terms of cache size, instruction set etc. There are too many combinatorial possibilities for such pre-compilation.QuoteAll tool vendors make barely justifyable claims.

author: Howardlong
author_rank: Super Contributor
timestamp: October 26, 2014, 04:47:04 pm
content: Quote from: tggzzz on October 26, 2014, 08:53:37 amI assume we're talking about RAM cache... if so I really have a hard time believing that they compile based on one Intel processor's cache to another. It's assuming an awful lot, including what else might be running at the same time. I can understand that they might want to take advantage of a given CPU's instruction set enhancements, although in almost all use cases I doubt it makes much difference from a pre-compiled x86 or x64 binary: even MS only expect a 5% improvement. Perhaps in some DSP scenarios, yes, I can see such a benefit, taking advantage of newer instructions. I'd rather take a predictable and consistent average 5% speed hit to indeterministic behaviour, with those immortal words of the call centre, "Computer's running a bit slow".QuoteYou got that right!

author: tggzzz
author_rank: Super Contributor
timestamp: October 26, 2014, 05:19:48 pm
content: Quote from: Howardlong on October 26, 2014, 04:47:04 pmI was thinking of L1/L2 cache rather than any caching done in "RAM".For the purpose of this discussion I include "linking" in the compilation process. I can imagine that (in order to try and compete with Java's HotSpot) during installation some highly processor-specific libraries are either statically linked and/or inlined.Windows 8 requires using the CMPXCHG16B instruction which is not present in all processors. That is an oblique hint that cache and cache access isn't merely a case of different cache sizes - but I don't know all the details.Windows runs on more than just X86; I don't know about .NET. (The last time I looked at .NET in detail was when Anders Hejlsberg came and gave us a talk about C#/.NET shortly before it was released. Since it was a single-o/s Java-lookalike I decided I wouldn't bother to use it unless it became necessary).Speed vs predicatability: I'd go for predictability too. But marketeers and benchmarkers wouldn'tAfter all, operations and maintenance a Somebody Else's Problem!

author: Howardlong
author_rank: Super Contributor
timestamp: October 26, 2014, 06:13:02 pm
content: Yes, I was trying to distinguish between that and disk cache.Problem is, any cache is a shared resource: an app, and its compiler, can't make assumptions that it's the only game in town. It can, at a micro-level, determine the best way to compile up, say, a loop, so that it fits into a single cache allocation unit, but beyond that no assumptions should be made.The project I worked on was written on the original .Net back around 2001 or so when a years worth of Java development was canned and "ported" (yes, that's right, of course it wasn't going to be completely rewritten) to .Net. I still to this day have no idea what they were thinking, but we had Microsofties parachuted in like flies around the proverbial t%rd, some of whom were OK, but most were no better than anyone else who'd read a couple of books. But it turned out it was a whitepaper development, so it had to work, and it was demo'd at one of the Barcelona shindigs, where we had to load up every screen of the app before doing the demo because it was such a sloth. It's still around today, in .Net, but now everythings being ported to.... you guessed it, Java.Cheers, Howard

author: tggzzz
author_rank: Super Contributor
timestamp: October 26, 2014, 06:33:09 pm
content: Quote from: Howardlong on October 26, 2014, 06:13:02 pmYes and no. There is a choice as to whether the cache address is the (process+virtual address) or (physical address). One is easier/faster to implement, the other reduces (eliminates?) the ability of one process to evict other processes from the cache.QuotePlus ca change, plus c'est la meme chose. Twas ever thus.

author: Howardlong
author_rank: Super Contributor
timestamp: October 26, 2014, 08:17:20 pm
content: The same extends in the disk cache arena to long term spindle-bound processes like AV and backups, neither of which should read data in a way that purges cache, but sadly this often doesn't happen.

author: Sigmoid
author_rank: Frequent Contributor
timestamp: October 29, 2014, 07:51:14 pm
content: Quote from: nctnico on October 06, 2014, 06:41:49 pmI'd rephrase that and say that C# is'Java which works'. Period.Since the awesome job Novell has done with MONO, C# and its standard libraries have also become a portable programming tool. If I can choose between C# and Java, I definitely go with the first if possible.With all the idiotic engineering decisions in JAVA, the overall pain in the rear that programming the bloody thing is, Oracle's unscrupulous approach to things (like patent trolling and bundling the runtime with malware), the weird and random incompatibilities between versions, the shit integration on pretty much any platform (not just Windows), and the speed (or lack thereof), and the memory usage, I'd say C# is far superior from both an end user and developer perspective.

author: SirNick
author_rank: Frequent Contributor
timestamp: October 30, 2014, 06:58:39 pm
content: On the "old PC" thread, someone referred to iOS / OS X development, and that led me to go back and look up Objective C again. Turns out Apple is pushing for a change to Swift now. Anyone looked into that? Would it have relevance outside of Apple's world? From a few syntax snippets that I saw it looked C-like enough to be familiar and comfortable, while providing OOP and side-stepping some of the main hurdles with large C applications (like having so much to do with pointers.)

author: tggzzz
author_rank: Super Contributor
timestamp: October 30, 2014, 11:46:43 pm
content: Quote from: SirNick on October 30, 2014, 06:58:39 pmAs far as I can tell it is constrained to be syntatic sugar, since it has to be completely compatible with Objective-C. Syntatic sugar can be nice and convenient, but won't enable new capabilities (although it may make enable more people to write code and/or do it faster).in its current incarnation, it will have even less relevance outside Apple than C# has outside MicroSoft.

author: SirNick
author_rank: Frequent Contributor
timestamp: October 31, 2014, 02:10:49 am
content: Huh. I thought it was just intended to be linkable with Obj-C. That's too bad.

author: theatrus
author_rank: Frequent Contributor
timestamp: October 31, 2014, 05:59:46 am
content: Swift has to be interoperable with the ObjC runtime, less so the language. For example, it is impossible to inherit from a Swift class in ObjectiveC (though it is possible to bridge Objective C to Swift).For a 1.0 language, with a strong compatibility requirement with ObjC, they've done very well.

author: tggzzz
author_rank: Super Contributor
timestamp: October 31, 2014, 10:32:08 am
content: Quote from: theatrus on October 31, 2014, 05:59:46 amDoes it make any sense to conceive of an Objective-C class inheriting from a Swift class? I would accept significant limitations on what's in the Objective-C class.QuoteThat's my impression too. (Much better than C++ and C!)

author: theatrus
author_rank: Frequent Contributor
timestamp: October 31, 2014, 02:45:21 pm
content: Quote from: tggzzz on October 31, 2014, 10:32:08 amIf someone writes a library / view controller / etc in Swift, yet your normal application workflow is still ObjC? Not many would fall in that camp, but it is conceivable. Using any Swift also restricts you to the 8.0 SDK (unsure on the OS X side).