Jump to content

C, C++, C# Programming - what is the sense in this


PB666

Recommended Posts

I am really making a push now to learn C and all its variants. I have may Linux system finally stable and a dual boot system and I am managing (arduously) to learn the language.

Learning basic was easy, visual basic without a course was arduous, but I eventually became proficient at it in both Prof and VBA (which I mostly use). I came at MS-basic from basically programming an Apple IIe in machine language, I used an assembly language editor for a time but eventually found I could code directly in hexadecimal.

So this is a computer science question. With C what is the sense? if it is supposed to be faster or more powerful, I find many of the functions you have to sort through types, or convert types. And I have been reading online that some of the System.Math functions are really not that efficient, that you could write more efficient classes in your own program. So why doesn't the standard just give the algorhythm and let folks create their own functional classes. Suppose I don't need an answer that is accurate to 20 decimal places, suppose 4 is good enough, why do I want to waste the clock cycles trying to achieve 20 places.

One of the functions is you have to take a float, convert it to double, run the math function, when done convert it back to float again. That's very efficient.

The other thing, from a Visual basic point of view, the language itself is sort of archane in its structure. For example loops closures go unidentified, I find my self counting closed brackets and things like this.

What really is the basis of C's popularity, couldn't we just have a basic portable across many platforms.

Link to comment
Share on other sites

First of all, C, C++, and C# are three completely different languages with similarity in syntax and some historical parallels. They serve completely different purposes and should not be lumped together. Modern C and C++ compile directly to machine code, for example, while C# compiles to byte code that runs on CLR. Which means that even with JIT, C# should not be used for performance-critical tasks.

BASIC, in contrast, takes its roots as an interpreted language. While VB also compiles to CLR, it still has a lot of the problems common to interpreted languages. Abysmal performance is just tip of the iceberg. It has poor type-safety, bad garbage collection, and object-oriented features that are bolted onto an outdated language.

The most important thing to understand about a real programming language is that it's not about built-in functions. C has almost none. It comes with a pretty broad spectrum of standard libraries, for sure, but they are not really part of the language. More importantly, every single one of them can be replaced to fit a specific need. A good language is not a set of functions. It's a tool kit. Why is C a particularly good language? Because it translates almost directly to machine code. Which means you always have an idea how well your code is actually going to perform. If you cannot look at your code and tell what instructions it's going to turn into, you cannot write efficient code. And this is absolutely impossible to do with the languages like VB.

But yes, C is archaic, which makes it unsuitable for a lot of modern tasks. That's why C++ exists. C++ has all of the features expected of a modern language, starting with objects and ending with meta-programming. That does, however, come at a cost of performance. Optimization of C++ code is nowhere near as straight forward, and takes much longer for compiler to perform. Which is why C has not been phased out. A high performance high complexity application will be written in a mix of C and C++. Fortunately, C-style linking is part of the C++ standard.

Finally, C# is a completely different breed of languages. It is much closer to Java than C in almost every way. From code organization, to execution, to memory management. However, it also comes with a compatibility feature allowing it to call native code with C-style syntax. In that case, C/C++ code can effectively become a library for C# code to tap into for performance-intensive operations, while maintaining organization and safety of a higher level language.

So even if we look at C#, which is a .NET language, just like VB, VB has not a fraction of the features, while performing far, far worse than C#. The only redeeming feature of VB is that you don't need to know anything about programming to write some simple code in it. But it is absolutely unsuitable for anything serious.

Link to comment
Share on other sites

It's history. There were Bell Labs, there was Unix and there was C (early 70s). Mainly, C became popular since Unix itself was re-written from the assembly language into C and Unix was pretty common these days.

Generally, there were also ALGOL, FORTRAN, PASCAL, etc but they were not universal enough and there were many dialects varying from one platform to another, from one compiler to another. So, the fact that there was a commonly accepted language standard added to the popularity of C.

Then came C++ (mainly 'C with classes' and many new adepts followed the OOP paradigm). The language was adapted for IBM PC platform (now known as x86) and quickly become popular together with the platform itself. Certainly there were other languages but C++ compilers generated native code unlike their many counterparts that required runtime libraries. Thus C/C++ became the main tool for application development for x86.

It all runs along the same rails even now. Young people grow up with the knowledge that C++ is a 'must have' language in their portfolio, then they write applications and then there's another generation of programmers grows up with this knowledge.

Now fortunately the CPU speeds and memory are huge and there's no need to count every CPU tick and every memory byte. This situation allowed creating huge frameworks that encapsulated many standard tasks in its classes. Java c C# were born.

C#/Java allows you to quickly develop some tools you need without thinking of memory management, garbage collection, I/O, etc. They allow you to concentrate on the task you really need to solve. But everything comes at a price - you've got .Net Framework or Java VM, you've got slower execution performance and larger memory requirements.

Every task require an adequate tool, that's all. If you need performance or low system requirements use assembly / C / C++. If you need simply to draw a window with a button without any particular requirements - use modern languages because it's simpler.

As for the brace matching - here's my advice - comment any closing brace:


namespace MyNamespace
{
class MyClass
{

while (someCondition)
{
try
{
} // try
catch
{
} // catch
} // while

} // myClass
} // namespace MyNamespace

this way you won't lose anything.

Edited by cicatrix
Link to comment
Share on other sites

C originated at bell labs. It was called C because it was based off the language "B". C++ is based off of C. It was originally was going to be called "C with classes" (so you can do stuff like potato.explode();) but they went with C++ as a reference to the new function [vaiable]++; (e.g. n++;). I don't know how C# came into existence. I think Microsoft was involved.

Souce: Several code books I have read.

Hope this helps.

Luke

--updated--

Also, not all programming is done for modern computers with tens of GBs of RAM.

Pick up an Arduino or a PIC and you'll be counting those bytes soon enough.

Oh god. I still have nightmares about my arduino. (the old ones, with only 16kb of code space)

Edited by lukethecoder64
Link to comment
Share on other sites

I can't see sense in learning C, C++ and C#.

C and C++ is used for example to code linux kernel, while C# is Microsoft invention and it has nothing to do with those two. C# is more like Java and most of its features was invented to take market share of Java, so learning C# at same time as C and C++ is mistake IMO.

If you are looking for language for your self it would be reasonable to pick most popular first http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html

Link to comment
Share on other sites

Any serious C# project will feature C/C++ integration. So yes, learning all three is valuable. And yes, if you want to have a boring job with a five figure salary, go ahead and learn just Java. Unless you know how to write C plugins for it, you won't be working on anything more exciting than app UI.

Link to comment
Share on other sites

So even if we look at C#, which is a .NET language, just like VB, VB has not a fraction of the features, while performing far, far worse than C#. The only redeeming feature of VB is that you don't need to know anything about programming to write some simple code in it. But it is absolutely unsuitable for anything serious.

Actually the creators of C# claim that this opinion that C# is just an iteration of Java, they claim that it was patterned off of C++.

The reason why I selected C hash was that I want to create high efficiency routines that I can run from VB or VBA, basically, so the efficiency issue is the issue. But exactly to the point, I wanted to tailor structures and classes to the efficiency and accuracy that I needed. The problem is that this has proven to be rather archaic process in either C++ or C#. Microsoft claims that both VB and C# are converted to essentially the same product before finally being converted to assembly language at runtime (Runtime implimentation). Also C hash runs in linux, which means If I have to I can run any vb app in linux as long as I can convert it to C#. Since these are the most similar it seems logical.

So let me opinion about the problems of VB in principle and compare with C.

1VB. The If ...... End If structures, unlike For and Next do not have identifiers. For example hypothetically If-1 End If-1. When you have left out a next or end statement, the computer does not recognize that it was missing for an end or next statement, and proclaims that an End if is missing even though it might be a Next.

1C The { ....... } covers not only If and For and while and For each and . . . . . but also covers subroutines, class definitions. so a problem that is bad in VB is a magnitude worse in C. Seriously code segment identifiers are not compiled, they are freebees. 1{ }1 2{ }2 3{ }3 4{ }4 So that if you messed up one of your brackets the programs can tell you 'hey bracket 1 is missing it closing bracket'

2VB. Function definitions. If you are running a function within a module of basic, you simply need to declare the function and variable and a few lines of code. Its relatively simple. For the most part you don't want to run a function except if it will clear several lines of code up. So for example I want to evaluate non-normality, I can create a Skewing function and a Kurtosis function, or combine both into a single function (the output would have to be a string in that case)

2C. Jeeze Louise, lol. Static, Public, Private, implementation requires a new statement for multiple iterations. Why do I need to create a new class exactly to have multiple iterations. The simplest functional math statement and I have run into errors with just about every character of code. Is this really saving clock cycles, calling subroutines as separate classes? In C a function definition is not just a function, it is literally everything, whereas in VB functions are Functions (return calls) and everything else is subroutine, or even a defined type in VB6 (the equivilant of a struct in C). Because the functions are not set apart what has happened (as I see it) every single identifier in a class becomes very context sensitive, so any minor deviation from what the computer expects will generate an error. The problem in C is that class and function are muddled, a function should be something with a return value, it is not it can be any routine called in a class, if a static is not given it runs pretty much like the pi() function, if the static is not given you have to call a new instance of the function (an pray that its going to work).

So it seems to me, that say if I am going to need several routines running simultaneously in C, I am going to have to create a whole new class for each, to make sure that the other might-be functions in that class are not going to be carried on for the ride. This makes sense if you need to build really big classes, such as an employee class or product class, but if the function of the iteration is to process some basic parameters.

Here's an example:

Suppose I need 30 classes (types of objects in a solar system, types of diseases, whatever)

Some of these are so simple that I can create structures (which apparently are not used anymore in C) but most will be defined as a class, so, unless I combine them into a dynamic linked library, I'm going to have 30 class files for the program. Not only this I am going to have to be tracking all of these things in memory.

So for example suppose I have finished a sector. Even if I create a model without a given class (less say a lessor companion in a binary star system), I am still loading the class. IF I combine functions into classes, then every time I call the celestial routine, I am also pulling a routine for a fluffball which I would not use since a celestial is gravitationally flattened. So in this case fluffball I could run as a structure (struct) and it would not need to process the effects of its own gravity (since this could be handled collectively) on all surrounding gravities, but a celestials gravity would need to be assessed (for example it can toss a fluffball out of the system or tear it apart and eat the fragments), so I would be pulling class routines for doing assessment of gravity effects. In VB6 I would simply define at type fluffer and set variables in a type, then dimension fluffballs

Dim fluffball() as fluffer. And in the programm

fluffballcount += 1

Redim Preserve fluffball(fluffballcount)

With fluffball(fluffballCount)

.mass = RND(K): .X = xPos: .Y = yPos: .Z = xPos: .density = 0.01: .velX = 1000: .velY = 2000: .velZ = 10000: .sector = sectorNumber

End With

Sector fluffball(fluffballcount).sector (parameter list) ' An object its going to examine to see if fluffball interacted with anything, or how is shifted mass or gravity in its space.

. . . . . .

So now in C, fluffball is now an instance of a class and all its parameters will have to be shipped to the object to be updated, this essentially means making an expensive call for essentially routine equivalencies.

- - - Updated - - -


namespace MyNamespace
{
class MyClass
{

while (someCondition)
{
try
{
} // try
catch
{
} // catch
} // while

} // myClass
} // namespace MyNamespace

this way you won't lose anything.

Good idea, didn't think of that but I should have.

The /// section of definitions I have tried to use this but it doesn't seem to work, it works in the You Tube but not on my computer.

Edited by PB666
Link to comment
Share on other sites

Any serious C# project will feature C/C++ integration. So yes, learning all three is valuable. And yes, if you want to have a boring job with a five figure salary, go ahead and learn just Java. Unless you know how to write C plugins for it, you won't be working on anything more exciting than app UI.

C# integration with C/C++ in what project?

You have very narrow experience in Java then... Java is multiplatform, so you can use it under windows, linux or mac, while adding your C plugin would mean you have to write and maintain 3 different versions of this plugin. Of course not every software needs to be multiplatform software, but it is one of main Java features.

Link to comment
Share on other sites

I'll bite the trollbait:

" C and all its variants". As stated above, C# is not a variant of C at all, but merely Java once it has been "embraced and extended" (Sun/Oracle is doing its part on the "extinguish" part).

"So this is a computer science question. With C what is the sense?" C is handy way of writing/reading (the reading turns out to be much more important) assembler code written for PDP-7 and PDP-11 microcomputers. It also had great documentation: "The C programming language by Kernigham and Ritchie", this book was short and complete, and allowed new hackers to learn the language. Once established, most compiler effort went into C, most required programs were written in C (or FORTRAN) so that the speed of a computer was effectively "how fast can it run C programs". C++ extends this lead. Note that C++ isn't just "C with classes". It is "C with the kitchen sink, but allows pure C to compile on C++ compilers". I'd avoid C++ unless you really want to learn a ton of arcane details on exactly what each command does. Hint: the way classes are defined in all the "learn C++ in fixnum days" at my local library never bothered to mention that it couldn't be used in non-trivial cases. You either have to use the "new" keyword or have some other means of keeping the object off the stack or it dies with the subroutine (the "object" remains as a pointer, just all the data gets swept up in the stack). Note there isn't any C++ in the Linux kernal. Officially this is because of the difficulty of tracking down C++ memory use, but likely has to do with Linus's views of C++ and C++ programmers.

"One of the functions is you have to take a float, convert it to double, run the math function, when done convert it back to float again. That's very efficient. "

I'm willing to bet that isn't "because C", that is "the way that function is defined by ieee-754" (the official standard of floating point). You could write your own, but it wouldn't be standard and would be considered buggy. It also wouldn't be any faster on anything made since the 486, any modern CPU (but not GPU) will multiply and add doubles just as fast as floats (although you can obviously maker arrays of more floats in things like SSEn). To really rub salt in your wounds, per ieee-754 when the computer multiplies two doubles together it needs the full 98 bit mantissa and then rounds it to 53 bits for the final answer (3/4 of the work is then thrown away). Look up rounding errors to find out why (or just listen to a sound sample that has a 64k point IFFT(FFT(x)) done on it).

"What really is the basis of C's popularity, couldn't we just have a basic portable across many platforms."

https://xkcd.com/927/ [standards]

Then you don't want C. You want Java: write once debug everywhere. As mentioned above, the amount of C that is standard is vanishingly small. Some of that (the string library) is insecure and deprecated (without an official replacement). You should be able to make a portable backend in C (assuming that you aren't dependent on *any* libraries), but C has zero user interface functions beyond the mentioned (and broken) string [printing] functions.

Link to comment
Share on other sites

C# integration with C/C++ in what project?

You have very narrow experience in Java then... Java is multiplatform, so you can use it under windows, linux or mac, while adding your C plugin would mean you have to write and maintain 3 different versions of this plugin. Of course not every software needs to be multiplatform software, but it is one of main Java features.

Sometimes you want a barebones stripped application of all its bells and whistles that just crunches massive amount of data. I have 200Gbyte of Desinovan genome that I want to process. I know how to do in in VBasic relatively logically an easily, now I need to get into a version of C that can make it go fast, barring that I will probably never be able to hex code on an i586 processor, i need the next best thing, ergo on linux and learning C. The logic is, if I can port it to C# and work out all the bugs there I can create a C++ application and run it on the console. In response to what one of the other posters says, efficiency is very important, still.

Tried running barebones sequence alignment on mtDNA sequences from all Eutherians, and will need to repeat soon, the last time I ran the alignment it took just over 3 days.

- - - Updated - - -

To really rub salt in your wounds, per ieee-754 when the computer multiplies two doubles together it needs the full 98 bit mantissa and then rounds it to 53 bits for the final answer (3/4 of the work is then thrown away). Look up rounding errors to find out why (or just listen to a sound sample that has a 64k point IFFT(FFT(x)) done on it).

Which contradicts your previous point. As per say calculating a log or a square root, all I need for certain comparisons is 3 digits, many of these are statistical so if I am off by 0.001 P at the threshold of 0.05 p it doesn't really matter since I will have to reprocess all the positives anyway. It could for a SquareRoot take Newton's shortcut and it would work.

What really is the basis of C's popularity, couldn't we just have a basic portable across many platforms."

https://xkcd.com/927/

I moved to Linux simply to get away from the OS overhead with windows 10.

Link to comment
Share on other sites

C is popular because history and usability. Even with all its flaws and cumbersome features (Memory leaks on a regular basis even in simple code), it's still a robust and well-rounded programming language for all your lower-level programming needs (even though it's technically a high-level language). C++/C# are variations of C that make object-oriented programming available (C# is imo just revamped C++ with more emphasis on end-user applications). I'd agree with those telling you that java is better, it's easier and does all the pesky stuff like garbage collection for you, but if you really want to control your code, use C and its variants.

Oh, and Bruce Eckel has written very good books called Thinking in C++, available for free at his website. They're kinda dated, but you'll get the point, and you'll know what to ask on Stack Overflow or Google.

Link to comment
Share on other sites

Sometimes you want a barebones stripped application of all its bells and whistles that just crunches massive amount of data. I have 200Gbyte of Desinovan genome that I want to process. I know how to do in in VBasic relatively logically an easily, now I need to get into a version of C that can make it go fast, barring that I will probably never be able to hex code on an i586 processor, i need the next best thing, ergo on linux and learning C. The logic is, if I can port it to C# and work out all the bugs there I can create a C++ application and run it on the console. In response to what one of the other posters says, efficiency is very important, still.

Tried running barebones sequence alignment on mtDNA sequences from all Eutherians, and will need to repeat soon, the last time I ran the alignment it took just over 3 days.

Few questions:

1. Does your app have to process data in chain or you can split processing in multiple threads?

2. Do you have access to many computers?

3. Do you need multiplatform app? (all you computers are running linux or there are many different systems?)

4. Problem is CPU power or I/O of your hard drive (you mentioned 200GB of data)?

If your app have to process many loops with exact same code you could use Java, I don't remember now how it is called, since I wasn't using Java for last few years, but there was some really great feature in that language. It could compile parts of your Java code into native code for your OS, so it was running as fast as C code ;)

Ohh and if someone is saying to you that you have to know C to write plugins for Java ask him in what language is written Java virtual machine (that is key for multiple platform app)...

Spoiler alert it is C++ ;)

Link to comment
Share on other sites

Memory leaks on a regular basis even in simple code)

You may call me crazy, but C/C++ are very great for LEARNING how to program. I started learning with MSX-Basic on Z80 processor and it allowed me so much that wasn't probably wise. Memory leaks teach you humility and discipline.

Link to comment
Share on other sites

You may call me crazy, but C/C++ are very great for LEARNING how to program. I started learning with MSX-Basic on Z80 processor and it allowed me so much that wasn't probably wise. Memory leaks teach you humility and discipline.

I am not saying the contrary. On the opposite, I think that C/C++ are great languages. I'm just saying that once you go past the learning phase, it's good to move on to Java and such, the concept is the same but it makes your life simpler. From my own experience, I can tell how annoying is to find the one pesky memory leak in 1000+ line code (OpenCV + RaspBerry Pi).

I still consider memory leaks extremely annoying and useless, but again, that might have something to do with my overachieving nature and inability to handle defeat in general.

Link to comment
Share on other sites

Few questions:

1. Does your app have to process data in chain or you can split processing in multiple threads?

2. Do you have access to many computers?

3. Do you need multiplatform app? (all you computers are running linux or there are many different systems?)

4. Problem is CPU power or I/O of your hard drive (you mentioned 200GB of data)?

If your app have to process many loops with exact same code you could use Java, I don't remember now how it is called, since I wasn't using Java for last few years, but there was some really great feature in that language. It could compile parts of your Java code into native code for your OS, so it was running as fast as C code ;)

Ohh and if someone is saying to you that you have to know C to write plugins for Java ask him in what language is written Java virtual machine (that is key for multiple platform app)...

Spoiler alert it is C++ ;)

OK, so in preparation I have two SSD drives, one is 500 GB and the other is 120 GB, some of the sequence files I parsed with VB because they were too large for a single 64 GB memory pen. They will have to be recombined. I need basically i386 compatibility and I already have it with windows/linux C#. But the thing is that I have techniques in VB developed that really I will need to get the logic to work, so that it needs to be portable with VB.net into something else with minimal amount of work. The process is that in Studio.Net I can start shaving portions of the VB code into C#. That's a big plus but the structure has to be compatible. Parallel processing would be great, sequence is randomly placed in the file, and I have already split the file into binary code for transport. I have access to 2 computers, but only 6 total processors. (Win 7, Win 10, Ubuntu 14.0.4) Technically speaking I could recombined all the sequence into a single file, and then carve it into 8 smaller files that could be processed individually. The end product will be a text files.

- - - Updated - - -

Finally, lol .......

[FONT=Monospace] [COLOR=#009695]using[/COLOR][COLOR=#333333] System[/COLOR][COLOR=#333333];[/COLOR]
[COLOR=#009695]namespace[/COLOR][COLOR=#333333] Trial[/COLOR]
[COLOR=#333333]{[/COLOR]
[COLOR=#009695]public [/COLOR][COLOR=#009695]class [/COLOR][COLOR=#3364a4]Class_AddNumbers[/COLOR]
[COLOR=#333333]{[/COLOR]
[COLOR=#009695]public [/COLOR][COLOR=#009695]int [/COLOR][COLOR=#333333]AddNumbers[/COLOR][COLOR=#333333]([/COLOR][COLOR=#009695]int[/COLOR][COLOR=#333333]number1[/COLOR][COLOR=#333333],[/COLOR][COLOR=#009695]int[/COLOR][COLOR=#333333]number2[/COLOR][COLOR=#333333],[/COLOR][COLOR=#009695]int[/COLOR][COLOR=#333333]number3[/COLOR][COLOR=#333333])[/COLOR]
[COLOR=#333333]{[/COLOR]
[COLOR=#009695]return[/COLOR][COLOR=#333333] number1[/COLOR][COLOR=#333333] + [/COLOR][COLOR=#333333]number2 [/COLOR][COLOR=#333333]+ [/COLOR][COLOR=#333333]number3[/COLOR][COLOR=#333333];[/COLOR]
[COLOR=#333333]}[/COLOR][COLOR=#888888][I]//[/I][/COLOR][COLOR=#888888][I]function[/I][/COLOR][COLOR=#888888][I] AddNumbers[/I][/COLOR]
[COLOR=#333333]}[/COLOR][COLOR=#888888][I]//Class_AddNumbers[/I][/COLOR]
[COLOR=#333333]}[/COLOR][COLOR=#888888][I]//[/I][/COLOR][COLOR=#888888][I]namespace[/I][/COLOR][COLOR=#888888][I] Trial[/I][/COLOR][/FONT]

[FONT=Monospace] [COLOR=#009695]
using[/COLOR][COLOR=#333333] System[/COLOR][COLOR=#333333];[/COLOR]

[COLOR=#009695]namespace[/COLOR][COLOR=#333333] Trial[/COLOR]
[COLOR=#333333]{[/COLOR]
[COLOR=#009695]class[/COLOR][COLOR=#3364a4] MainClass[/COLOR]
[COLOR=#333333]{[/COLOR]
[COLOR=#009695]public [/COLOR][COLOR=#009695]static[/COLOR][COLOR=#009695] void[/COLOR][COLOR=#333333]Main[/COLOR][COLOR=#333333]([/COLOR][COLOR=#009695]string[/COLOR][COLOR=#333333][][/COLOR][COLOR=#333333] args[/COLOR][COLOR=#333333])[/COLOR]
[COLOR=#333333]{[/COLOR]
[COLOR=#888888][I]//[/I][/COLOR][COLOR=#888888][I]string[/I][/COLOR][COLOR=#888888][I]EndKey[/I][/COLOR][COLOR=#888888][I];[/I][/COLOR]
[COLOR=#009695]int [/COLOR][COLOR=#333333]Looper1[/COLOR][COLOR=#333333]=[/COLOR][COLOR=#f57d00]0[/COLOR][COLOR=#333333], [/COLOR][COLOR=#333333]Looper2[/COLOR][COLOR=#333333]=[/COLOR][COLOR=#f57d00]0[/COLOR][COLOR=#333333], [/COLOR][COLOR=#333333]Looper3[/COLOR][COLOR=#333333]=[/COLOR][COLOR=#f57d00]0[/COLOR][COLOR=#333333], [/COLOR][COLOR=#333333]Maxloops[/COLOR][COLOR=#333333]=[/COLOR][COLOR=#f57d00]15[/COLOR][COLOR=#333333], [/COLOR][COLOR=#333333]CummLoop[/COLOR][COLOR=#333333]=[/COLOR][COLOR=#f57d00]0[/COLOR][COLOR=#333333];[/COLOR]
[COLOR=#009695]for[/COLOR][COLOR=#333333]([/COLOR][COLOR=#333333]Looper1[/COLOR][COLOR=#333333]=[/COLOR][COLOR=#f57d00]1[/COLOR][COLOR=#333333];[/COLOR][COLOR=#333333] Looper1[/COLOR][COLOR=#333333]<[/COLOR][COLOR=#333333]Maxloops[/COLOR][COLOR=#333333]-[/COLOR][COLOR=#f57d00]1[/COLOR][COLOR=#333333]; [/COLOR][COLOR=#333333]Looper1[/COLOR][COLOR=#333333]++[/COLOR][COLOR=#333333])
[/COLOR][COLOR=#333333]{[/COLOR]
[COLOR=#3364a4]Console[/COLOR][COLOR=#333333].[/COLOR][COLOR=#333333]WriteLine[/COLOR][COLOR=#333333]([/COLOR][COLOR=#333333]Looper1[/COLOR][COLOR=#333333])[/COLOR][COLOR=#333333];[/COLOR]
[COLOR=#009695]for[/COLOR][COLOR=#333333]([/COLOR][COLOR=#333333]Looper2[/COLOR][COLOR=#333333]=[/COLOR][COLOR=#333333]Looper1[/COLOR][COLOR=#333333]+[/COLOR][COLOR=#f57d00]1[/COLOR][COLOR=#333333];[/COLOR][COLOR=#333333]Looper2[/COLOR][COLOR=#333333]<[/COLOR][COLOR=#333333]Maxloops[/COLOR][COLOR=#333333];[/COLOR][COLOR=#333333]Looper2[/COLOR][COLOR=#333333]++[/COLOR][COLOR=#333333])[/COLOR][COLOR=#333333]
{[/COLOR]
[COLOR=#3364a4]Console[/COLOR][COLOR=#333333].[/COLOR][COLOR=#333333]Write[/COLOR][COLOR=#333333]([/COLOR][COLOR=#f57d00]"[/COLOR][COLOR=#f57d00]"[/COLOR][COLOR=#333333])[/COLOR][COLOR=#333333];[/COLOR][COLOR=#3364a4]Console[/COLOR][COLOR=#333333].[/COLOR][COLOR=#333333]WriteLine[/COLOR][COLOR=#333333]([/COLOR][COLOR=#333333]Looper2[/COLOR][COLOR=#333333])[/COLOR][COLOR=#333333];[/COLOR]
[COLOR=#009695]for[/COLOR][COLOR=#333333]([/COLOR][COLOR=#333333]Looper3[/COLOR][COLOR=#333333]=[/COLOR][COLOR=#333333]Looper2[/COLOR][COLOR=#333333]+[/COLOR][COLOR=#f57d00]1[/COLOR][COLOR=#333333];[/COLOR][COLOR=#333333]Looper3[/COLOR][COLOR=#333333]<[/COLOR][COLOR=#333333]Maxloops[/COLOR][COLOR=#333333]+[/COLOR][COLOR=#f57d00]1[/COLOR][COLOR=#333333]; [/COLOR][COLOR=#333333]Looper3[/COLOR][COLOR=#333333]++[/COLOR][COLOR=#333333])[/COLOR]
[COLOR=#333333]{[/COLOR]
[COLOR=#3364a4]Class_AddNumbers [/COLOR][COLOR=#333333]AddTheseNumbers[/COLOR][COLOR=#333333] = [/COLOR][COLOR=#009695]new [/COLOR][COLOR=#3364a4]Class_AddNumbers[/COLOR][COLOR=#333333]()[/COLOR][COLOR=#333333];[/COLOR]
[COLOR=#333333]CummLoop[/COLOR][COLOR=#333333] =[/COLOR][COLOR=#333333] AddTheseNumbers[/COLOR][COLOR=#333333].[/COLOR][COLOR=#333333]AddNumbers[/COLOR][COLOR=#333333] ([/COLOR][COLOR=#333333]Looper1[/COLOR][COLOR=#333333],[/COLOR][COLOR=#333333] Looper2[/COLOR][COLOR=#333333],[/COLOR][COLOR=#333333] Looper3[/COLOR][COLOR=#333333])[/COLOR][COLOR=#333333];[/COLOR]
[COLOR=#3364a4]Console[/COLOR][COLOR=#333333].[/COLOR][COLOR=#333333]Write[/COLOR][COLOR=#333333]([/COLOR][COLOR=#f57d00]"[/COLOR][COLOR=#f57d00]"[/COLOR][COLOR=#333333])[/COLOR][COLOR=#333333]; [/COLOR][COLOR=#3364a4]Console[/COLOR][COLOR=#333333].[/COLOR][COLOR=#333333]Write[/COLOR][COLOR=#333333]([/COLOR][COLOR=#333333]Looper3[/COLOR][COLOR=#333333])[/COLOR][COLOR=#333333];[/COLOR][COLOR=#3364a4] Console[/COLOR][COLOR=#333333].[/COLOR][COLOR=#333333]WriteLine[/COLOR][COLOR=#333333]([/COLOR][COLOR=#f57d00]"[/COLOR][COLOR=#f57d00]-[/COLOR][COLOR=#ff0000]{[/COLOR][COLOR=#ff0000]0[/COLOR][COLOR=#ff0000]}[/COLOR][COLOR=#f57d00]"[/COLOR][COLOR=#333333],[/COLOR][COLOR=#333333]CummLoop[/COLOR][COLOR=#333333])[/COLOR][COLOR=#333333];[/COLOR]
[COLOR=#333333]}[/COLOR]
[COLOR=#333333]}[/COLOR]
[COLOR=#333333]}[/COLOR]
[COLOR=#3364a4]Console[/COLOR][COLOR=#333333].[/COLOR][COLOR=#333333]ReadLine[/COLOR][COLOR=#333333]()[/COLOR][COLOR=#333333];[/COLOR]
[COLOR=#333333]}[/COLOR]
[COLOR=#333333]}[/COLOR]
[COLOR=#333333]}
[/COLOR][/FONT]

Class_AddNumbers AddTheseNumbers = new Class_AddNumbers();

Of all the statements this gave me the most trouble, it won't work with a static declaration in the called functional. The archane function here is that you have to assign the type (Class_AddNumbers) and then tell C that also by the way its going to be a new Class_AddNumbers. Lol, no kidding I am defining a type as one thing and then saying by the way its also a new the same thing.

I am not trying to be insultive here really, I am going to learn the C# and C++ but just to point out......

in basic


Dim X as integer

Function AddNumbers (Number1 as integer, Number2 as Integer, Number3 as Integer) as Integer
If (Number1 + Number2 + Number3) > 32768 Then AddNumbers = 0 Else AddNumbers = Number1 + Number2 + Number3 'note also added a overrun protection.
End Function

Sub Main
[Rest of program]
x = AddNumbers(L1, L2, L3)
[Rest of rest of program]
End Sub

Link to comment
Share on other sites

PB666, your basic complaint is that you write bad code, and C# makes it more difficult to do so than VB. Don't feel bad, this is a common problem for VB programmers. I was the same way when I used to write in VB two decades ago. In the words of one comp-sci professor, "It's alright if some of you never programmed before. It's much worse if you know BASIC."

These are bad programming practices, and you should get rid of them. You'll code better in either language once you do.

Actually the creators of C# claim that this opinion that C# is just an iteration of Java, they claim that it was patterned off of C++.

In style. But not in how it works. Again, C/C++ compile to native binaries. C# compiles to byte code. So does Java. C/C++ do not do garbage collection. C#/Java do. List goes on. But stylistic similarities between C# and C++ do mean that a lot of optimization techniques work for both, which is part of the reason why C# is pretty decent in speed. The other part is JIT in CLR, which is much better than JVM's JIT. But I'm getting off topic.

The reason why I selected C hash was that I want to create high efficiency routines that I can run from VB or VBA, basically, so the efficiency issue is the issue. But exactly to the point, I wanted to tailor structures and classes to the efficiency and accuracy that I needed. The problem is that this has proven to be rather archaic process in either C++ or C#. Microsoft claims that both VB and C# are converted to essentially the same product before finally being converted to assembly language at runtime (Runtime implimentation). Also C hash runs in linux, which means If I have to I can run any vb app in linux as long as I can convert it to C#. Since these are the most similar it seems logical.

So first of all, C# runs on CLR. So does VB. You can actually run VB binaries on Linux. There are ways to do that. I don't know how good Mono's JIT, though. (You are talking about running C# via Mono, right?) So performance could be a problem. But again, secondary concern.

Biggest issue here is that it's the wrong choice of language. If you're after performance, performance, and performance, your code should be written in C. Not C#, not C++. Plain old C. There are ways to incorporate C sub-routines in a VB program. That's your best bet for staying with familiar VB for high level logic and still getting performance of a C program.

Also, if your C sub-routines have platform-dependent code, you're doing it wrong. Your C portions should be written to be platform-independent. That way the same binaries will run on Windows or Linux machine. And if you ever need to compile for Android, or what have you, it will be up to compiler to take care of these differences.

So let me opinion about the problems of VB in principle and compare with C.

1VB. The If ...... End If structures, unlike For and Next do not have identifiers. For example hypothetically If-1 End If-1. When you have left out a next or end statement, the computer does not recognize that it was missing for an end or next statement, and proclaims that an End if is missing even though it might be a Next.

1C The { ....... } covers not only If and For and while and For each and . . . . . but also covers subroutines, class definitions. so a problem that is bad in VB is a magnitude worse in C. Seriously code segment identifiers are not compiled, they are freebees. 1{ }1 2{ }2 3{ }3 4{ }4 So that if you messed up one of your brackets the programs can tell you 'hey bracket 1 is missing it closing bracket'

You should be indenting your code. It's absolutely impossible to miss a matching brace if you properly indent. And yeah, sometimes it helps to comment the closing brace to remember exactly what you are closing. Some times it matters. But simply remembering to indent each time you open a brace will already resolve almost all of your problems.

Code segments actually have compilation effect. They define scope, and scope defines what's happening to your stack. If you are writing deeply recursive code, these unqualified {} blocks can save you a ton of stack, allowing deeper recursion without a crash.

2VB. Function definitions. If you are running a function within a module of basic, you simply need to declare the function and variable and a few lines of code. Its relatively simple. For the most part you don't want to run a function except if it will clear several lines of code up. So for example I want to evaluate non-normality, I can create a Skewing function and a Kurtosis function, or combine both into a single function (the output would have to be a string in that case)

This is how functions work in C and C++. It's only C# that does that messed up thing with everything requiring a class. That does provide better type-safety, but I don't like it either.

Also, if you're worried about performance, using strings for function input/output is NOT the way to go. When you create a string, it's allocated on the heap, which requires a few hundred cycles in the best case. That can easily run into thousands if heap needs to be expanded. And then you have to generate the actual string, which is thousands more cycles. And that's without the overhead of garbage collection on top of this if you're doing VB/C#/Java. Of course, if you're writing this in C, absolutely all of this is explicit, so you know precisely what you're wasting your cycles on. Also, there are far, far better ways of handling multiple outputs. C's favorite way is passing in references to output variables. C++ can return structs. How the later is handled depends on implementation and optimization options.

2C. Jeeze Louise, lol. Static, Public, Private, implementation requires a new statement for multiple iterations. Why do I need to create a new class exactly to have multiple iterations. The simplest functional math statement and I have run into errors with just about every character of code. Is this really saving clock cycles, calling subroutines as separate classes? In C a function definition is not just a function, it is literally everything, whereas in VB functions are Functions (return calls) and everything else is subroutine, or even a defined type in VB6 (the equivilant of a struct in C). Because the functions are not set apart what has happened (as I see it) every single identifier in a class becomes very context sensitive, so any minor deviation from what the computer expects will generate an error. The problem in C is that class and function are muddled, a function should be something with a return value, it is not it can be any routine called in a class, if a static is not given it runs pretty much like the pi() function, if the static is not given you have to call a new instance of the function (an pray that its going to work).

So it seems to me, that say if I am going to need several routines running simultaneously in C, I am going to have to create a whole new class for each, to make sure that the other might-be functions in that class are not going to be carried on for the ride. This makes sense if you need to build really big classes, such as an employee class or product class, but if the function of the iteration is to process some basic parameters.

Again, just one more reason to go with C/C++. You can create a bare function in these languages, which will exist on the stack only, meaning it can be called in parallel from as many threads as you like without fretting over race conditions.

So now in C, fluffball is now an instance of a class and all its parameters will have to be shipped to the object to be updated, this essentially means making an expensive call for essentially routine equivalencies.

In C, there is no such thing as a class, much less an instance of it. In C++, you'd have a choice how to do this. In C#, you can actually make sure that all of the parameters you are interested in are passed in as actual parameters, or ride on top of a struct you pass in by reference. Believe it or not, you actually have way more control in C/C++/C# than VB. You are just used to having no control, and so your complaints are all of the type, "Why doesn't it just do what I want it to do." The answer is, you haven't told it to.

The /// section of definitions I have tried to use this but it doesn't seem to work, it works in the You Tube but not on my computer.

What do you mean they don't work? The comments? Or are you trying to have them do something other than just being comments?

P.S. And we haven't even gotten to the meat of the problem. How do you make your C code run fast, especially with multiple threads on multiple machines? This is a whole separate topic, and part of the answer is, "By not writing it like you do in VB."

Link to comment
Share on other sites

Programming languages are tools. For certain applications C will be better, for others not. It's hard to hammer nails into wood using a saw.

For code that needs to run fast, C or C++ is usually the best choice. But keep in mind that depending on the complexity of your problem you'll gain more "performance" from improving the algorithm than from writing faster code. A high level language that makes it easy to implement such an algorithm might be a better solution. For many problems optimizing the algorithm yields improvements magnitudes better than concentrating on writing "optimized code."

That's not saying that your solution should or should not be written in C; merely that when you're looking to improve processing time, looking for a "fast language" might not be the most effective choice.

Link to comment
Share on other sites

OK, so in preparation I have two SSD drives, one is 500 GB and the other is 120 GB, some of the sequence files I parsed with VB because they were too large for a single 64 GB memory pen. They will have to be recombined. I need basically i386 compatibility and I already have it with windows/linux C#. But the thing is that I have techniques in VB developed that really I will need to get the logic to work, so that it needs to be portable with VB.net into something else with minimal amount of work. The process is that in Studio.Net I can start shaving portions of the VB code into C#. That's a big plus but the structure has to be compatible. Parallel processing would be great, sequence is randomly placed in the file, and I have already split the file into binary code for transport. I have access to 2 computers, but only 6 total processors. (Win 7, Win 10, Ubuntu 14.0.4) Technically speaking I could recombined all the sequence into a single file, and then carve it into 8 smaller files that could be processed individually. The end product will be a text files.

Here are some tests, they are from 2009 http://reverseblade.blogspot.com/2009/02/c-versus-c-versus-java-performance.html but my point in here is not how much faster is "my fav lang over someone else fav lang" you have there nice chart showing in what algorithms one language is better than the other.

I don't know what is your app main "logic", so you have to decide on your own, what kind of algorithms you are using most and pick best solution for that.

Here is also nice benchmark for linux and many languages and many algorithms http://benchmarksgame.alioth.debian.org/

You can think about your app structure on many different layers.

Multithreading is one way and it is good if you have multiple cores and multiple computers, but it won't save you from issues like:

load large data chunk from disk (disk usage 100%, CPU usage 0%)

run logic (disk 0%, CPU 100%)

write data to disk (disk 100%, cpu 0%)

You have to pick right size of chunk you read and write, so you wouldn't waste lots of time doing that part of your code.

You can also try to make buffer for loaded chunks and load next portion of data while "run logic" step your CPU is used at 100%, but disk is free to load next part of file.

It all depends what is your logic if and how it can be sliced... yes logic not only data can be sliced in some algorithms, for example standard logic:

load input data -> process logic -> write output

in some cases you can use mid-points, it all depends what are you doing:

input data -> process 1st part of logic -> temp file -> 2nd part of logic -> output data

now if you would want to repeat lots of time 2nd step of your logic you can safe some time just by reading input data from temporary files.

You can even try alternative method and not using any programming language ;) just put your data in database engine and create SQL query... databases are great if you need to find patterns, sort, count or aggregate your data and I am sure they are going to run very fast and you can split them on multiple computers :)

There is no single "best scenario, best language or best algorithm" it depends what are you doing:

- if you need to repeat execution of your app multiple time with same data, but you put different parameters in your logic

- repeat execution of app every time with different data set and same parameters in logic

- or else :)

Edited by Darnok
Link to comment
Share on other sites

But keep in mind that depending on the complexity of your problem you'll gain more "performance" from improving the algorithm than from writing faster code. A high level language that makes it easy to implement such an algorithm might be a better solution. For many problems optimizing the algorithm yields improvements magnitudes better than concentrating on writing "optimized code."

That's not saying that your solution should or should not be written in C; merely that when you're looking to improve processing time, looking for a "fast language" might not be the most effective choice.

Well, this is why when you wish to build something really complex, you never use just one language. For example, the games in the studio I work at are written primarily in C. But some of the more abstract libs have to be C++ or it'd just be too crazy to work with. (Primary reason for C over C++ is compiler time, btw, not so much performance.) On the other hand, most of the code I work with is low level engine stuff. So I write a lot of code with intrinsics, which is very close to writing Assembler code.

Either VC greatly improved since 2009, or somebody did not know how to configure the optimization settings.

And yes, these simple test algorithms tend to perform pretty close, because your limiting factor is branch prediction, which will be just about the same between native and good JIT. I would have liked to see them try running skeletal animation and ragdolls on C#/Java, though. Among common use algorithms, it's the most brutal abuse of branching, cache, and raw computational performance, which typically makes JIT cry.

Edited by K^2
Link to comment
Share on other sites

PB666, your basic complaint is that you write bad code, and C# makes it more difficult to do so than VB. Don't feel bad, this is a common problem for VB programmers. I was the same way when I used to write in VB two decades ago. In the words of one comp-sci professor, "It's alright if some of you never programmed before. It's much worse if you know BASIC."

These are bad programming practices, and you should get rid of them. You'll code better in either language once you do.

I wouldn't call them bad, VB works very well if some one is handing you data on an excel worksheet, as is the lingua franca for most people who process data but don't program. Its only when you have a serial stream of data and you need to do strait line processing, lets not use the word bad, lets call it weak. Here is the basic problem and believe me I have worked it down as small as I can, the variable definition in basic is not very good, in fact it stinks, but C# goes overboard particularly in creating instances. Every Basic function assumes that it has no idea what you are going to send it so it is going to try to convert everything to what it wants to process, then convert it back to what you want. If you know in advance you would convert in advance that long integer into a double if you are doing precision multiplication. I use integers for counters and pointers and try not to mix it into the floating point stuff. But I cannot control the fact that basic doesn't know if its going to be using a single or a integer as a counter.
So first of all, C# runs on CLR. So does VB. You can actually run VB binaries on Linux. There are ways to do that. I don't know how good Mono's JIT, though. (You are talking about running C# via Mono, right?) So performance could be a problem. But again, secondary concern.

The CLR is clearly and advantage of studio.net, it comes with an enormous overhead. But it makes crossing between the two programming languages easier. I should make a point that a couple of decades ago I purchased Visual C++ and was attempting to cross over, the problem was the next version of Visual basic added most of the features that C++ was strong in, except the speed.

Biggest issue here is that it's the wrong choice of language. If you're after performance, performance, and performance, your code should be written in C. Not C#, not C++. Plain old C. There are ways to incorporate C sub-routines in a VB program. That's your best bet for staying with familiar VB for high level logic and still getting performance of a C program.

I agree. OK so the problem that I have had with doing the good old fashion hard run was upper level control. Even in VB its hard to plan break points, in dos you never worried about it, you had no control, once you allowed the processor to run a function it simply ran until in finished or you hit the reset button. What I plan to hand off to C is going to be some pretty intense processing, so I need the higher level OS breakpoints. But if I want to run C based dll, then basically I need something like C# or VB to hand off once the data is in the machine and needs heavy processing. I believe that MonoDevelope can create C routines, I know it can create C++.

Also, if your C sub-routines have platform-dependent code, you're doing it wrong. Your C portions should be written to be platform-independent. That way the same binaries will run on Windows or Linux machine. And if you ever need to compile for Android, or what have you, it will be up to compiler to take care of these differences.

Its going to have to be platform specific in one regard I need to have make-file and open file, append file, and close file command. At least multiple times. So if its on linux it needs to be linux compatible filing system. Don't care about android, not care about IPAD, don't care about apple.

You should be indenting your code. It's absolutely impossible to miss a matching brace if you properly indent. And yeah, sometimes it helps to comment the closing brace to remember exactly what you are closing. Some times it matters. But simply remembering to indent each time you open a brace will already resolve almost all of your problems.

The MonoDevelop was automatically indenting and not particularly where I would choose to. In VB I always indent, always manually and always remember the consequences, 2 for each level except the If then Else End If in which else is always 1 outdent. I tend not to run recursive code, although I have played with it.

What do you mean they don't work? The comments? Or are you trying to have them do something other than just being comments?

"///" on the you tube immediately filled out 5 lines with each element in the definitions passed variables, basically you could describe the types used in the function. I tried the same thing and nothing happened. I don't need these but they are a nice feature.

Link to comment
Share on other sites

If a plugin has to be in C++, just roll with it. There are some nuances, but for your purposes, you can write C code in C++ and it will compile, execute, and probably run either just as fast or close enough. Plus, you can use some of the neat C++ features, like new operator instead of malloc. On the other hand, you don't have to. So if you don't want to declare a single class, don't.

"///" on the you tube immediately filled out 5 lines with each element in the definitions passed variables, basically you could describe the types used in the function.

Oh, that could be a plugin to dev environment.

Link to comment
Share on other sites

PB666: Declare your AddNumbers method static. Then you can call it without creating an object for it, like so:

Class_AddNumbers.AddNumbers(...);

The closest analoge to your methods/functions in VB that you just write and call in a single module probably would just be private static functions in C#. Callable without an object, but only from other functions from the same class. Same in C++, only there, you can also just have static functions in the .cpp file without declaring them in the class header. Note: 'static' means about seven different things in C++ depending on context. And even though the two 'static's here work towards the same goal, they're totally different.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...