Being Smart about C/C++ Development on AIX and Linux

47
© 2014 IBM Corporation DAX-5162 C-ing is Believing: Being Smart about C/C++ Development on AIX and Linux Kenny Smith, Strongback Consulting

Transcript of Being Smart about C/C++ Development on AIX and Linux

Page 1: Being Smart about C/C++ Development on AIX and Linux

© 2014 IBM Corporation

DAX-5162C-ing is Believing: Being Smart about C/C++ Development on AIX and LinuxKenny Smith, Strongback Consulting

Page 2: Being Smart about C/C++ Development on AIX and Linux

About Us: Strongback Consulting

• IBM Advanced Business Partner• Rational, WebSphere, ICS SVP certified• Strongly focused on DevOps, Enterprise Modernization, and application infrastructure• Key Industries Served: Finance, Insurance, Travel, Logistics, Healthcare, Manufacturing,

Government• Rational Design Partner for HATS and other Rational enterprise modernization

technologies

Discover us at:http://www.strongback.us

Subscribe to us athttp://blog.strongbackconsulting.com

Socialize with us on Facebook & LinkedIn http://www.facebook.com/StrongbackConsulting

http://www.linkedin.com/company/290754

Page 3: Being Smart about C/C++ Development on AIX and Linux

3

Talking Points

• Editors• Content Assist & Templates• Refactoring• Static Code Analysis• Performance Advisor

Page 4: Being Smart about C/C++ Development on AIX and Linux

4

In the beginning….

Page 5: Being Smart about C/C++ Development on AIX and Linux

5

Then came telnet

• Edit directly on the target computer• English based language construction

Page 6: Being Smart about C/C++ Development on AIX and Linux

6

Next came vi… and then vim

• Colorized parsing of code, regex search/replace• ..but this is where most people stopped!

Page 7: Being Smart about C/C++ Development on AIX and Linux

7

Why do I need a rich development editor?

• Productivity! [proh-duhk-tiv-i-tee]• Its about the economics!• The rate at which goods and services having exchange

value are brought forth or produced – :Productivity increased dramatically last year.

• Why do you use a word processor instead of a type writer?

Page 8: Being Smart about C/C++ Development on AIX and Linux

8

Complexities of C/C++

• C makes it easy to shoot yourself in the foot. C++ makes it harder, but when you do, you blow away your whole leg! — Bjarne Stroustrup

• Pointers• Memory arithmetic• Memory leaks (see above)• Compiler differences – variability depending upon the processor• Syntax – language elements not found in other languages• Debugging

Page 9: Being Smart about C/C++ Development on AIX and Linux

The Editors:LPEX, C/C++, Remote

9

Page 10: Being Smart about C/C++ Development on AIX and Linux

10

The LPEX Editor

• Can act like the standard editor of any system• vi/emacs for *Nix systems• ispf for mainframe• seu for IBM I

• Change appearance to make it look like telnet

Page 11: Being Smart about C/C++ Development on AIX and Linux

The General C/C++ Editor

• Multiple ways to edit C/C++ source• C-C++ editor - Acts more like typical

Eclipse language editors (such as Java)

• LPEX Editor – can emulate vi editor• Use context menu, Open With to open

with a specific editor• Remote C/C++ specifically used in

AIX/Linux projects

Page 12: Being Smart about C/C++ Development on AIX and Linux

Icons used for C/C++

• Icons found in• Project Explorer• Call Hierarchy• Type Hierarchy• Outline View• Make targets view• Navigator View

Page 13: Being Smart about C/C++ Development on AIX and Linux

13

Syntax Highlighting

• Comments• Strings• Reserved words• values, variables Current cursor

row has blue background

Page 14: Being Smart about C/C++ Development on AIX and Linux

14

Method indicators

• Margin is highlighted in blue indicating the beginning and ending of the current method

method indicator

Cursor position

Page 15: Being Smart about C/C++ Development on AIX and Linux

15

Code Folding

• Comments, methods & classes can be collapsed or folded for ease of reading

• Click on the + to expand• Click on the – to collapse

Indicates additional code inside the collapsed area

Page 16: Being Smart about C/C++ Development on AIX and Linux

16

Hover

• Place your cursor over a variable or method• Displays a window showing the declaration

Hover mouse over the convert method

Window pops up in the editor showing

the declaration.

Page 17: Being Smart about C/C++ Development on AIX and Linux

17

Errors / Warnings

• Margin area indicators to show errors or warnings

• Hover the cursor over to show more information

• Warnings also underlined in yellow squiggles

Column location of error

Hover over marker

Page 18: Being Smart about C/C++ Development on AIX and Linux

18

Mark occurrences

• Put cursor on a variable name

• Additional occurrences marked with a gray background

• Toggle on/off with the task bar icon

Page 19: Being Smart about C/C++ Development on AIX and Linux

19

Show whitespace characters

• Use menu bar to show grey symbols representing whitespace characters

• Space, tab, carriage return, new line, etc.

Page 20: Being Smart about C/C++ Development on AIX and Linux

20

Code formatting

• Shift left / right• Correct Indentation• Format

• auto formats the entire source• properly indents throughout

Page 21: Being Smart about C/C++ Development on AIX and Linux

21

Format Source (CNTL+SHIFT+F)

Before After

Page 22: Being Smart about C/C++ Development on AIX and Linux

22

Commenting code

• Highlight multiple rows• Click CTRL+ / to comment• Click CTRL + / to uncomment• For /* style block commenting, use

CTRL+SHIFT+/

Page 23: Being Smart about C/C++ Development on AIX and Linux

23

Open Declaration

• From context menu, or F3: opens declared method location

• If in another file (or header), the file must be on the search path

• Also depends on the type of project you are using– MVS Subproject, z/Unix Subproject, C/C++ project, zFolder, etc.

Page 24: Being Smart about C/C++ Development on AIX and Linux

24

Quick Outline

• Right Click → Quick Outline• Shows a searchable outline of the

source member• Type in the text field to search

methods and types

Enter search text here

Filtered Results

Page 25: Being Smart about C/C++ Development on AIX and Linux

25

Call Hierarchy

• Right Click → Open Call Hierarchy• shows the loaded callers and callees for a selected C/C++

function

Toggle between caller

and callee

Hide contants, enums, and

variables

Show history of call hierarchy

Page 26: Being Smart about C/C++ Development on AIX and Linux

26

Find Dialog

• CTRL + F to bring up dialog

• Can search case sensitive, forward, backward, on all code, or just that selected.

• Regular expressions• Content assist

available to help build a search query

Page 27: Being Smart about C/C++ Development on AIX and Linux

27

Customizing the Editor

Page 28: Being Smart about C/C++ Development on AIX and Linux

28

CNTL+SHIFT+L

• Shows ALL keyboard shortcuts available• one keyboard shortcut to rule them all

Page 29: Being Smart about C/C++ Development on AIX and Linux

Content Assist &Templates

29

Page 30: Being Smart about C/C++ Development on AIX and Linux

Content Assist

30

• Allows you to provide context sensitive content completion upon user request

• CTRL+Space again to cycle through parser or template proposals

• Clicking or pressing Enter on a selected line in the list inserts the selection into the editor.

Configure the behavior of the content assist in the C/C++ →  Editor →  Code Assist preference page.

Page 31: Being Smart about C/C++ Development on AIX and Linux

31

Content Assist Sources• In the C/C++ editor press Ctrl + Space on code to complete. This

opens a list of available code completions. • Use the mouse or the keyboard (Up Arrow, Down Arrow, Page Up, Page

Down, Home, End, Enter) to navigate and select lines in the list.• Existing methods, properties, fields, etc.• Language constructs• Code templates

Page 32: Being Smart about C/C++ Development on AIX and Linux

What are Templates?

• Simply put, little pieces of code with defined placeholders• Work slightly differently than snippets• Place holders are called variables

• Syntax is ${variable_name}• Eclipse based – many languages supported• Java, ANT, COBOL, PL/I, JavaScript, HTML, XML, etc.

• Can be imported & exported• Can vary be easy or difficult to setup • Will save you HOURS upon HOURS of hand coding!

Page 33: Being Smart about C/C++ Development on AIX and Linux

Creating Templates Continued

• Insert Variable – inserts a given variable• Variable is described in the yellow box to the right of its name

Page 34: Being Smart about C/C++ Development on AIX and Linux

34

Syntax Check

• Editor parsed syntax checking

Page 35: Being Smart about C/C++ Development on AIX and Linux

Refactoring

35

Page 36: Being Smart about C/C++ Development on AIX and Linux

Refactoring

36

Refactoring: make system-wide code changes without affecting the behavior of the program.

Refactoring commands are available from the context menus of several views (e.g. Project Explorer, Outline) and editors. Many "apparently simple" commands, such as Move and Rename, are actually refactoring operations, since moving and renaming elements often require changes in dependent files.

• Extract a function, constant or local variable• Rename a method, variable or class• Hide a method signature

Operations can be previewed for all of the changes resulting from a refactoring action before you choose to carry them out.

Page 37: Being Smart about C/C++ Development on AIX and Linux

37

Extract Constant

• Improve performance, and avoid duplicate strings

Page 38: Being Smart about C/C++ Development on AIX and Linux

38

Renaming

• Easily rename a variable throughout your code• More accurate than find/replace

– i.e. try to find and replace a single character variable!

Page 39: Being Smart about C/C++ Development on AIX and Linux

Source Actions

39

Use the Source menu to perform many actions to modify, remove or generate code automatically.

• Toggle a line or block as a comment; on or off.• Format entire source files or fragments.• Correct Indentation• Implement getters & setters• Sort lines

The Source menu can be accessed from many context views such as in the C/C++ editor.

Page 40: Being Smart about C/C++ Development on AIX and Linux

Software Analyzer

40

Page 41: Being Smart about C/C++ Development on AIX and Linux

41

Static Code Analysis

• Software analyzer built into the product• Static code analysis can find common coding errors• Can create scan configurations and check against multiple rules

Page 42: Being Smart about C/C++ Development on AIX and Linux

42

Software Analyzer Results

• Categorized results can be exported into XML• could import into RTC as work items for remediation

• Severity and categories tell you which things to work on first

Page 43: Being Smart about C/C++ Development on AIX and Linux

43

Tuning with Performance Advisor

• Collects data via tprof/procstack (AIX), or oProfile (linux)

Page 44: Being Smart about C/C++ Development on AIX and Linux

44

Summary

• Why we have tools – PRODUCTIVITY!• Editor improvements over vi• Refactoring tools• Content Assist, Templating• Static Code Analysis• Performance Advisor

• What we did not cover: Debugging• This alone is worthy of this tool in your toolbox

Page 46: Being Smart about C/C++ Development on AIX and Linux

Questions?

46