LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

When will CVI support a C++ compiler Natively?

Yeah, welcome to my hell, tho personally I find C++ easier to accomplish tasks in than C, I am especially fond of C#, but when your entire department are electronics engineers and you're the only professional programmer in the department, it's frustrating.  I work in manufacturing test
0 Kudos
Message 21 of 48
(2,235 Views)

So do I.  

We wind up having several senior programmers spend days tracking down a mistake that it took some amateur C hack 5 minutes to make.  Then the program manager complains about the software cost.

Mishandling pointers is a favorite, but in general the capacity of systems engineers, EE's, and techs to write unbelievably bad code would blow your mind.   Most of the amateur hacks are literally too stupid to be embarassed at the junk they write.  Many of them also seem to be convinced that writing C code just can't be that hard - pure arrogance.

Menchar

 

 

 

0 Kudos
Message 22 of 48
(2,224 Views)
*snickers* I'm the department new guy, young, lacking professional experience, no degree... Got mocked for about a week until they realized I was producing code so well engineered that not only could a freshman CS student read it and understand general program flow, it was make a C veteran proud and a C++ veteran laugh at silly attempts to do data hiding in C.  Then I explained that I started coding in C when I was 6 years old in 1990.
 
Before I came in, globals were the standard for about 20% of variables, datastore accessor functions were not only not used, they were a foreign concept, and the mere thought of recursion made heads spin.  I said red-black tree once and with the exception of the department's lead engineer, I just got blank stares.  Kinda sad really.  What Industry are you working in then? I'm in the power protection industry.

Message Edited by DanielGreen on 10-29-2007 12:50 PM

0 Kudos
Message 23 of 48
(2,218 Views)

I'm at raytheon.

Yup, globals are bad - turns out that's easily said but profoundly true.  I was going to try and multi-thread a large goofed up app until I looked at global usage - I'll grow old and die before I could work through it all.

I get shouted down, sometimes literally, and laughed at for making suggestions like:

1.  Minimize pointer use.  Don't de-reference a NULL pointer.  Don't use pointers to void as a polytype to defeat the type system, such as it is.
2.  One declaration per line, in alphabetical order, using meaningful names.
3.  Some form of hungarian notation so variable type is known without hunting all over for the declaration.
4.  No "magic numbers".
5.  Use the registry, not .ini files
6.  Use the

if ((iStatus = function ()) != NO_ERROR) {
   // error handling here
}


     idiom.
7.  Use a consistent brace style, normally the "one true bracket style."
8.  Annotate - good code's written once and read many times.
9.   Limit nesting depth, function length, number of parameters, module size.
10. Don't code memory leaks.
11. Don't recode stuff that's in the standard library.

Among others.

I use the terms "too stupid to be embarrased" and "conspiracy of fools" quite a bit.

Menchar

0 Kudos
Message 24 of 48
(2,213 Views)

1.  Minimize pointer use.  Don't de-reference a NULL pointer.  Don't use pointers to void as a polytype to defeat the type system, such as it is.

This is a no brainer, pointers are FINE if they're used as constant pointers from accessors in a modular API that nobody but a really godo idiot can break.


2.  One declaration per line, in alphabetical order, using meaningful names.

This is style, but very GOOD style


3.  Some form of hungarian notation so variable type is known without hunting all over for the declaration.

For CVI this is a good idea even if it's just throwing val str or ptr onto the variable name somewhere to get an IDEA of what we're working with, in other IDE's it's not such a big deal, in VS, I just mouse over the identifier.


4.  No "magic numbers".

unless it's like [BUFFERLEN-1] or other relatively idiot proof ones, even then I tend to comment...


5.  Use the registry, not .ini files

This depends on the implementation and distribution method, we use ini's alot because we run alot of our software off remote drives, however I do tend to agree.

6.  Use the

if ((iStatus = function ()) != NO_ERROR) {
   // error handling here
}


     idiom.

 

    Eww... first row open brackets, bad readability and brackettracing.


7.  Use a consistent brace style, normally the "one true bracket style."

Style my friend, it's all good so long as it's condusive to good development and is consistant.


8.  Annotate - good code's written once and read many times.

Just dont' say "this is an integer"


9.   Limit nesting depth, function length, number of parameters, module size.

functions should do one thing and do it well, if that one thing encompasses other smaller related things, they should each be functions, lather rinse repeat.

10. Don't code memory leaks.

Tell that to Microsoft.


11. Don't recode stuff that's in the standard library.

Unless it's academic in nature.

0 Kudos
Message 25 of 48
(2,210 Views)
ho shit... i just went "hoooo ! haaaaa ! hooooo !" reading all those last post ! now i know that i am not alone having such difficult time fighting against incompetent developpers...

personnally, i come from an Ada background, where the language is so restrictive that you almost have no choice other than writing code correctly. i believe that good programming practices are hard to teach to people using a permissive language like C.

one thing i constantly fight for is data abstraction, and unfortunately C is very poor at it. the only possible way to have a real private type is to declare a pointer to a struct, which leads to a lot of pointer use, 90% of which is unnecessary. why do i think data abstraction is so important ? because, when designing a software, i first split it in a number of totally independant modules that i glue together by a simplistic mean. for me, i should be able to give my fellow developpers a header file, and they should be able to use it without ever having to peek at the code beneath. unfortunately, C has never been designed to work like this, and so people knoing only this language generally do not understand the benefit of coding this way.

talking about coding style: some constructions are dangerous, like global variables, type casting and type "lazyness" (declare everything an int or a pointer to void). those should be avoided, but an expert can use them without any danger. hungarian notation or other "true brace style", i don't care about ias long as you are always consistant: find a coding style and stick with it !

also, menchar said: "good code's written once and read many times". i remember being laughed at, while arguing about rewriting a very badly written software, when i said the software in question would be a maintenance nightmare. "who cares about maintenance ?", said my boss. it is now 9 month i am painfully trying to maintain said software, and make it evolve as close as possible to the customer requests... 9 month of maintenance nightmare and my boss doesn't give a shit about that !
0 Kudos
Message 26 of 48
(2,195 Views)
I work at Schweitzer Engineering Labs, and don't get me wrong, they're a WONDERFUL team, and what they know, hardware, they know better than most people in thier field, but they are for the most part, not software engineers in test development.  They are Electronics engineers or similar disciplines, so ideas like modular design go in one ear and out the other.  They just don't care because they dont' understand why they should care.  It's sad.
0 Kudos
Message 27 of 48
(2,192 Views)

My comment on the idiom was to capture an error return and deal with it, instead of ignoring returned status as so many of the clowns around here do.  tens of thousands of lines of code and it all falls apart whenever there's an error - no way to localize it without going in and hacking it.  The bracket style isn't important.

You have to do it with "style" in C 'cause there's no way for the compiler/linker to enforce good practice.  Yup, Ada is strictly typed, too bad no one much wants to use it.  Some say they ruined the language with Ada 95.

structs are about the best C offers for encapsulation / "data hiding".

CVI toolbox has List type, I use the heck out of this.  A collection-like abstraction in C.   Lists of structs work pretty well sometimes.

Plus I think NI gives you the sources to List.  Now if they only had a map 🙂    Could likely make one from the List data type, could also make queue, set, I think.

Try running this metric tool over some of your C code   www.campwoodsw.com.

Some of the code I have to deal with goes off the chart with this tool - I was going to send some of it to the author of the tool to see if he had ever seen metrics as bad.

I may post some of it up here just for laughs.  We could have a "bad CVI C code" contest.  Then realize that someone actually got paid to write it 🙂

Menchar

0 Kudos
Message 28 of 48
(2,186 Views)
average statements per function 1597.6 *raises eyebrow* someone learned in GW basic didn't they...
0 Kudos
Message 29 of 48
(2,183 Views)
Wow. That's a big one.
 
Here's one of ours.  Filenames hidden to protect the guilty.
 
Parameter    Value
=========    =====
Project Directory   -----
Project Name    -----
Checkpoint Name    Baseline
File Name    -----
Lines     1,130
Statements    514
Percent Branch Statements  35.4
Percent Lines with Comments  22.5
Functions    1
Average Statements per Function  820.0
Line Number of Most Complex Function 65
Name of Most Complex Function  Status_Processing()
Complexity of Most Complex Function 163
Line Number of Deepest Block  538
Maximum Block Depth   9+
Average Block Depth   7.54
Average Complexity   163.00
--------------------------------------------------------------------------------------------
Name of Function   Complexity, Statements, Max Depth, Calls
Status_Processing()   163, 501, 12, 191
--------------------------------------------------------------------------------------------
Block Depth    Statements
0                         13
1                         27
2                          5
3                          1
4                          6
5                          4
6                          32
7                          72
8                         90
9+                      264
--------------------------------------------------------------------------------------------
 
You gotta love that 264 / 514 statements are nested 9 or more blocks deep ....
 
menchar
 
0 Kudos
Message 30 of 48
(2,179 Views)